diff --git a/tests/legacy-cli/e2e/setup/002-npm-sandbox.ts b/tests/legacy-cli/e2e/setup/002-npm-sandbox.ts index 1d1824f25235..271980317b3b 100644 --- a/tests/legacy-cli/e2e/setup/002-npm-sandbox.ts +++ b/tests/legacy-cli/e2e/setup/002-npm-sandbox.ts @@ -17,6 +17,13 @@ export default async function () { process.env.NPM_CONFIG_USERCONFIG = npmrc; process.env.NPM_CONFIG_PREFIX = npmModulesPrefix; + // Snapshot builds may contain versions that are not yet released (e.g., RC phase main branch). + // In this case peer dependency ranges may not resolve causing npm 7+ to fail during tests. + // To support this case, legacy peer dependency mode is enabled for snapshot builds. + if (getGlobalVariable('argv')['ng-snapshots']) { + process.env['NPM_CONFIG_legacy_peer_deps'] = 'true'; + } + // Configure the registry and prefix used within the test sandbox await writeFile(npmrc, `registry=${npmRegistry}\nprefix=${npmModulesPrefix}`); await mkdir(npmModulesPrefix); diff --git a/tests/legacy-cli/e2e/utils/packages.ts b/tests/legacy-cli/e2e/utils/packages.ts index cc294acfcfa8..3c6476f14c3f 100644 --- a/tests/legacy-cli/e2e/utils/packages.ts +++ b/tests/legacy-cli/e2e/utils/packages.ts @@ -50,7 +50,6 @@ export async function setRegistry(useTestRegistry: boolean): Promise { : 'https://registry.npmjs.org'; const isCI = getGlobalVariable('ci'); - const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots']; // Ensure local test registry is used when outside a project if (isCI) { @@ -60,11 +59,4 @@ export async function setRegistry(useTestRegistry: boolean): Promise { // Yarn supports both `NPM_CONFIG_REGISTRY` and `YARN_REGISTRY`. process.env['NPM_CONFIG_REGISTRY'] = url; } - - // Snapshot builds may contain versions that are not yet released (e.g., RC phase main branch). - // In this case peer dependency ranges may not resolve causing npm 7+ to fail during tests. - // To support this case, legacy peer dependency mode is enabled for snapshot builds. - if (isSnapshotBuild) { - process.env['NPM_CONFIG_legacy_peer_deps'] = 'true'; - } }