fix: use npm co-located with the action node binary

This commit is contained in:
Ben Quarmby
2026-04-27 15:50:53 -07:00
parent 903f9c1a6e
commit 5a9e198ae2
2 changed files with 155 additions and 152 deletions
+149 -150
View File
File diff suppressed because one or more lines are too long
+6 -2
View File
@@ -29,7 +29,10 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
await writeFile(path.join(dest, 'package.json'), packageJson) await writeFile(path.join(dest, 'package.json'), packageJson)
await writeFile(path.join(dest, 'package-lock.json'), JSON.stringify(lockfile)) await writeFile(path.join(dest, 'package-lock.json'), JSON.stringify(lockfile))
const npmExitCode = await runCommand('npm', ['ci'], { cwd: dest }) // On Windows, the PATH key casing varies; search case-insensitively.
const pathKey = Object.keys(process.env).find(k => k.toUpperCase() === 'PATH') ?? 'PATH'
const npmEnv = { ...process.env, [pathKey]: path.dirname(process.execPath) + path.delimiter + process.env[pathKey] }
const npmExitCode = await runCommand('npm', ['ci'], { cwd: dest, env: npmEnv })
if (npmExitCode !== 0) { if (npmExitCode !== 0) {
return npmExitCode return npmExitCode
} }
@@ -155,10 +158,11 @@ function getSystemNodeVersion(): Promise<{ major: number; minor: number }> {
}) })
} }
function runCommand(cmd: string, args: string[], opts: { cwd: string }): Promise<number> { function runCommand(cmd: string, args: string[], opts: { cwd: string; env?: Record<string, string | undefined> }): Promise<number> {
return new Promise<number>((resolve, reject) => { return new Promise<number>((resolve, reject) => {
const cp = spawn(cmd, args, { const cp = spawn(cmd, args, {
cwd: opts.cwd, cwd: opts.cwd,
env: opts.env,
stdio: ['pipe', 'inherit', 'inherit'], stdio: ['pipe', 'inherit', 'inherit'],
shell: process.platform === 'win32', shell: process.platform === 'win32',
}) })