@@ -15,6 +15,8 @@ interface ExecOptions {
15
15
cwd ?: string ;
16
16
}
17
17
18
+ const NPM_CONFIG_RE = / ^ n p m _ c o n f i g _ / i;
19
+
18
20
let _processes : child_process . ChildProcess [ ] = [ ] ;
19
21
20
22
export type ProcessOutput = {
@@ -138,6 +140,20 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
138
140
} ) ;
139
141
}
140
142
143
+ export function extractNpmEnv ( ) {
144
+ return Object . keys ( process . env )
145
+ . filter ( ( v ) => NPM_CONFIG_RE . test ( v ) )
146
+ . reduce (
147
+ ( vars , n ) => {
148
+ vars [ n ] = process . env [ n ] ;
149
+ return vars ;
150
+ } ,
151
+ {
152
+ PATH : process . env . PATH ,
153
+ } ,
154
+ ) ;
155
+ }
156
+
141
157
export function waitForAnyProcessOutputToMatch (
142
158
match : RegExp ,
143
159
timeout = 30000 ,
@@ -269,21 +285,22 @@ export function silentNpm(
269
285
{
270
286
silent : true ,
271
287
cwd : ( options as { cwd ?: string } | undefined ) ?. cwd ,
288
+ env : extractNpmEnv ( ) ,
272
289
} ,
273
290
'npm' ,
274
291
params ,
275
292
) ;
276
293
} else {
277
- return _exec ( { silent : true } , 'npm' , args as string [ ] ) ;
294
+ return _exec ( { silent : true , env : extractNpmEnv ( ) } , 'npm' , args as string [ ] ) ;
278
295
}
279
296
}
280
297
281
298
export function silentYarn ( ...args : string [ ] ) {
282
- return _exec ( { silent : true } , 'yarn' , args ) ;
299
+ return _exec ( { silent : true , env : extractNpmEnv ( ) } , 'yarn' , args ) ;
283
300
}
284
301
285
302
export function npm ( ...args : string [ ] ) {
286
- return _exec ( { } , 'npm' , args ) ;
303
+ return _exec ( { env : extractNpmEnv ( ) } , 'npm' , args ) ;
287
304
}
288
305
289
306
export function node ( ...args : string [ ] ) {
0 commit comments