Skip to content

Commit 01b4ad8

Browse files
jbedardalan-agius4
authored andcommitted
test: align yarn and npm prefix config
1 parent 2cda5a6 commit 01b4ad8

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

tests/legacy-cli/e2e/setup/002-npm-sandbox.ts

+17-6
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,39 @@ import { getGlobalVariable, setGlobalVariable } from '../utils/env';
88
export 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
15-
// From this point onward all npm transactions use the "global" npm cache
16-
// isolated within this e2e test invocation.
16+
// Change the npm+yarn userconfig to the sandboxed npmrc to override the default ~
1717
process.env.NPM_CONFIG_USERCONFIG = npmrc;
18-
process.env.NPM_CONFIG_PREFIX = npmModulesPrefix;
18+
19+
// The npm+yarn registry URL
1920
process.env.NPM_CONFIG_REGISTRY = npmRegistry;
2021

22+
// Configure npm+yarn to use a sandboxed bin directory
23+
// From this point onward all yarn/npm bin files/symlinks are put into the prefix directories
24+
process.env.NPM_CONFIG_PREFIX = npmModulesPrefix;
25+
process.env.YARN_CONFIG_PREFIX = yarnModulesPrefix;
26+
2127
// Snapshot builds may contain versions that are not yet released (e.g., RC phase main branch).
2228
// In this case peer dependency ranges may not resolve causing npm 7+ to fail during tests.
2329
// To support this case, legacy peer dependency mode is enabled for snapshot builds.
2430
if (getGlobalVariable('argv')['ng-snapshots']) {
2531
process.env['NPM_CONFIG_legacy_peer_deps'] = 'true';
2632
}
2733

28-
// Configure the registry and prefix used within the test sandbox
34+
// Configure the registry and prefix used within the test sandbox via rc files
2935
await writeFile(npmrc, `registry=${npmRegistry}\nprefix=${npmModulesPrefix}`);
36+
await writeFile(yarnrc, `registry ${npmRegistry}\nprefix ${yarnModulesPrefix}`);
37+
3038
await mkdir(npmModulesPrefix);
39+
await mkdir(yarnModulesPrefix);
3140

3241
setGlobalVariable('npm-global', npmModulesPrefix);
42+
setGlobalVariable('yarn-global', yarnModulesPrefix);
3343

34-
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.`);
3546
}

tests/legacy-cli/e2e/utils/process.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface ExecOptions {
1616
cwd?: string;
1717
}
1818

19-
const NPM_CONFIG_RE = /^npm_config_/i;
19+
const NPM_CONFIG_RE = /^(npm_config_|yarn_)/i;
2020

2121
let _processes: child_process.ChildProcess[] = [];
2222

@@ -40,6 +40,7 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
4040
// Ensure the custom npm and yarn global bin is on the PATH
4141
// https://docs.npmjs.com/cli/v8/configuring-npm/folders#executables
4242
const paths = [
43+
join(getGlobalVariable('yarn-global'), 'bin'),
4344
join(getGlobalVariable('npm-global'), process.platform.startsWith('win') ? '' : 'bin'),
4445
env.PATH || process.env['PATH'],
4546
].join(delimiter);

0 commit comments

Comments
 (0)