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