@@ -15,6 +15,8 @@ interface ExecOptions {
1515 cwd ?: string ;
1616}
1717
18+ const NPM_CONFIG_RE = / ^ n p m _ c o n f i g _ / i;
19+
1820let _processes : child_process . ChildProcess [ ] = [ ] ;
1921
2022export type ProcessOutput = {
@@ -138,6 +140,20 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
138140 } ) ;
139141}
140142
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+
141157export function waitForAnyProcessOutputToMatch (
142158 match : RegExp ,
143159 timeout = 30000 ,
@@ -269,21 +285,22 @@ export function silentNpm(
269285 {
270286 silent : true ,
271287 cwd : ( options as { cwd ?: string } | undefined ) ?. cwd ,
288+ env : extractNpmEnv ( ) ,
272289 } ,
273290 'npm' ,
274291 params ,
275292 ) ;
276293 } else {
277- return _exec ( { silent : true } , 'npm' , args as string [ ] ) ;
294+ return _exec ( { silent : true , env : extractNpmEnv ( ) } , 'npm' , args as string [ ] ) ;
278295 }
279296}
280297
281298export function silentYarn ( ...args : string [ ] ) {
282- return _exec ( { silent : true } , 'yarn' , args ) ;
299+ return _exec ( { silent : true , env : extractNpmEnv ( ) } , 'yarn' , args ) ;
283300}
284301
285302export function npm ( ...args : string [ ] ) {
286- return _exec ( { } , 'npm' , args ) ;
303+ return _exec ( { env : extractNpmEnv ( ) } , 'npm' , args ) ;
287304}
288305
289306export function node ( ...args : string [ ] ) {
0 commit comments