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 yarnModulesPrefix = join ( tempRoot , 'yarn-global' ) ;
1112 const npmRegistry : string = getGlobalVariable ( 'package-registry' ) ;
1213 const npmrc = join ( tempRoot , '.npmrc' ) ;
14+ const yarnrc = join ( tempRoot , '.yarnrc' ) ;
1315
14- // Configure npm to use the sandboxed npm globals and rc file
16+ // Change the npm+yarn userconfig to the sandboxed npmrc to override the default ~
17+ process . env . NPM_CONFIG_USERCONFIG = npmrc ;
18+
19+ // The npm+yarn registry URL
20+ process . env . NPM_CONFIG_REGISTRY = npmRegistry ;
21+
22+ // Configure npm+yarn to use a sandboxed bin directory
1523 // From this point onward all npm transactions use the "global" npm cache
1624 // isolated within this e2e test invocation.
17- process . env . NPM_CONFIG_USERCONFIG = npmrc ;
1825 process . env . NPM_CONFIG_PREFIX = npmModulesPrefix ;
19- process . env . NPM_CONFIG_REGISTRY = npmRegistry ;
26+ process . env . YARN_CONFIG_PREFIX = yarnModulesPrefix ;
2027
2128 // Snapshot builds may contain versions that are not yet released (e.g., RC phase main branch).
2229 // In this case peer dependency ranges may not resolve causing npm 7+ to fail during tests.
@@ -25,9 +32,15 @@ export default async function () {
2532 process . env [ 'NPM_CONFIG_legacy_peer_deps' ] = 'true' ;
2633 }
2734
28- // Configure the registry and prefix used within the test sandbox
35+ // Configure the registry and prefix used within the test sandbox via rc files
2936 await writeFile ( npmrc , `registry=${ npmRegistry } \nprefix=${ npmModulesPrefix } ` ) ;
37+ await writeFile ( yarnrc , `registry ${ npmRegistry } \nprefix ${ yarnModulesPrefix } ` ) ;
3038 await mkdir ( npmModulesPrefix ) ;
39+ await mkdir ( yarnModulesPrefix ) ;
40+
41+ setGlobalVariable ( 'npm-global' , npmModulesPrefix ) ;
42+ setGlobalVariable ( 'yarn-global' , yarnModulesPrefix ) ;
3143
32- console . log ( ` Using "${ npmModulesPrefix } " as e2e test global npm cache.` ) ;
44+ console . log ( ` Using "${ npmModulesPrefix } " as e2e test global npm bin dir.` ) ;
45+ console . log ( ` Using "${ yarnModulesPrefix } " as e2e test global yarn bin dir.` ) ;
3346}
0 commit comments