@@ -34,24 +34,40 @@ interface NPMOptions extends SpawnOptions {
34
34
35
35
export function npm ( options ?: NPMOptions ) {
36
36
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
+
37
45
return {
38
46
run ( ...args : ReadonlyArray < string > ) : void {
39
- spawn ( 'npm' , [ ...globalOptions , 'run' , ...args ] , options ) ;
47
+ spawn ( 'npm' , [ ...globalOptions , 'run' , ...args ] , npmOptions ) ;
40
48
} ,
41
49
install ( ...args : ReadonlyArray < string > ) : void {
42
- spawn ( 'npm' , [ ...globalOptions , 'install' , ...args ] , options ) ;
50
+ spawn ( 'npm' , [ ...globalOptions , 'install' , ...args ] , npmOptions ) ;
43
51
} ,
44
52
ci ( ...args : ReadonlyArray < string > ) : void {
45
- spawn ( 'npm' , [ ...globalOptions , 'ci' , ...args ] , options ) ;
53
+ spawn ( 'npm' , [ ...globalOptions , 'ci' , ...args ] , npmOptions ) ;
46
54
} ,
47
55
exec ( ...args : ReadonlyArray < string > ) : void {
48
- spawn ( 'npm' , [ ...globalOptions , 'exec' , ...args ] , options ) ;
56
+ spawn ( 'npm' , [ ...globalOptions , 'exec' , ...args ] , npmOptions ) ;
49
57
} ,
50
58
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
+ ) ;
52
64
} ,
53
65
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
+ ) ;
55
71
} ,
56
72
} ;
57
73
}
@@ -89,6 +105,7 @@ export function git(options?: GITOptions) {
89
105
interface SpawnOptions {
90
106
cwd ?: string ;
91
107
env ?: typeof process . env ;
108
+ shell ?: boolean ;
92
109
}
93
110
94
111
function spawnOutput (
0 commit comments