|
| 1 | +import { readFile, writeFile } from 'node:fs/promises' |
1 | 2 | import { resolve } from 'node:path' |
2 | 3 | import { x } from 'tinyexec' |
3 | 4 |
|
4 | 5 | const dirs = ['create-nuxt', 'nuxi', 'nuxt-cli'] |
5 | 6 |
|
6 | 7 | for (const dir of dirs) { |
7 | | - await x('changelogen', ['--canary', 'nightly', '--publish'], { |
8 | | - nodeOptions: { stdio: 'inherit', cwd: resolve('packages', dir) }, |
9 | | - throwOnError: true, |
10 | | - }) |
| 8 | + const cwd = resolve('packages', dir) |
| 9 | + const pkgPath = resolve(cwd, 'package.json') |
| 10 | + const original = await readFile(pkgPath, 'utf8') |
| 11 | + |
| 12 | + await addNightlyBins(pkgPath, original) |
| 13 | + |
| 14 | + try { |
| 15 | + await x('changelogen', ['--canary', 'nightly', '--publish'], { |
| 16 | + nodeOptions: { stdio: 'inherit', cwd }, |
| 17 | + throwOnError: true, |
| 18 | + }) |
| 19 | + } |
| 20 | + finally { |
| 21 | + await writeFile(pkgPath, original) |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +/** |
| 26 | + * `npx <pkg>` only resolves a bin whose name matches the (unscoped) package |
| 27 | + * name when a package ships more than one bin, so the `-nightly` packages need |
| 28 | + * `-nightly` aliases for each of their bins. |
| 29 | + */ |
| 30 | +async function addNightlyBins(pkgPath, original) { |
| 31 | + const pkg = JSON.parse(original) |
| 32 | + if (!pkg.bin) { |
| 33 | + return |
| 34 | + } |
| 35 | + |
| 36 | + const bin = { ...pkg.bin } |
| 37 | + const entrypoint = Object.values(pkg.bin)[0] |
| 38 | + bin[`${pkg.name.split('/').pop()}-nightly`] = entrypoint |
| 39 | + for (const [name, path] of Object.entries(pkg.bin)) { |
| 40 | + bin[`${name}-nightly`] = path |
| 41 | + } |
| 42 | + |
| 43 | + await writeFile(pkgPath, `${JSON.stringify({ ...pkg, bin }, null, 2)}\n`) |
11 | 44 | } |
0 commit comments