Skip to content

Commit a06ae42

Browse files
committed
shell true
1 parent e0836d7 commit a06ae42

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib_dev/process.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
import * as child_process from "node:child_process";
22
import * as fs from "node:fs/promises";
33
import * as path from "node:path";
4+
import { execPath } from "node:process";
45
import { bsc_exe, rescript_legacy_exe } from "#cli/bins";
56

7+
// On GitHub Actions runners, `npm` is not a native binary but a shell script
8+
// installed alongside the `node` executable in the hostedtoolcache directory.
9+
// Spawning it directly by name (`spawn("npm")`) can fail with ENOENT because
10+
// the PATH in CI sometimes gets polluted with bogus entries (e.g. `/tmp/xfs-*`
11+
// prepended), causing `execvp` to stop searching before reaching the real npm.
12+
// To avoid relying on PATH resolution, we resolve `npm` relative to
13+
// `process.execPath` (the current Node binary) and run it with `shell: true`
14+
// so the shebang (`#!/usr/bin/env node`) inside the npm script is honoured.
15+
const npmBin = path.join(path.dirname(execPath), "npm");
16+
617
/**
718
* @typedef {{
819
* throwOnFail?: boolean,
@@ -52,6 +63,7 @@ export function setup(cwd = process.cwd()) {
5263

5364
if (process.env.CI) {
5465
console.log("[exec] PATH =", options.env?.PATH ?? process.env.PATH);
66+
console.log("[npm] using", npmBin);
5567
}
5668

5769
const stdoutChunks = [];
@@ -256,7 +268,10 @@ export function setup(cwd = process.cwd()) {
256268
* @return {Promise<ExecResult>}
257269
*/
258270
npm(args = [], options = {}) {
259-
return exec("npm", args, options);
271+
return exec(npmBin, args, {
272+
...options,
273+
shell: process.platform !== "win32" || options.shell,
274+
});
260275
},
261276
};
262277
}

0 commit comments

Comments
 (0)