From 16b7000e554d8da132c7301873153e5f6e2adb1f Mon Sep 17 00:00:00 2001 From: jdalton Date: Tue, 17 Nov 2026 11:43:03 -0500 Subject: [PATCH] build(sea): use Node 27.0.0-alpha.0.1.1 --- .gitignore | 7 +++ eslint.config.js | 1 + src/sea/.node-version | 1 + src/sea/README.md | 2 +- src/sea/build-sea.mts | 10 ++-- src/sea/node-version.mts | 10 ++++ src/sea/readme-version.mts | 50 +++++++++++++++++++ src/utils/quote-powershell.mts | 4 ++ test/unit/lib/terminal/output.test.mts | 13 +++-- test/unit/sea/build-sea.test.mts | 61 ++++++++++++++++++++--- test/unit/utils/quote-powershell.test.mts | 21 ++++++++ test/utils/sea.mts | 14 ++++++ tsconfig.json | 3 +- 13 files changed, 180 insertions(+), 17 deletions(-) create mode 100644 src/sea/.node-version create mode 100644 src/sea/node-version.mts create mode 100644 src/sea/readme-version.mts create mode 100644 src/utils/quote-powershell.mts create mode 100644 test/unit/utils/quote-powershell.test.mts create mode 100644 test/utils/sea.mts diff --git a/.gitignore b/.gitignore index 93d4b0b001..cef656d62f 100644 --- a/.gitignore +++ b/.gitignore @@ -232,12 +232,15 @@ !/test/unit/sea/build/lock.test.mts !/test/unit/sea/build/publish.test.mts !/test/unit/sea/build-sea.test.mts +!/test/utils/ +!/test/utils/sea.mts !/test/unit/sea/download-bytes.test.mts !/test/unit/sea/download-cache.test.mts !/test/unit/sea/runtime.test.mts !/test/unit/sea/version.test.mts !/test/unit/utils/ !/test/unit/utils/agent.test.mts +!/test/unit/utils/quote-powershell.test.mts !/test/unit/lib/ !/test/unit/lib/native/ !/test/unit/lib/native/cli-harness.test.mts @@ -1054,6 +1057,9 @@ !/src/sea/adapters/synp.mts !/src/sea/bootstrap.mts !/src/sea/build-sea.mts +!/src/sea/readme-version.mts +!/src/sea/.node-version +!/src/sea/node-version.mts !/src/sea/licenses/cdxgen-third-party/boolbase-1.0.0-ISC.txt !/src/sea/licenses/cdxgen-third-party/err-code-2.0.3-MIT.txt !/src/sea/licenses/cdxgen-third-party/imurmurhash-0.1.4-MIT.txt @@ -1179,6 +1185,7 @@ !/src/utils/purl-legacy-npm-names.json !/src/utils/purl-to-ghsa.mts !/src/utils/purl.mts +!/src/utils/quote-powershell.mts !/src/utils/registry-manifest.json !/src/utils/requirements.mts !/src/utils/sdk.mts diff --git a/eslint.config.js b/eslint.config.js index 237fb1976e..fec4727faa 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -244,6 +244,7 @@ module.exports = [ // Allow loose one-off scripts. 'scripts/*.mts', 'scripts/test/*.mts', + 'test/utils/*.mts', ], defaultProject: 'tsconfig.json', tsconfigRootDir: rootPath, diff --git a/src/sea/.node-version b/src/sea/.node-version new file mode 100644 index 0000000000..cb7cd63aad --- /dev/null +++ b/src/sea/.node-version @@ -0,0 +1 @@ +27.0.0-alpha.0.1.1 diff --git a/src/sea/README.md b/src/sea/README.md index a8e31d03f5..ba87b7661e 100644 --- a/src/sea/README.md +++ b/src/sea/README.md @@ -27,7 +27,7 @@ The CLI already runs on Node. SEA keeps that runtime and uses Node's VFS to embe pnpm build:sea -- --prototype ``` -The builder uses Node `v27.0.0-alpha.0.0.0`. It verifies the Node archive against the release `SHASUMS256.txt`. Node 27 is a prerelease, so these builds are experimental. +The builder uses Node `v27.0.0-alpha.0.1.1`. It verifies the Node archive against the release `SHASUMS256.txt`. Node 27 is a prerelease, so these builds are experimental. Build on the target OS and architecture. The builder supports `darwin`, `linux`, and `win32`, with `x64` and `arm64` archives where Node publishes them. Cross-target builds fail. diff --git a/src/sea/build-sea.mts b/src/sea/build-sea.mts index d63ed6e865..e9c8f0ad73 100644 --- a/src/sea/build-sea.mts +++ b/src/sea/build-sea.mts @@ -16,19 +16,22 @@ import { publishArtifactPair } from './build/publish.mts' import { createSeaCapabilities } from './capabilities.mts' import { downloadBytes } from './download-bytes.mts' import { cachedDownload } from './download-cache.mts' +import { NODE_VERSION } from './node-version.mts' +import { updateSeaReadmeVersion } from './readme-version.mts' import { stageSynp } from './stage-synp.mts' import { stageUv } from './stage-uv.mts' import { SEA_VERSION } from './version.mts' +import { quotePowerShell } from '../utils/quote-powershell.mts' const HERE = path.dirname(fileURLToPath(import.meta.url)) const ROOT = path.resolve(HERE, '../..') -const NODE_VERSION = '27.0.0-alpha.0.0.0' const MAX_PINNED_ARCHIVE_BYTES = 512 * 1024 * 1024 const MAX_NODE_SUMS_BYTES = 1024 * 1024 // `pnpm build:dist:src` starts by deleting `dist/`. Keep SEA artifacts outside // that managed distribution tree so an ordinary package build cannot erase // the output of a preceding SEA build. const DEFAULT_OUT = path.join(ROOT, 'build/sea') + const TARGETS = [ ['darwin', 'arm64', 'darwin-arm64'], ['darwin', 'x64', 'darwin-x64'], @@ -638,7 +641,7 @@ async function pinnedNode(target: string): Promise<{ const extracted = path.join(owned, 'unpacked') await fs.mkdir(extracted) if (platform === 'win') { - const ps = `Expand-Archive -LiteralPath '${archivePath.replaceAll("'", "''")}' -DestinationPath '${extracted.replaceAll("'", "''")}' -Force` + const ps = `Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory(${quotePowerShell(archivePath)}, ${quotePowerShell(extracted)})` await run('powershell', ['-NoProfile', '-Command', ps]) const extractedRoot = path.join( extracted, @@ -833,6 +836,7 @@ async function main(): Promise { 'No matching supported target; pass --platform and --arch explicitly for cross builds', ) } + await updateSeaReadmeVersion(path.join(HERE, 'README.md'), NODE_VERSION) const [, , triple] = target if (target[0] !== process.platform || target[1] !== process.arch) { throw new Error( @@ -1127,8 +1131,6 @@ async function main(): Promise { rootFiles, }) if (process.platform === 'win32') { - const quotePowerShell = (value: string) => - `'${value.replaceAll("'", "''")}'` const sourceList = archivePaths .map(filename => quotePowerShell(path.join(stage, filename))) .join(', ') diff --git a/src/sea/node-version.mts b/src/sea/node-version.mts new file mode 100644 index 0000000000..2d0d652431 --- /dev/null +++ b/src/sea/node-version.mts @@ -0,0 +1,10 @@ +import { readFileSync } from 'node:fs' + +export const NODE_VERSION = readFileSync( + new URL('.node-version', import.meta.url), + 'utf8', +).trim() + +if (!NODE_VERSION) { + throw new Error('SEA Node version file is empty: src/sea/.node-version') +} diff --git a/src/sea/readme-version.mts b/src/sea/readme-version.mts new file mode 100644 index 0000000000..b776e2758a --- /dev/null +++ b/src/sea/readme-version.mts @@ -0,0 +1,50 @@ +import fs from 'node:fs/promises' + +export const NODE_VERSION_START = '' +export const NODE_VERSION_END = '' + +export function renderSeaReadme(readme: string, nodeVersion: string): string { + const startIndex = readme.indexOf(NODE_VERSION_START) + const endIndex = readme.indexOf(NODE_VERSION_END) + let throws = startIndex === -1 || endIndex === -1 || startIndex >= endIndex + + if (!throws) { + throws = + readme.indexOf( + NODE_VERSION_START, + startIndex + NODE_VERSION_START.length, + ) !== -1 + } + + if (!throws) { + throws = + readme.indexOf(NODE_VERSION_END, endIndex + NODE_VERSION_END.length) !== + -1 + } + + if (throws) { + throw new Error( + 'SEA README must contain one ordered Node version marker pair', + ) + } + + const versionStart = startIndex + NODE_VERSION_START.length + return [ + readme.slice(0, versionStart), + `\`v${nodeVersion}\``, + readme.slice(endIndex), + ].join('') +} + +export async function updateSeaReadmeVersion( + readmePath: string, + nodeVersion: string, +): Promise { + const original = await fs.readFile(readmePath, 'utf8') + const updated = renderSeaReadme(original, nodeVersion) + if (updated === original) { + return false + } + await fs.writeFile(readmePath, updated) + return true +} diff --git a/src/utils/quote-powershell.mts b/src/utils/quote-powershell.mts new file mode 100644 index 0000000000..1833614457 --- /dev/null +++ b/src/utils/quote-powershell.mts @@ -0,0 +1,4 @@ +/** Quote a value as a PowerShell single-quoted string literal. */ +export function quotePowerShell(value: string): string { + return `'${value.replaceAll("'", "''")}'` +} diff --git a/test/unit/lib/terminal/output.test.mts b/test/unit/lib/terminal/output.test.mts index e230f01b03..dd4f71b5de 100644 --- a/test/unit/lib/terminal/output.test.mts +++ b/test/unit/lib/terminal/output.test.mts @@ -4,6 +4,7 @@ import { normalizeBackendOutput, normalizeBackendPaths, } from '../../../lib/terminal/output.mts' +import { readSeaNodeVersion } from '../../../utils/sea.mts' import type { TerminalBackend } from '@termless/core' @@ -30,23 +31,25 @@ describe('terminal output normalization', () => { ) }) - it('normalizes only the manifest Node version across split chunks', () => { + it('normalizes only the manifest Node version across split chunks', async () => { const received: Buffer[] = [] const backend = { feed(data: Uint8Array) { received.push(Buffer.from(data)) }, } as unknown as TerminalBackend + const nodeVersion = await readSeaNodeVersion() const normalizer = normalizeBackendOutput(backend, [ - { search: 'v27.0.0-alpha.0.0.0', replacement: 'v' }, + { search: `v${nodeVersion}`, replacement: 'v' }, ]) - backend.feed(Buffer.from('Node.js v27.0.0-alpha.')) - backend.feed(Buffer.from('0.0.0; package 1.2.3')) + const splitAt = Math.floor(nodeVersion.length / 2) + backend.feed(Buffer.from(`Node.js v${nodeVersion.slice(0, splitAt)}`)) + backend.feed(Buffer.from(`${nodeVersion.slice(splitAt)}; package 1.2.3`)) normalizer.flush() expect(Buffer.concat(received).toString()).toBe( 'Node.js v; package 1.2.3', ) - expect(normalizer.matched('v27.0.0-alpha.0.0.0')).toBe(true) + expect(normalizer.matched(`v${nodeVersion}`)).toBe(true) }) it('normalizes the socket-patch executable display token across split chunks', () => { diff --git a/test/unit/sea/build-sea.test.mts b/test/unit/sea/build-sea.test.mts index d0039d979a..bb59c1d4a1 100644 --- a/test/unit/sea/build-sea.test.mts +++ b/test/unit/sea/build-sea.test.mts @@ -15,8 +15,17 @@ import { sha512IntegrityHex, } from '../../../src/sea/build-sea.mts' import { createSeaCapabilities } from '../../../src/sea/capabilities.mts' +import { + NODE_VERSION_END, + NODE_VERSION_START, + renderSeaReadme, + updateSeaReadmeVersion, +} from '../../../src/sea/readme-version.mts' +import { readSeaNodeVersion } from '../../utils/sea.mts' const execFileAsync = promisify(execFile) +// PowerShell's archive cmdlets can be slow on shared Windows CI runners. +const WINDOWS_ARCHIVE_TEST_TIMEOUT_MS = 90_000 const root = path.resolve( path.dirname(fileURLToPath(import.meta.url)), '../../..', @@ -40,8 +49,8 @@ describe('SEA build arguments', () => { }) describe('SEA lockfile metadata', () => { - it('parses a unique exact Node archive checksum entry', () => { - const archive = 'node-v27.0.0-alpha.0.0.0-linux-x64.tar.gz' + it('parses a unique exact Node archive checksum entry', async () => { + const archive = `node-v${await readSeaNodeVersion()}-linux-x64.tar.gz` const digest = 'a'.repeat(64) expect(findNodeArchiveSha256(`${digest} ${archive}\n`, archive)).toBe( digest, @@ -86,6 +95,45 @@ describe('SEA lockfile metadata', () => { }) }) +describe('SEA README Node version', () => { + it('renders the pinned version between its hidden markers', async () => { + const nodeVersion = await readSeaNodeVersion() + const source = `The builder uses ${NODE_VERSION_START}old${NODE_VERSION_END}.` + + expect(renderSeaReadme(source, nodeVersion)).toBe( + `The builder uses ${NODE_VERSION_START}\`v${nodeVersion}\`${NODE_VERSION_END}.`, + ) + }) + + it('keeps the checked-in README version in sync with the pin', async () => { + const readme = await readFile(path.join(root, 'src/sea/README.md'), 'utf8') + + expect(renderSeaReadme(readme, await readSeaNodeVersion())).toBe(readme) + }) + + it('updates only the marked version and is idempotent', async () => { + const directory = await mkdtemp(path.join(os.tmpdir(), 'sea-readme-test-')) + const readmePath = path.join(directory, 'README.md') + const source = `Keep this. ${NODE_VERSION_START}old${NODE_VERSION_END} Keep this too.` + + try { + await writeFile(readmePath, source) + + expect( + await updateSeaReadmeVersion(readmePath, await readSeaNodeVersion()), + ).toBe(true) + expect(await readFile(readmePath, 'utf8')).toBe( + renderSeaReadme(source, await readSeaNodeVersion()), + ) + expect( + await updateSeaReadmeVersion(readmePath, await readSeaNodeVersion()), + ).toBe(false) + } finally { + await rm(directory, { recursive: true, force: true }) + } + }) +}) + describe('SEA capability policy', () => { it('keeps optional tools unavailable unless their payloads are present', () => { expect( @@ -115,7 +163,7 @@ describe('SEA archive paths', () => { }) it.skipIf(process.platform !== 'win32')( - 'keeps nested tools paths in a real Compress-Archive round trip', + 'keeps nested tools paths in a real Windows ZIP round trip', async () => { const directory = await mkdtemp(path.join(os.tmpdir(), 'sea-zip-test-')) const stage = path.join(directory, 'stage') @@ -130,7 +178,8 @@ describe('SEA archive paths', () => { 'param([string]$Stage, [string]$Archive, [string]$Expanded)', "$ErrorActionPreference = 'Stop'", "Compress-Archive -LiteralPath (Join-Path $Stage 'tools') -DestinationPath $Archive -Force", - 'Expand-Archive -LiteralPath $Archive -DestinationPath $Expanded -Force', + 'Add-Type -AssemblyName System.IO.Compression.FileSystem', + '[System.IO.Compression.ZipFile]::ExtractToDirectory($Archive, $Expanded)', "if (-not (Test-Path (Join-Path $Expanded 'tools/uv/uv.exe'))) { throw 'Nested uv executable was flattened' }", ].join('\n'), ) @@ -148,7 +197,7 @@ describe('SEA archive paths', () => { archive, expanded, ], - { timeout: 30_000 }, + { timeout: WINDOWS_ARCHIVE_TEST_TIMEOUT_MS }, ) expect( (await stat(path.join(expanded, 'tools/uv/uv.exe'))).isFile(), @@ -157,7 +206,7 @@ describe('SEA archive paths', () => { await rm(directory, { recursive: true, force: true }) } }, - 30_000, + WINDOWS_ARCHIVE_TEST_TIMEOUT_MS, ) }) diff --git a/test/unit/utils/quote-powershell.test.mts b/test/unit/utils/quote-powershell.test.mts new file mode 100644 index 0000000000..d81491c601 --- /dev/null +++ b/test/unit/utils/quote-powershell.test.mts @@ -0,0 +1,21 @@ +import { describe, expect, it } from 'vitest' + +import { quotePowerShell } from '../../../src/utils/quote-powershell.mts' + +describe('quotePowerShell', () => { + it('wraps a value in a PowerShell single-quoted string', () => { + expect(quotePowerShell('C:\\tools\\node.zip')).toBe("'C:\\tools\\node.zip'") + }) + + it('doubles single quotes inside the value', () => { + expect(quotePowerShell("C:\\Users\\O'Neil\\node.zip")).toBe( + "'C:\\Users\\O''Neil\\node.zip'", + ) + }) + + it('leaves PowerShell expansion characters literal', () => { + expect(quotePowerShell('$(Write-Host `value`)')).toBe( + "'$(Write-Host `value`)'", + ) + }) +}) diff --git a/test/utils/sea.mts b/test/utils/sea.mts new file mode 100644 index 0000000000..bfbb126bdc --- /dev/null +++ b/test/utils/sea.mts @@ -0,0 +1,14 @@ +import { readFile } from 'node:fs/promises' +import path from 'node:path' +import { fileURLToPath } from 'node:url' + +const REPOSITORY_ROOT = path.resolve( + path.dirname(fileURLToPath(import.meta.url)), + '../..', +) + +export async function readSeaNodeVersion(): Promise { + return ( + await readFile(path.join(REPOSITORY_ROOT, 'src/sea/.node-version'), 'utf8') + ).trim() +} diff --git a/tsconfig.json b/tsconfig.json index 280df1c38a..84b2dcaa23 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,8 @@ "src/**/*.mts", "scripts/ci/**/*.mts", "scripts/lib/**/*.mts", - "scripts/release/**/*.mts" + "scripts/release/**/*.mts", + "scripts/utils/**/*.mts" ], "exclude": [ "src/**/*.test.mts",