-
-
Notifications
You must be signed in to change notification settings - Fork 64
feat(sea): let users override the base Node binary #279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
408dfde
8dd9bc1
9d9d4d3
cc6e680
f5a1d3a
f47221b
32b66d4
1648fc2
a2834a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -192,6 +192,18 @@ export async function exec( | |
| } | ||
|
|
||
| if (flags.sea) { | ||
| // Base-node override (both forms are mutually exclusive). nodePath embeds a | ||
| // specific binary; useLocalNode embeds the Node running pkg. Either lets you | ||
| // ship a SEA built on a custom runtime (e.g. one linked against older glibc). | ||
| if (flags.seaNodePath && flags.seaUseLocalNode) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Correctness — multi-target silently bakes the wrong binary. The mutual-exclusion guard is good, but the bigger footgun is unguarded: Add a guard here: when |
||
| throw wasReported( | ||
| "Specify either '--sea-node-path' or '--sea-use-local-node', not both", | ||
| ); | ||
| } | ||
| const seaBase = { | ||
| nodePath: flags.seaNodePath, | ||
| useLocalNode: flags.seaUseLocalNode, | ||
| }; | ||
| if (inputJson || configJson) { | ||
| // Enhanced SEA mode — use walker pipeline. | ||
| // seaEnhanced validates the host Node version and minTargetMajor itself. | ||
|
|
@@ -202,6 +214,7 @@ export async function exec( | |
| params: { ...params, seaMode: true }, | ||
| addition: isConfiguration(input) ? input : undefined, | ||
| doCompress: flags.compress, | ||
| ...seaBase, | ||
| }); | ||
| } else { | ||
| // Simple SEA mode — plain .js file without package.json. | ||
|
|
@@ -216,6 +229,7 @@ export async function exec( | |
| await sea(inputFin, { | ||
| targets, | ||
| signature: flags.signature, | ||
| ...seaBase, | ||
| }); | ||
| } | ||
| return; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,6 +66,10 @@ export interface PkgOptions { | |
| debug?: boolean; | ||
| signature?: boolean; | ||
| sea?: boolean; | ||
| /** SEA mode: path to a base Node binary to embed (overrides the download). */ | ||
| seaNodePath?: string; | ||
| /** SEA mode: embed the Node binary running pkg (process.execPath) as the base. */ | ||
| seaUseLocalNode?: boolean; | ||
| } | ||
|
|
||
| export interface PackageJson { | ||
|
|
@@ -200,4 +204,12 @@ export interface PkgExecOptions { | |
| noDictionary?: string[]; | ||
| /** Sign macOS binaries when applicable. Default `true`. */ | ||
| signature?: boolean; | ||
| /** | ||
| * SEA mode: path to a base Node binary to embed instead of downloading one | ||
| * from nodejs.org. Use to embed a custom build (e.g. one linked against an | ||
| * older glibc). Its major version must match the target's. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 This claim isn't enforced. "Its major version must match the target's" — nothing checks it. Either validate |
||
| */ | ||
| seaNodePath?: string; | ||
| /** SEA mode: embed the Node binary running pkg (`process.execPath`) as the base. */ | ||
| seaUseLocalNode?: boolean; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| 'use strict'; | ||
|
|
||
| // Packaged into a SEA with `--sea-use-local-node`, so the embedded runtime is | ||
| // the same Node that ran pkg (rather than a downloaded one). Output is asserted | ||
| // by main.js. process.pkg confirms the enhanced SEA bootstrap is active. | ||
| console.log('local-node SEA OK:' + (process.pkg != null)); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| 'use strict'; | ||
|
|
||
| const assert = require('assert'); | ||
| const utils = require('../utils.js'); | ||
|
|
||
| // Enhanced SEA requires Node.js >= 22 | ||
| if (utils.getNodeMajorVersion() < 22) { | ||
| return; | ||
| } | ||
|
|
||
| assert(__dirname === process.cwd()); | ||
|
|
||
| const input = './package.json'; | ||
| const testName = 'test-95-sea-local-node'; | ||
|
|
||
| const newcomers = utils.seaHostOutputs(testName); | ||
|
|
||
| const before = utils.filesBefore(newcomers); | ||
|
|
||
| // `--sea-use-local-node` embeds the Node binary running pkg as the SEA base | ||
| // instead of downloading one. Exercises the base-node override end to end (and, | ||
| // on Node >= 25.5 hosts, the in-core `--build-sea` injection path). | ||
| utils.runSeaHostOnly(input, testName, ['--sea-use-local-node']); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 |
||
|
|
||
| utils.assertSeaOutput(testName, 'local-node SEA OK:true\n'); | ||
|
|
||
| utils.filesAfter(before, newcomers, { tolerateWindowsEbusy: true }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "name": "test-95-sea-local-node", | ||
| "version": "1.0.0", | ||
| "main": "index.js", | ||
| "bin": "index.js" | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 Docs now stale/contradictory.
docs-site/guide/custom-node.mdcurrently tells users SEA "does not honourPKG_NODE_PATH… For SEA, useprocess.execPath… directly." After this PR that page is wrong and needs updating in the same PR. (If you adopt thePKG_NODE_PATH-in-SEA approach from the review summary, this becomes a one-line "now works in SEA too" rather than documenting a second mechanism.)