From 1b56ab292040ddb897872e27a4f8cd3d74e346e1 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 17 Nov 2026 15:55:16 +0100 Subject: [PATCH 1/2] =?UTF-8?q?test:=20reproduce=20#1664=20=E2=80=94=20npm?= =?UTF-8?q?=20calls=20run=20the=20installer's=20shell=20wrapper=20beside?= =?UTF-8?q?=20Node=20instead=20of=20npm-cli.js=20in=20node=5Fmodules?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ports/npm-cli.test.ts | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/ports/npm-cli.test.ts b/src/ports/npm-cli.test.ts index d70cb98d5..4ef64420e 100644 --- a/src/ports/npm-cli.test.ts +++ b/src/ports/npm-cli.test.ts @@ -46,6 +46,41 @@ async function stubNpm( return { npm, dataDirectory, script }; } +// why: #1664: the official Windows installer puts node.exe, a POSIX shell wrapper named `npm` and +// `node_modules/npm/bin/npm-cli.js` side by side, with no symlink (Node 22.23.5, Windows 11). The +// wrapper's first lines are copied from that install; node reads them as JavaScript and fails. +const WINDOWS_NPM_WRAPPER = `#!/usr/bin/env bash + +# This is used by the Node.js installer, which expects the cygwin/mingw +# shell script to already be present in the npm dependency folder. + +(set -o igncr) 2>/dev/null && set -o igncr; # cygwin encoding fix +`; + +async function windowsLayoutNpm(): Promise<{ + npm: NodeNpmCli; + dataDirectory: string; + script: string; +}> { + const tree = await realpath(await mkdtemp(join(tmpdir(), "simlock-npm-"))); + trees.push(tree); + const dataDirectory = join(tree, "data"); + await mkdir(dataDirectory); + const nodejs = join(tree, "nodejs"); + await mkdir(join(nodejs, "node_modules", "npm", "bin"), { recursive: true }); + await symlink(process.execPath, join(nodejs, "node")); + await writeFile(join(nodejs, "npm"), WINDOWS_NPM_WRAPPER); + const script = join(nodejs, "node_modules", "npm", "bin", "npm-cli.js"); + await writeFile(script, STUB_NPM); + const npm = new NodeNpmCli({ + runner: new NodeProcessRunner(), + filesystem: new NodeFilesystem(), + dataDirectory, + execPath: join(nodejs, "node"), + }); + return { npm, dataDirectory, script }; +} + describe("NodeNpmCli", () => { it("runs npm with the daemon's Node, in its data directory", async () => { const { npm, dataDirectory, script } = await stubNpm(); @@ -63,6 +98,24 @@ describe("NodeNpmCli", () => { } }); + it("runs npm-cli.js from node_modules beside Node when npm there is the installer's shell wrapper", async () => { + const { npm, dataDirectory, script } = await windowsLayoutNpm(); + + const outcomes = [ + await npm.view("simlock@0.4.0"), + await npm.install("simlock@0.4.0"), + await npm.globalRoot(), + ]; + + expect(outcomes).toEqual( + [ + ["view", "simlock@0.4.0", "version"], + ["i", "-g", "simlock@0.4.0"], + ["root", "-g"], + ].map((argv) => ({ ok: true, output: JSON.stringify({ argv, script, cwd: dataDirectory }) })), + ); + }); + it("keeps the last 2000 characters of npm's stderr when it fails", async () => { const { npm } = await stubNpm(); From 9f26738bd7a764fdfce55a32e4f7892e8ef9dad8 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 17 Nov 2026 15:57:43 +0100 Subject: [PATCH 2/2] fix(ports): npm runs from node_modules beside Node when the installer has no npm symlink (#1664) --- src/ports/npm-cli.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ports/npm-cli.ts b/src/ports/npm-cli.ts index 3c084d527..af0197a61 100644 --- a/src/ports/npm-cli.ts +++ b/src/ports/npm-cli.ts @@ -79,9 +79,16 @@ export class NodeNpmCli implements NpmCli { return this.#run(["root", "-g"], SHORT_LIMIT_MS, "30 seconds"); } + // why: the Windows installer has no `npm` symlink, only a shell wrapper Node cannot parse. + async #script(node: string): Promise { + const bundled = join(dirname(node), "node_modules", "npm", "bin", "npm-cli.js"); + if (await this.options.filesystem.exists(bundled)) return bundled; + return this.options.filesystem.realpath(join(dirname(node), "npm")); + } + async #run(args: readonly string[], timeoutMs: number, limit: string): Promise { const node = this.options.execPath ?? process.execPath; - const script = await this.options.filesystem.realpath(join(dirname(node), "npm")); + const script = await this.#script(node); const result = await this.options.runner.run(node, [script, ...args], { cwd: this.options.dataDirectory, timeoutMs,