@@ -322,6 +322,24 @@ export function silentYarn(...args: string[]) {
322322 return _exec ( { silent : true } , 'yarn' , args ) ;
323323}
324324
325+ const YARN = join ( __dirname , '../../../../.yarn/releases/yarn-1.22.17.cjs' ) ;
326+
327+ export function globalYarn ( args : string [ ] , env ?: NodeJS . ProcessEnv ) {
328+ if ( ! process . env . LEGACY_CLI_RUNNER ) {
329+ throw new Error ( 'The global yarn should only be executed from the primary e2e runner process' ) ;
330+ }
331+
332+ // Use the yarn global cache when executing yarn
333+ const npmPrefix = process . env . NPM_CONFIG_PREFIX ;
334+ try {
335+ process . env . NPM_CONFIG_PREFIX = getGlobalVariable ( 'yarn-global' ) ;
336+
337+ return _exec ( { silent : true , env } , 'node' , [ YARN , ...args ] ) ;
338+ } finally {
339+ process . env . NPM_CONFIG_PREFIX = npmPrefix ;
340+ }
341+ }
342+
325343export function npm ( ...args : string [ ] ) {
326344 return _exec ( { } , 'npm' , args ) ;
327345}
@@ -361,12 +379,14 @@ export async function launchTestProcess(entry: string, ...args: any[]) {
361379 // non angular-cli paths such as /usr/bin for generic commands.
362380 paths = paths . filter ( ( p ) => p . startsWith ( tempRoot ) || ! p . includes ( 'angular-cli' ) ) ;
363381
364- // Ensure the custom npm global bin is on the PATH
382+ // Ensure the custom npm and yarn global bin is on the PATH
365383 // https://docs.npmjs.com/cli/v8/configuring-npm/folders#executables
366384 if ( process . platform . startsWith ( 'win' ) ) {
367- paths . unshift ( env . NPM_CONFIG_PREFIX ! ) ;
385+ paths . unshift ( getGlobalVariable ( 'npm-global' ) ) ;
386+ paths . unshift ( getGlobalVariable ( 'yarn-global' ) ) ;
368387 } else {
369- paths . unshift ( join ( env . NPM_CONFIG_PREFIX ! , 'bin' ) ) ;
388+ paths . unshift ( join ( getGlobalVariable ( 'npm-global' ) , 'bin' ) ) ;
389+ paths . unshift ( join ( getGlobalVariable ( 'yarn-global' ) , 'bin' ) ) ;
370390 }
371391
372392 env . PATH = paths . join ( delimiter ) ;
0 commit comments