11import { mkdir , writeFile } from 'fs/promises' ;
22import { join } from 'path' ;
3- import { getGlobalVariable } from '../utils/env' ;
3+ import { getGlobalVariable , setGlobalVariable } from '../utils/env' ;
4+ import { globalYarn } from '../utils/process' ;
45
56/**
67 * Configure npm to use a unique sandboxed environment.
78 */
89export default async function ( ) {
910 const tempRoot : string = getGlobalVariable ( 'tmp-root' ) ;
1011 const npmModulesPrefix = join ( tempRoot , 'npm-global' ) ;
12+ const yarnModuleCache = join ( tempRoot , 'yarn-cache-folder' ) ;
13+ const yarnModulesPrefix = join ( tempRoot , 'yarn-global' ) ;
1114 const npmRegistry : string = getGlobalVariable ( 'package-registry' ) ;
1215 const npmrc = join ( tempRoot , '.npmrc' ) ;
16+ const yarnrc = join ( tempRoot , '.yarnrc' ) ;
1317
1418 // Configure npm to use the sandboxed npm globals and rc file
1519 // From this point onward all npm transactions use the "global" npm cache
1620 // isolated within this e2e test invocation.
1721 process . env . NPM_CONFIG_USERCONFIG = npmrc ;
1822 process . env . NPM_CONFIG_PREFIX = npmModulesPrefix ;
1923 process . env . NPM_CONFIG_REGISTRY = npmRegistry ;
24+ process . env . YARN_CACHE_FOLDER = yarnModuleCache ;
2025
2126 // Snapshot builds may contain versions that are not yet released (e.g., RC phase main branch).
2227 // In this case peer dependency ranges may not resolve causing npm 7+ to fail during tests.
@@ -25,9 +30,18 @@ export default async function () {
2530 process . env [ 'NPM_CONFIG_legacy_peer_deps' ] = 'true' ;
2631 }
2732
28- // Configure the registry and prefix used within the test sandbox
33+ // Configure the registry and create the prefix directories
2934 await writeFile ( npmrc , `registry=${ npmRegistry } \nprefix=${ npmModulesPrefix } ` ) ;
35+ await writeFile (
36+ yarnrc ,
37+ `registry ${ npmRegistry } \nprefix ${ yarnModulesPrefix } \ncache-folder ${ yarnModuleCache } ` ,
38+ ) ;
3039 await mkdir ( npmModulesPrefix ) ;
40+ await mkdir ( yarnModulesPrefix ) ;
41+ await mkdir ( yarnModuleCache ) ;
42+
43+ setGlobalVariable ( 'npm-global' , npmModulesPrefix ) ;
44+ setGlobalVariable ( 'yarn-global' , yarnModulesPrefix ) ;
3145
3246 console . log ( ` Using "${ npmModulesPrefix } " as e2e test global npm cache.` ) ;
3347}
0 commit comments