@@ -33,11 +33,22 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
3333 let stdout = '' ;
3434 let stderr = '' ;
3535 const cwd = options . cwd ?? process . cwd ( ) ;
36- const env = options . env ;
36+ const env = options . env ?? { } ;
3737 console . log (
3838 `==========================================================================================` ,
3939 ) ;
4040
41+ const paths = ( env . PATH || process . env . PATH ) ! . split ( delimiter ) ;
42+
43+ // Ensure the custom npm and yarn global bin is on the PATH
44+ // https://docs.npmjs.com/cli/v8/configuring-npm/folders#executables
45+ paths . unshift ( join ( getGlobalVariable ( 'yarn-global' ) , 'bin' ) ) ;
46+ if ( process . platform . startsWith ( 'win' ) ) {
47+ paths . unshift ( getGlobalVariable ( 'npm-global' ) ) ;
48+ } else {
49+ paths . unshift ( join ( getGlobalVariable ( 'npm-global' ) , 'bin' ) ) ;
50+ }
51+
4152 args = args . filter ( ( x ) => x !== undefined ) ;
4253 const flags = [
4354 options . silent && 'silent' ,
@@ -52,7 +63,7 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
5263
5364 const spawnOptions : SpawnOptions = {
5465 cwd,
55- ... ( env ? { env } : { } ) ,
66+ env : { ... env , PATH : paths . join ( delimiter ) } ,
5667 } ;
5768
5869 if ( process . platform . startsWith ( 'win' ) ) {
@@ -147,15 +158,10 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
147158export function extractNpmEnv ( ) {
148159 return Object . keys ( process . env )
149160 . 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- ) ;
161+ . reduce < NodeJS . ProcessEnv > ( ( vars , n ) => {
162+ vars [ n ] = process . env [ n ] ;
163+ return vars ;
164+ } , { } ) ;
159165}
160166
161167export function waitForAnyProcessOutputToMatch (
@@ -355,20 +361,12 @@ export async function launchTestProcess(entry: string, ...args: any[]) {
355361 } ;
356362
357363 // Modify the PATH environment variable...
358- let paths = process . env . PATH ! . split ( delimiter ) ;
364+ let paths = ( env . PATH || process . env . PATH ) ! . split ( delimiter ) ;
359365
360366 // Only include paths within the sandboxed test environment or external
361367 // non angular-cli paths such as /usr/bin for generic commands.
362368 paths = paths . filter ( ( p ) => p . startsWith ( tempRoot ) || ! p . includes ( 'angular-cli' ) ) ;
363369
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-
372370 env . PATH = paths . join ( delimiter ) ;
373371
374372 return _exec ( { env } , process . execPath , [ resolve ( __dirname , 'run_test_process' ) , entry , ...args ] ) ;
0 commit comments