Skip to content

Commit 5511966

Browse files
committed
fix(spawn): preserve Windows process.env Proxy behavior
When no custom environment variables are provided, use process.env directly instead of spreading it. This preserves Windows Proxy behavior which provides case-insensitive environment variable access. Root cause: Spreading process.env creates a plain object that loses the Proxy, breaking case-insensitive access on Windows (PATH vs Path). Solution: Only spread when merging custom environment variables. Otherwise, pass process.env directly to child process. Benefits: - Preserves Windows case-insensitive env var access - Reduces unnecessary object creation when no custom env needed - Fixes empty CLI output issue on Windows CI runners
1 parent 0c655b9 commit 5511966

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

src/spawn.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -614,14 +614,22 @@ export function spawn(
614614
// third-party code, Node.js built-ins, or JavaScript built-in methods.
615615
// https://github.com/npm/promise-spawn
616616
// https://github.com/nodejs/node/blob/v24.0.1/lib/child_process.js#L674-L678
617+
// Preserve Windows process.env Proxy behavior when no custom env is provided.
618+
// On Windows, process.env is a Proxy that provides case-insensitive access
619+
// (PATH vs Path vs path). Spreading creates a plain object that loses this.
620+
// Only spread when we have custom environment variables to merge.
621+
const envToUse = env
622+
? ({
623+
__proto__: null,
624+
...process.env,
625+
...env,
626+
} as unknown as NodeJS.ProcessEnv)
627+
: process.env
628+
617629
const promiseSpawnOpts = {
618630
__proto__: null,
619631
cwd: typeof spawnOptions.cwd === 'string' ? spawnOptions.cwd : undefined,
620-
env: {
621-
__proto__: null,
622-
...process.env,
623-
...env,
624-
} as unknown as NodeJS.ProcessEnv,
632+
env: envToUse,
625633
signal: abortSignal,
626634
stdio: spawnOptions.stdio,
627635
stdioString,

0 commit comments

Comments
 (0)