Skip to content

Commit 9a2ebdf

Browse files
committed
fix(benchmark): select npm.cmd on windows
see: nodejs/node#3675 and in particular: nodejs/node#3675 (comment)
1 parent 9c90a23 commit 9a2ebdf

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

resources/utils.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,40 @@ interface NPMOptions extends SpawnOptions {
3434

3535
export function npm(options?: NPMOptions) {
3636
const globalOptions = options?.quiet === true ? ['--quiet'] : [];
37+
38+
// `npm` points to an executable shell script; so it doesn't require a shell per se.
39+
// On Windows `shell: true` is required or `npm` will be picked rather than `npm.cmd`.
40+
// This could alternatively be handled by manually selecting `npm.cmd` on Windows.
41+
// See: https://github.com/nodejs/node/issues/3675 and in particular
42+
// https://github.com/nodejs/node/issues/3675#issuecomment-308963807.
43+
const npmOptions = { shell: true, ...options };
44+
3745
return {
3846
run(...args: ReadonlyArray<string>): void {
39-
spawn('npm', [...globalOptions, 'run', ...args], options);
47+
spawn('npm', [...globalOptions, 'run', ...args], npmOptions);
4048
},
4149
install(...args: ReadonlyArray<string>): void {
42-
spawn('npm', [...globalOptions, 'install', ...args], options);
50+
spawn('npm', [...globalOptions, 'install', ...args], npmOptions);
4351
},
4452
ci(...args: ReadonlyArray<string>): void {
45-
spawn('npm', [...globalOptions, 'ci', ...args], options);
53+
spawn('npm', [...globalOptions, 'ci', ...args], npmOptions);
4654
},
4755
exec(...args: ReadonlyArray<string>): void {
48-
spawn('npm', [...globalOptions, 'exec', ...args], options);
56+
spawn('npm', [...globalOptions, 'exec', ...args], npmOptions);
4957
},
5058
pack(...args: ReadonlyArray<string>): string {
51-
return spawnOutput('npm', [...globalOptions, 'pack', ...args], options);
59+
return spawnOutput(
60+
'npm',
61+
[...globalOptions, 'pack', ...args],
62+
npmOptions,
63+
);
5264
},
5365
diff(...args: ReadonlyArray<string>): string {
54-
return spawnOutput('npm', [...globalOptions, 'diff', ...args], options);
66+
return spawnOutput(
67+
'npm',
68+
[...globalOptions, 'diff', ...args],
69+
npmOptions,
70+
);
5571
},
5672
};
5773
}
@@ -89,6 +105,7 @@ export function git(options?: GITOptions) {
89105
interface SpawnOptions {
90106
cwd?: string;
91107
env?: typeof process.env;
108+
shell?: boolean;
92109
}
93110

94111
function spawnOutput(

0 commit comments

Comments
 (0)