cli: share app archive across Node builds (#44331)

This commit is contained in:
Simon Klee 2026-08-23 09:11:54 +02:00 committed by GitHub
parent 6cd3da1d4c
commit 853d3534e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 45 additions and 7 deletions

View file

@ -27,6 +27,9 @@ if (outdir === path.join(dir, "dist-node")) {
const bundleOnly = process.argv.includes("--bundle-only")
const single = process.argv.includes("--single")
const skipInstall = process.argv.includes("--skip-install")
const appArchiveOnly = process.argv.includes("--app-archive-only")
const requestedArchive = process.argv.find((arg) => arg.startsWith("--app-archive="))?.slice("--app-archive=".length)
const archivePath = requestedArchive ? path.resolve(dir, requestedArchive) : undefined
const requested = process.argv.find((arg) => arg.startsWith("--target="))?.slice("--target=".length)
const allTargets = [
nodeTarget("linux", "arm64"),
@ -41,6 +44,14 @@ const targets = requested
? [nodeTarget(process.platform, process.arch)]
: allTargets
process.chdir(dir)
if (!skipInstall) run(process.execPath, ["install", "--os=*", "--cpu=*"])
if (appArchiveOnly) {
if (!archivePath) throw new Error("--app-archive-only requires --app-archive=<path>")
await mkdir(path.dirname(archivePath), { recursive: true })
await writeFile(archivePath, await buildAppArchive(Script.channel))
process.exit(0)
}
if (targets.length === 0) {
if (requested === "darwin-x64") throw new Error("Node 26.4 SEA does not support macOS x64")
throw new Error(`Unknown Node target: ${requested}`)
@ -48,15 +59,12 @@ if (targets.length === 0) {
if (!bundleOnly && targets.some((target) => target.platform === "darwin" && target.arch === "x64")) {
throw new Error("Node 26.4 SEA does not support macOS x64")
}
process.chdir(dir)
if (!skipInstall) run(process.execPath, ["install", "--os=*", "--cpu=*"])
const appArchive = archivePath ? (await Bun.file(archivePath).text()).trim() : await buildAppArchive(Script.channel)
if (!bundleOnly) await rm(outdir, { recursive: true, force: true })
const builder =
!bundleOnly || targets.some((target) => target.platform === process.platform && target.arch === process.arch)
? await resolveHostNode()
: undefined
const appArchive = await buildAppArchive(Script.channel)
// Vite silently rewrites text imports of known asset types (.txt) to asset
// URL strings when the raw-text plugin doesn't intercept them first — the