
























@@ -41,6 +41,7 @@ const NPM_GLOBAL_INSTALL_OMIT_OPTIONAL_FLAGS = [
4141"--omit=optional",
4242 ...NPM_GLOBAL_INSTALL_QUIET_FLAGS,
4343] as const;
44+const NPM_CONFIG_SCRIPT_SHELL_KEYS = ["NPM_CONFIG_SCRIPT_SHELL", "npm_config_script_shell"];
4445const FIRST_PACKAGED_DIST_INVENTORY_VERSION = { major: 2026, minor: 4, patch: 15 };
4546const OMITTED_PRIVATE_QA_BUNDLED_PLUGIN_ROOTS = new Set([
4647"dist/extensions/qa-channel",
@@ -315,6 +316,31 @@ function applyCorepackDownloadPromptEnv(env: Record<string, string>) {
315316}
316317}
317318319+function hasNpmScriptShellSetting(env: NodeJS.ProcessEnv): boolean {
320+return NPM_CONFIG_SCRIPT_SHELL_KEYS.some((key) => Boolean(env[key]?.trim()));
321+}
322+323+function resolvePosixNpmScriptShell(env: NodeJS.ProcessEnv): string | null {
324+if (process.platform === "win32") {
325+return null;
326+}
327+if (fsSync.existsSync("/bin/sh")) {
328+return "/bin/sh";
329+}
330+const shell = env.SHELL?.trim();
331+return shell && path.isAbsolute(shell) && fsSync.existsSync(shell) ? shell : null;
332+}
333+334+function applyPosixNpmScriptShellEnv(env: Record<string, string>) {
335+if (hasNpmScriptShellSetting(env)) {
336+return;
337+}
338+const scriptShell = resolvePosixNpmScriptShell(env);
339+if (scriptShell) {
340+env.NPM_CONFIG_SCRIPT_SHELL = scriptShell;
341+}
342+}
343+318344export function resolveGlobalInstallSpec(params: {
319345packageName: string;
320346tag: string;
@@ -344,8 +370,13 @@ export async function createGlobalInstallEnv(
344370const hasCorepackDownloadPromptSetting = Boolean(
345371sourceEnv.COREPACK_ENABLE_DOWNLOAD_PROMPT?.trim(),
346372);
373+const missingPosixScriptShell =
374+Boolean(resolvePosixNpmScriptShell(sourceEnv)) && !hasNpmScriptShellSetting(sourceEnv);
347375const requiresMergedEnv =
348-pathPrepend.length > 0 || process.platform === "win32" || !hasCorepackDownloadPromptSetting;
376+pathPrepend.length > 0 ||
377+process.platform === "win32" ||
378+!hasCorepackDownloadPromptSetting ||
379+missingPosixScriptShell;
349380if (!requiresMergedEnv) {
350381return env;
351382}
@@ -357,6 +388,7 @@ export async function createGlobalInstallEnv(
357388applyPathPrepend(merged, pathPrepend);
358389applyWindowsPackageInstallEnv(merged);
359390applyCorepackDownloadPromptEnv(merged);
391+applyPosixNpmScriptShellEnv(merged);
360392return merged;
361393}
362394此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。