1
1
import { mkdir , writeFile } from 'fs/promises' ;
2
2
import { join } from 'path' ;
3
- import { getGlobalVariable } from '../utils/env' ;
3
+ import { getGlobalVariable , setGlobalVariable } from '../utils/env' ;
4
4
5
5
/**
6
6
* Configure npm to use a unique sandboxed environment.
7
7
*/
8
8
export default async function ( ) {
9
9
const tempRoot : string = getGlobalVariable ( 'tmp-root' ) ;
10
10
const npmModulesPrefix = join ( tempRoot , 'npm-global' ) ;
11
+ const yarnModuleCache = join ( tempRoot , 'yarn-cache-folder' ) ;
12
+ const yarnModulesPrefix = join ( tempRoot , 'yarn-global' ) ;
11
13
const npmRegistry : string = getGlobalVariable ( 'package-registry' ) ;
12
14
const npmrc = join ( tempRoot , '.npmrc' ) ;
15
+ const yarnrc = join ( tempRoot , '.yarnrc' ) ;
13
16
14
17
// Configure npm to use the sandboxed npm globals and rc file
15
18
// From this point onward all npm transactions use the "global" npm cache
16
19
// isolated within this e2e test invocation.
17
20
process . env . NPM_CONFIG_USERCONFIG = npmrc ;
18
21
process . env . NPM_CONFIG_PREFIX = npmModulesPrefix ;
19
22
process . env . NPM_CONFIG_REGISTRY = npmRegistry ;
23
+ process . env . YARN_CACHE_FOLDER = yarnModuleCache ;
20
24
21
25
// Snapshot builds may contain versions that are not yet released (e.g., RC phase main branch).
22
26
// In this case peer dependency ranges may not resolve causing npm 7+ to fail during tests.
@@ -25,9 +29,22 @@ export default async function () {
25
29
process . env [ 'NPM_CONFIG_legacy_peer_deps' ] = 'true' ;
26
30
}
27
31
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
+ ) ;
30
42
await mkdir ( npmModulesPrefix ) ;
43
+ await mkdir ( yarnModulesPrefix ) ;
44
+ await mkdir ( yarnModuleCache ) ;
45
+
46
+ setGlobalVariable ( 'npm-global' , npmModulesPrefix ) ;
47
+ setGlobalVariable ( 'yarn-global' , yarnModulesPrefix ) ;
31
48
32
49
console . log ( ` Using "${ npmModulesPrefix } " as e2e test global npm cache.` ) ;
33
50
}
0 commit comments