@@ -32,11 +32,18 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
32
32
let stdout = '' ;
33
33
let stderr = '' ;
34
34
const cwd = options . cwd ?? process . cwd ( ) ;
35
- const env = options . env ;
35
+ const env = options . env ?? process . env ;
36
36
console . log (
37
37
`==========================================================================================` ,
38
38
) ;
39
39
40
+ // Ensure the custom npm and yarn global bin is on the PATH
41
+ // https://docs.npmjs.com/cli/v8/configuring-npm/folders#executables
42
+ const paths = [
43
+ join ( getGlobalVariable ( 'npm-global' ) , process . platform . startsWith ( 'win' ) ? '' : 'bin' ) ,
44
+ env . PATH || process . env [ 'PATH' ] ,
45
+ ] . join ( delimiter ) ;
46
+
40
47
args = args . filter ( ( x ) => x !== undefined ) ;
41
48
const flags = [
42
49
options . silent && 'silent' ,
@@ -51,7 +58,7 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
51
58
52
59
const spawnOptions : SpawnOptions = {
53
60
cwd,
54
- ... ( env ? { env } : { } ) ,
61
+ env : { ... env , PATH : paths } ,
55
62
} ;
56
63
57
64
if ( process . platform . startsWith ( 'win' ) ) {
@@ -146,15 +153,10 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
146
153
export function extractNpmEnv ( ) {
147
154
return Object . keys ( process . env )
148
155
. filter ( ( v ) => NPM_CONFIG_RE . test ( v ) )
149
- . reduce < NodeJS . ProcessEnv > (
150
- ( vars , n ) => {
151
- vars [ n ] = process . env [ n ] ;
152
- return vars ;
153
- } ,
154
- {
155
- PATH : process . env . PATH ,
156
- } ,
157
- ) ;
156
+ . reduce < NodeJS . ProcessEnv > ( ( vars , n ) => {
157
+ vars [ n ] = process . env [ n ] ;
158
+ return vars ;
159
+ } , { } ) ;
158
160
}
159
161
160
162
export function waitForAnyProcessOutputToMatch (
@@ -364,20 +366,12 @@ export async function launchTestProcess(entry: string, ...args: any[]) {
364
366
} ;
365
367
366
368
// Modify the PATH environment variable...
367
- let paths = process . env . PATH ! . split ( delimiter ) ;
369
+ let paths = ( env . PATH || process . env . PATH ) ! . split ( delimiter ) ;
368
370
369
371
// Only include paths within the sandboxed test environment or external
370
372
// non angular-cli paths such as /usr/bin for generic commands.
371
373
paths = paths . filter ( ( p ) => p . startsWith ( tempRoot ) || ! p . includes ( 'angular-cli' ) ) ;
372
374
373
- // Ensure the custom npm global bin is on the PATH
374
- // https://docs.npmjs.com/cli/v8/configuring-npm/folders#executables
375
- if ( process . platform . startsWith ( 'win' ) ) {
376
- paths . unshift ( env . NPM_CONFIG_PREFIX ! ) ;
377
- } else {
378
- paths . unshift ( join ( env . NPM_CONFIG_PREFIX ! , 'bin' ) ) ;
379
- }
380
-
381
375
env . PATH = paths . join ( delimiter ) ;
382
376
383
377
return _exec ( { env } , process . execPath , [ resolve ( __dirname , 'run_test_process' ) , entry , ...args ] ) ;
0 commit comments