11import { mkdir , writeFile } from 'fs/promises' ;
22import { join } from 'path' ;
3- import { getGlobalVariable } from '../utils/env' ;
3+ import { getGlobalVariable , setGlobalVariable } from '../utils/env' ;
44
55/**
66 * Configure npm to use a unique sandboxed environment.
77 */
88export default async function ( ) {
99 const tempRoot : string = getGlobalVariable ( 'tmp-root' ) ;
1010 const npmModulesPrefix = join ( tempRoot , 'npm-global' ) ;
11+ const yarnModuleCache = join ( tempRoot , 'yarn-cache-folder' ) ;
12+ const yarnModulesPrefix = join ( tempRoot , 'yarn-global' ) ;
1113 const npmRegistry : string = getGlobalVariable ( 'package-registry' ) ;
1214 const npmrc = join ( tempRoot , '.npmrc' ) ;
15+ const yarnrc = join ( tempRoot , '.yarnrc' ) ;
1316
1417 // Configure npm to use the sandboxed npm globals and rc file
1518 // From this point onward all npm transactions use the "global" npm cache
1619 // isolated within this e2e test invocation.
1720 process . env . NPM_CONFIG_USERCONFIG = npmrc ;
1821 process . env . NPM_CONFIG_PREFIX = npmModulesPrefix ;
1922 process . env . NPM_CONFIG_REGISTRY = npmRegistry ;
23+ process . env . YARN_CACHE_FOLDER = yarnModuleCache ;
2024
2125 // Snapshot builds may contain versions that are not yet released (e.g., RC phase main branch).
2226 // In this case peer dependency ranges may not resolve causing npm 7+ to fail during tests.
@@ -25,9 +29,22 @@ export default async function () {
2529 process . env [ 'NPM_CONFIG_legacy_peer_deps' ] = 'true' ;
2630 }
2731
28- // Configure the registry and prefix used within the test sandbox
29- await writeFile ( npmrc , `registry=${ npmRegistry } \nprefix=${ npmModulesPrefix } ` ) ;
32+ // Configure the registry and create the prefix directories
33+ await writeFile ( npmrc , [ `registry=${ npmRegistry } ` , `prefix=${ npmModulesPrefix } ` ] . join ( '\n' ) ) ;
34+ await writeFile (
35+ yarnrc ,
36+ [
37+ `registry ${ npmRegistry } ` ,
38+ `prefix ${ yarnModulesPrefix } ` ,
39+ `cache-folder ${ yarnModuleCache } ` ,
40+ ] . join ( '\n' ) ,
41+ ) ;
3042 await mkdir ( npmModulesPrefix ) ;
43+ await mkdir ( yarnModulesPrefix ) ;
44+ await mkdir ( yarnModuleCache ) ;
45+
46+ setGlobalVariable ( 'npm-global' , npmModulesPrefix ) ;
47+ setGlobalVariable ( 'yarn-global' , yarnModulesPrefix ) ;
3148
3249 console . log ( ` Using "${ npmModulesPrefix } " as e2e test global npm cache.` ) ;
3350}
0 commit comments