Skip to content

Commit af14cc8

Browse files
committed
chore: add new binary paths for nightly release
1 parent 33101d9 commit af14cc8

1 file changed

Lines changed: 37 additions & 4 deletions

File tree

scripts/release-nightly.mjs

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,44 @@
1+
import { readFile, writeFile } from 'node:fs/promises'
12
import { resolve } from 'node:path'
23
import { x } from 'tinyexec'
34

45
const dirs = ['create-nuxt', 'nuxi', 'nuxt-cli']
56

67
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`)
1144
}

0 commit comments

Comments
 (0)