Skip to content

Commit 6a1b459

Browse files
author
tsouth89
committed
fix(build): isolate the self-check from Node's global module folders
Clearing NODE_PATH does not isolate CommonJS resolution. Node still falls back to $HOME/.node_modules, $HOME/.node_libraries and the install prefix, so a globally installed copy of a dependency missing from the package would satisfy the probe and the check would report success on a broken artifact. Reproduced by putting a package in %USERPROFILE%\.node_modules: with NODE_PATH cleared it still resolved; with --no-global-search-paths it does not. Reported by @SunkenInTime.
1 parent 22731fd commit 6a1b459

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

‎scripts/build-desktop-artifact.ts‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,15 +1408,23 @@ const verifyPackagedBundleIsSelfContained = Effect.fn("verifyPackagedBundleIsSel
14081408
// and the bun adapters are only covered by the unpack globs and the
14091409
// inlined-native check below.
14101410
yield* runCommand(
1411-
ChildProcess.make(process.execPath, [entryPoint, "--version"], {
1412-
cwd: probeApp,
1413-
stdout: "pipe",
1414-
stderr: "pipe",
1415-
// NODE_PATH would let a createRequire call inside the bundle resolve a
1416-
// missing external from outside the packaged tree, which is the whole
1417-
// thing this is trying to rule out.
1418-
env: { ...process.env, NODE_PATH: "" },
1419-
}),
1411+
ChildProcess.make(
1412+
process.execPath,
1413+
// --no-global-search-paths because clearing NODE_PATH is not enough:
1414+
// CommonJS resolution still falls back to $HOME/.node_modules,
1415+
// $HOME/.node_libraries and the install prefix, so a globally installed
1416+
// copy of a missing dependency would quietly satisfy this check.
1417+
["--no-global-search-paths", entryPoint, "--version"],
1418+
{
1419+
cwd: probeApp,
1420+
stdout: "pipe",
1421+
stderr: "pipe",
1422+
// NODE_PATH would let a createRequire call inside the bundle resolve
1423+
// a missing external from outside the packaged tree, which is the
1424+
// whole thing this is trying to rule out.
1425+
env: { ...process.env, NODE_PATH: "" },
1426+
},
1427+
),
14201428
{ label: "bundle self-containment check (node bin.mjs --version)", verbose: input.verbose },
14211429
).pipe(
14221430
// Printing a version should be immediate. A regression that blocks (on

0 commit comments

Comments
 (0)