Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(benchmark): select npm.cmd on windows #4030

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions resources/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,40 @@ interface NPMOptions extends SpawnOptions {

export function npm(options?: NPMOptions) {
const globalOptions = options?.quiet === true ? ['--quiet'] : [];

// `npm` points to an executable shell script; so it doesn't require a shell per se.
// On Windows `shell: true` is required or `npm` will be picked rather than `npm.cmd`.
// This could alternatively be handled by manually selecting `npm.cmd` on Windows.
// See: https://github.com/nodejs/node/issues/3675 and in particular
// https://github.com/nodejs/node/issues/3675#issuecomment-308963807.
const npmOptions = { shell: true, ...options };

return {
run(...args: ReadonlyArray<string>): void {
spawn('npm', [...globalOptions, 'run', ...args], options);
spawn('npm', [...globalOptions, 'run', ...args], npmOptions);
},
install(...args: ReadonlyArray<string>): void {
spawn('npm', [...globalOptions, 'install', ...args], options);
spawn('npm', [...globalOptions, 'install', ...args], npmOptions);
},
ci(...args: ReadonlyArray<string>): void {
spawn('npm', [...globalOptions, 'ci', ...args], options);
spawn('npm', [...globalOptions, 'ci', ...args], npmOptions);
},
exec(...args: ReadonlyArray<string>): void {
spawn('npm', [...globalOptions, 'exec', ...args], options);
spawn('npm', [...globalOptions, 'exec', ...args], npmOptions);
},
pack(...args: ReadonlyArray<string>): string {
return spawnOutput('npm', [...globalOptions, 'pack', ...args], options);
return spawnOutput(
'npm',
[...globalOptions, 'pack', ...args],
npmOptions,
);
},
diff(...args: ReadonlyArray<string>): string {
return spawnOutput('npm', [...globalOptions, 'diff', ...args], options);
return spawnOutput(
'npm',
[...globalOptions, 'diff', ...args],
npmOptions,
);
},
};
}
Expand Down Expand Up @@ -89,6 +105,7 @@ export function git(options?: GITOptions) {
interface SpawnOptions {
cwd?: string;
env?: typeof process.env;
shell?: boolean;
}

function spawnOutput(
Expand Down
Loading