@@ -10,11 +10,27 @@ const treeKill = require('tree-kill');
10
10
interface ExecOptions {
11
11
silent ?: boolean ;
12
12
waitForMatch ?: RegExp ;
13
- env ?: { [ varname : string ] : string } ;
13
+ env ?: { [ varname : string ] : string } | 'npm' ;
14
14
stdin ?: string ;
15
15
cwd ?: string ;
16
16
}
17
17
18
+ const NPM_CONFIG_RE = / ^ n p m _ c o n f i g _ / i;
19
+
20
+ function extractNpmEnv ( ) {
21
+ return Object . keys ( process . env )
22
+ . filter ( ( v ) => NPM_CONFIG_RE . test ( v ) )
23
+ . reduce (
24
+ ( vars , n ) => {
25
+ vars [ n ] = process . env [ n ] ;
26
+ return vars ;
27
+ } ,
28
+ {
29
+ PATH : process . env . PATH ,
30
+ } ,
31
+ ) ;
32
+ }
33
+
18
34
let _processes : child_process . ChildProcess [ ] = [ ] ;
19
35
20
36
export type ProcessOutput = {
@@ -30,7 +46,7 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
30
46
let stdout = '' ;
31
47
let stderr = '' ;
32
48
const cwd = options . cwd ?? process . cwd ( ) ;
33
- const env = options . env ;
49
+ const env = options . env === 'npm' ? extractNpmEnv ( ) : options . env ;
34
50
console . log (
35
51
`==========================================================================================` ,
36
52
) ;
@@ -269,21 +285,22 @@ export function silentNpm(
269
285
{
270
286
silent : true ,
271
287
cwd : ( options as { cwd ?: string } | undefined ) ?. cwd ,
288
+ env : 'npm' ,
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 : 'npm' } , '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 : 'npm' } , 'yarn' , args ) ;
283
300
}
284
301
285
302
export function npm ( ...args : string [ ] ) {
286
- return _exec ( { } , 'npm' , args ) ;
303
+ return _exec ( { env : 'npm' } , 'npm' , args ) ;
287
304
}
288
305
289
306
export function node ( ...args : string [ ] ) {
0 commit comments