@@ -62,19 +62,18 @@ export function ExecBuiltin(props: ExecBuiltinProps) {
6262 "node:stream" : [ { name : "Stream" , default : true , type : true } ]
6363 } ) }
6464 builtinImports = { defu ( rest . builtinImports ?? { } , {
65- env : [ "isWindows" ]
65+ env : [ "isWindows" , "env" , { name : "Env" , type : true } ]
6666 } ) } >
6767 < FunctionDeclaration
6868 name = "resolveCommandEnv"
6969 parameters = { [
7070 {
7171 name : "params" ,
72- type : "{ argv: string[]; env?: NodeJS.ProcessEnv; baseEnv?: NodeJS.ProcessEnv; }"
72+ type : "{ argv: string[]; env?: NodeJS.ProcessEnv; }"
7373 }
7474 ] }
7575 returnType = "NodeJS.ProcessEnv" >
76- { code `const baseEnv = params.baseEnv ?? process.env;
77- const argv = params.argv;
76+ { code `const argv = params.argv;
7877const shouldSuppressNpmFund = (() => {
7978 const cmd = basename(argv[0] ?? "");
8079 if (cmd === "npm" || cmd === "npm.cmd" || cmd === "npm.exe") {
@@ -88,17 +87,19 @@ const shouldSuppressNpmFund = (() => {
8887 return false;
8988})();
9089
91- const mergedEnv = params.env ? { ...baseEnv, ...params.env } : { ...baseEnv };
92- const resolvedEnv = Object.fromEntries(
93- Object.entries(mergedEnv)
94- .filter(([, value]) => value !== undefined)
95- .map(([key, value]) => [key, String(value)])
90+ const result = Object.fromEntries(
91+ Object.entries({
92+ ...env,
93+ ...(params.env ?? {})
94+ })
95+ .filter(([, value]) => value !== undefined)
96+ .map(([key, value]) => [key, String(value)])
9697);
9798if (shouldSuppressNpmFund) {
98- resolvedEnv .NPM_CONFIG_FUND ??= "false";
99- resolvedEnv .npm_config_fund ??= "false";
99+ result .NPM_CONFIG_FUND ??= "false";
100+ result .npm_config_fund ??= "false";
100101}
101- return resolvedEnv; ` }
102+ return result; ` }
102103 </ FunctionDeclaration >
103104 < Spacing />
104105 < FunctionDeclaration
@@ -283,7 +284,7 @@ return false;`}
283284 defaultValue = "300000"
284285 />
285286 </ TSDoc >
286- < InterfaceMember name = "timeoutMs" type = "number" />
287+ < InterfaceMember name = "timeoutMs" optional type = "number" />
287288 < Spacing />
288289 < TSDoc heading = "The current working directory of the child process." />
289290 < InterfaceMember name = "cwd" optional type = "string" />
@@ -347,43 +348,40 @@ return false;`}
347348 typeof optionsOrTimeoutMs === "number"
348349 ? { timeoutMs: optionsOrTimeoutMs }
349350 : optionsOrTimeoutMs;
350- const { timeoutMs, cwd, input, env, noOutputTimeoutMs } = options;
351- const hasInput = input !== undefined;
352- const resolvedEnv = resolveCommandEnv({ argv, env });
353- const stdio = resolveCommandStdio({ hasInput, preferInherit: true });
351+ const { timeoutMs = 300000, cwd, input, noOutputTimeoutMs } = options;
354352
355- const finalArgv =
353+ const resolvedArgv =
356354 isWindows
357355 ? (resolveNpmArgvForWindows(argv) ?? argv)
358356 : argv;
359357const resolvedCommand =
360- finalArgv !== argv
361- ? (finalArgv [0] ?? "")
358+ resolvedArgv !== argv
359+ ? (resolvedArgv [0] ?? "")
362360 : resolveCommand(argv[0] ?? "");
363361const useCmdWrapper = isWindowsBatchCommand(resolvedCommand);
364362
365363const child = _spawn(
366364 useCmdWrapper
367- ? (process. env.ComSpec ?? "cmd.exe")
365+ ? (env.COMSPEC ?? "cmd.exe")
368366 : resolvedCommand,
369367 useCmdWrapper
370368 ? [
371369 "/d",
372370 "/s",
373371 "/c",
374- buildCmdExeCommandLine(resolvedCommand, finalArgv .slice(1))
372+ buildCmdExeCommandLine(resolvedCommand, resolvedArgv .slice(1))
375373 ]
376- : finalArgv .slice(1), {
377- stdio,
374+ : resolvedArgv .slice(1), {
375+ stdio: resolveCommandStdio({ hasInput: input !== undefined, preferInherit: true }) ,
378376 cwd,
379- env: resolvedEnv ,
377+ env: resolveCommandEnv({ argv, env: options.env }) ,
380378 windowsHide: true,
381379 windowsVerbatimArguments: useCmdWrapper
382380 ? true
383381 : options.windowsVerbatimArguments,
384382 ...(shouldSpawnWithShell({
385383 resolvedCommand: useCmdWrapper
386- ? (process. env.ComSpec ?? "cmd.exe")
384+ ? (env.COMSPEC ?? "cmd.exe")
387385 : resolvedCommand,
388386 platform: process.platform
389387 })
@@ -453,7 +451,7 @@ return new Promise((resolve, reject) => {
453451 }, timeoutMs >= 0 ? timeoutMs : Number.POSITIVE_INFINITY);
454452 armNoOutputTimer();
455453
456- if (hasInput && child.stdin) {
454+ if (input !== undefined && child.stdin) {
457455 child.stdin.write(input ?? "");
458456 child.stdin.end();
459457 }
@@ -506,7 +504,7 @@ return new Promise((resolve, reject) => {
506504 explicitCode: childExitState?.code ?? code,
507505 childExitCode: child.exitCode,
508506 resolvedSignal,
509- usesWindowsExitCodeShim: isWindows && (useCmdWrapper || finalArgv !== argv),
507+ usesWindowsExitCodeShim: isWindows && (useCmdWrapper || resolvedArgv !== argv),
510508 timedOut,
511509 noOutputTimedOut,
512510 killIssuedByTimeout
@@ -626,23 +624,16 @@ return new Promise((resolve, reject) => {
626624 name = "execSync"
627625 parameters = { [
628626 { name : "argv" , type : "string[]" } ,
629- { name : "options" , type : "SpawnOptions" , optional : true }
627+ { name : "options" , type : "SpawnOptions" , default : "{}" }
630628 ] }
631629 returnType = "string" >
632630 { code `return execFileSync(argv.length > 0 ? argv[0] : "", argv.slice(1), {
633631 encoding: "utf8",
634632 stdio: ["ignore", "pipe", "ignore"],
635- timeout: options?.timeoutMs ?? 300000,
636- env: options?.env ? resolveCommandEnv({ argv, env: options.env }) : process.env,
637- cwd: options?.cwd,
638- windowsHide: true,
639- windowsVerbatimArguments: options?.windowsVerbatimArguments,
640- ...(shouldSpawnWithShell({
641- resolvedCommand: argv[0] ?? "",
642- platform: process.platform
643- })
644- ? { shell: true }
645- : {})
633+ timeout: options.timeoutMs ?? 300000,
634+ env: resolveCommandEnv({ argv, env: options.env }),
635+ cwd: options.cwd || process.cwd(),
636+ windowsHide: true
646637 }).trim(); ` }
647638 </ FunctionDeclaration >
648639 < Spacing />
0 commit comments