@@ -34,24 +34,40 @@ interface NPMOptions extends SpawnOptions {
3434
3535export 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) {
89105interface SpawnOptions {
90106 cwd ?: string ;
91107 env ?: typeof process . env ;
108+ shell ?: boolean ;
92109}
93110
94111function spawnOutput (
0 commit comments