Skip to content

Commit

Permalink
fix(@angular/cli): respect registry in RC when running update through…
Browse files Browse the repository at this point in the history
… yarn

This commit fixes an issue where when `ng update` was ran using `yarn` (`yarn ng update`) the registry was always being overridden to `https://registry.yarnpkg.com`.

This is because yarn will set the `npm_config_registry` env variable to `https://registry.yarnpkg.com` even when an RC file is present with a different repository.

(cherry picked from commit 0dcb199)
  • Loading branch information
alan-agius4 committed Nov 11, 2022
1 parent fc82e3b commit ff03827
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/angular/cli/src/utilities/package-metadata.ts
Expand Up @@ -139,6 +139,18 @@ function readOptions(
continue;
}

if (
normalizedName === 'registry' &&
rcOptions['registry'] &&
value === 'https://registry.yarnpkg.com' &&
process.env['npm_config_user_agent']?.includes('yarn')
) {
// When running `ng update` using yarn (`yarn ng update`), yarn will set the `npm_config_registry` env variable to `https://registry.yarnpkg.com`
// even when an RC file is present with a different repository.
// This causes the registry specified in the RC to always be overridden with the below logic.
continue;
}

normalizedName = normalizedName.replace(/(?!^)_/g, '-'); // don't replace _ at the start of the key.s
envVariablesOptions[normalizedName] = value;
}
Expand Down
13 changes: 12 additions & 1 deletion tests/legacy-cli/e2e/tests/update/update-secure-registry.ts
@@ -1,7 +1,9 @@
import { ng } from '../../utils/process';
import { exec, ng } from '../../utils/process';
import { createNpmConfigForAuthentication } from '../../utils/registry';
import { expectToFail } from '../../utils/utils';
import { isPrereleaseCli } from '../../utils/project';
import { getActivePackageManager } from '../../utils/packages';
import assert from 'node:assert';

export default async function () {
// The environment variable has priority over the .npmrc
Expand Down Expand Up @@ -32,4 +34,13 @@ export default async function () {

await createNpmConfigForAuthentication(true, true);
await expectToFail(() => ng('update', ...extraArgs));

if (getActivePackageManager() === 'yarn') {
// When running `ng update` using yarn (`yarn ng update`), yarn will set the `npm_config_registry` env variable to `https://registry.yarnpkg.com`
// Validate the the registry in the RC is used.
await createNpmConfigForAuthentication(true, true);

const error = await expectToFail(() => exec('yarn', 'ng', 'update', ...extraArgs));
assert.match(error.message, /not allowed to access package/);
}
}

0 comments on commit ff03827

Please sign in to comment.