Skip to content

Commit 792a3ff

Browse files
committed
fix(@angular/cli): correctly spawn package managers on Windows in new abstraction
When running E2E tests on Windows, `spawn` was failing to find package manager executables like `npm` because it does not automatically resolve `.cmd` or `.bat` extensions when `shell: false` is used.
1 parent fa0ddc5 commit 792a3ff

File tree

2 files changed

+10
-6
lines changed
  • .github/workflows
  • packages/angular/cli/src/package-managers

2 files changed

+10
-6
lines changed

.github/workflows/pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ jobs:
171171
test_target_name: e2e.esbuild_node22
172172
env:
173173
E2E_SHARD_TOTAL: 1
174-
TESTBRIDGE_TEST_ONLY: tests/basic/{build,rebuild}.ts
174+
TESTBRIDGE_TEST_ONLY: tests/build/material.ts
175175

176176
e2e-package-managers:
177177
needs: build

packages/angular/cli/src/package-managers/host.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
* enabling the injection of mock or test-specific implementations.
1414
*/
1515

16-
import { spawn } from 'node:child_process';
16+
import { type SpawnOptions, spawn } from 'node:child_process';
1717
import { Stats } from 'node:fs';
1818
import { mkdtemp, readFile, readdir, rm, stat, writeFile } from 'node:fs/promises';
19-
import { tmpdir } from 'node:os';
19+
import { platform, tmpdir } from 'node:os';
2020
import { join } from 'node:path';
2121
import { PackageManagerError } from './error';
2222

@@ -107,18 +107,22 @@ export const NodeJS_HOST: Host = {
107107
} = {},
108108
): Promise<{ stdout: string; stderr: string }> => {
109109
const signal = options.timeout ? AbortSignal.timeout(options.timeout) : undefined;
110+
const isWin32 = platform() === 'win32';
110111

111112
return new Promise((resolve, reject) => {
112-
const childProcess = spawn(command, args, {
113-
shell: false,
113+
const spawnOptions = {
114+
shell: isWin32,
114115
stdio: options.stdio ?? 'pipe',
115116
signal,
116117
cwd: options.cwd,
117118
env: {
118119
...process.env,
119120
...options.env,
120121
},
121-
});
122+
} satisfies SpawnOptions;
123+
const childProcess = isWin32
124+
? spawn(`${command} ${args.join(' ')}`, spawnOptions)
125+
: spawn(command, args, spawnOptions);
122126

123127
let stdout = '';
124128
childProcess.stdout?.on('data', (data) => (stdout += data.toString()));

0 commit comments

Comments
 (0)