fix: enable shell mode for npm on Windows (#1963)

Fix Windows plugin install: run npm via shell only on win32 to execute npm.cmd; keep default spawn behavior for other commands.
This commit is contained in:
ANDRES FELIPE CARDONA SANTA 2026-01-26 00:35:16 -05:00
parent c8063bdcd8
commit 2516dc78a1

View File

@ -63,15 +63,14 @@ export async function runCommandWithTimeout(
const { windowsVerbatimArguments } = options; const { windowsVerbatimArguments } = options;
const hasInput = input !== undefined; const hasInput = input !== undefined;
const shouldSuppressNpmFund = (() => { const cmd = path.basename(argv[0] ?? "");
const cmd = path.basename(argv[0] ?? ""); const isNpmCommand = cmd === "npm" || cmd === "npm.cmd" || cmd === "npm.exe";
if (cmd === "npm" || cmd === "npm.cmd" || cmd === "npm.exe") return true; const isNpmViaCli =
if (cmd === "node" || cmd === "node.exe") { (cmd === "node" || cmd === "node.exe") && (argv[1] ?? "").includes("npm-cli.js");
const script = argv[1] ?? ""; const shouldSuppressNpmFund = isNpmCommand || isNpmViaCli;
return script.includes("npm-cli.js");
} // On Windows, npm is a .cmd batch file that requires shell mode to execute
return false; const useShell = process.platform === "win32" && isNpmCommand;
})();
const resolvedEnv = env ? { ...process.env, ...env } : { ...process.env }; const resolvedEnv = env ? { ...process.env, ...env } : { ...process.env };
if (shouldSuppressNpmFund) { if (shouldSuppressNpmFund) {
@ -85,6 +84,7 @@ export async function runCommandWithTimeout(
cwd, cwd,
env: resolvedEnv, env: resolvedEnv,
windowsVerbatimArguments, windowsVerbatimArguments,
shell: useShell,
}); });
// Spawn with inherited stdin (TTY) so tools like `pi` stay interactive when needed. // Spawn with inherited stdin (TTY) so tools like `pi` stay interactive when needed.
return await new Promise((resolve, reject) => { return await new Promise((resolve, reject) => {