fix(process): apply undefined env removals (#107258)

Co-authored-by: Pavan Kumar Gondhi <pavangondhi@gmail.com>
This commit is contained in:
Peter Steinberger
2026-07-14 00:43:30 -07:00
committed by GitHub
parent 4974750614
commit 489690fa16
2 changed files with 4 additions and 39 deletions
+4 -3
View File
@@ -12,9 +12,6 @@ function assignChildEnvValue(params: {
platform: NodeJS.Platform;
value: string | undefined;
}): void {
if (params.value === undefined) {
return;
}
if (params.platform === "win32") {
const normalizedKey = params.key.toLowerCase();
for (const existingKey of Object.keys(params.env)) {
@@ -23,6 +20,10 @@ function assignChildEnvValue(params: {
}
}
}
if (params.value === undefined) {
delete params.env[params.key];
return;
}
params.env[params.key] = params.value;
}
-36
View File
@@ -17,42 +17,6 @@ export type { SpawnResult } from "./exec-result.js";
export { resolveCommandEnv, shouldSpawnWithShell, spawnCommand } from "./exec-spawn.js";
export type { SpawnCommandOptions } from "./exec-spawn.js";
function assignChildEnvValue(params: {
env: NodeJS.ProcessEnv;
key: string;
platform: NodeJS.Platform;
value: string | undefined;
}): void {
if (params.platform === "win32") {
const normalizedKey = params.key.toLowerCase();
for (const existingKey of Object.keys(params.env)) {
if (existingKey.toLowerCase() === normalizedKey && existingKey !== params.key) {
delete params.env[existingKey];
}
}
}
if (params.value === undefined) {
delete params.env[params.key];
return;
}
params.env[params.key] = params.value;
}
function mergeChildEnv(params: {
baseEnv: NodeJS.ProcessEnv;
env?: NodeJS.ProcessEnv;
platform: NodeJS.Platform;
}): NodeJS.ProcessEnv {
const resolvedEnv: NodeJS.ProcessEnv = {};
for (const [key, value] of Object.entries(params.baseEnv)) {
assignChildEnvValue({ env: resolvedEnv, key, platform: params.platform, value });
}
for (const [key, value] of Object.entries(params.env ?? {})) {
assignChildEnvValue({ env: resolvedEnv, key, platform: params.platform, value });
}
return resolvedEnv;
}
const DEFAULT_EXEC_MAX_BUFFER_BYTES = 1024 * 1024;
export type RunExecOptions = {