|
| 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 | constdirs=['create-nuxt','nuxi','nuxt-cli'] |
5 | 6 |
|
6 | 7 | for(constdirofdirs){ |
7 | | -awaitx('changelogen',['--canary','nightly','--publish'],{ |
8 | | -nodeOptions: {stdio: 'inherit',cwd: resolve('packages',dir)}, |
9 | | -throwOnError: true, |
10 | | -}) |
| 8 | +constcwd=resolve('packages',dir) |
| 9 | +constpkgPath=resolve(cwd,'package.json') |
| 10 | +constoriginal=awaitreadFile(pkgPath,'utf8') |
| 11 | + |
| 12 | +awaitaddNightlyBins(pkgPath,original) |
| 13 | + |
| 14 | +try{ |
| 15 | +awaitx('changelogen',['--canary','nightly','--publish'],{ |
| 16 | +nodeOptions: {stdio: 'inherit', cwd }, |
| 17 | +throwOnError: true, |
| 18 | +}) |
| 19 | +} |
| 20 | +finally{ |
| 21 | +awaitwriteFile(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 | +asyncfunctionaddNightlyBins(pkgPath,original){ |
| 31 | +constpkg=JSON.parse(original) |
| 32 | +if(!pkg.bin){ |
| 33 | +return |
| 34 | +} |
| 35 | + |
| 36 | +constbin={ ...pkg.bin} |
| 37 | +constentrypoint=Object.values(pkg.bin)[0] |
| 38 | +bin[`${pkg.name.split('/').pop()}-nightly`]=entrypoint |
| 39 | +for(const[name,path]ofObject.entries(pkg.bin)){ |
| 40 | +bin[`${name}-nightly`]=path |
| 41 | +} |
| 42 | + |
| 43 | +awaitwriteFile(pkgPath,`${JSON.stringify({ ...pkg, bin },null,2)}\n`) |
11 | 44 | } |
0 commit comments