From 77c96f8b2ae219bf69dc9d5278cff39dc981c680 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Wed, 16 Jun 2021 13:05:40 +0200 Subject: [PATCH] fix(@angular/cli): handle unscoped authentication details in `.npmrc` files Unless auth options are scope with the registry url it appears that npm-registry-fetch ignores them, even though they are documented. https://github.com/npm/npm-registry-fetch/blob/8954f61d8d703e5eb7f3d93c9b40488f8b1b62ac/README.md https://github.com/npm/npm-registry-fetch/blob/8954f61d8d703e5eb7f3d93c9b40488f8b1b62ac/auth.js#L45-L91 --- .../cli/src/commands/update/schematic/index.ts | 5 ++++- packages/angular/cli/utilities/package-metadata.ts | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/angular/cli/src/commands/update/schematic/index.ts b/packages/angular/cli/src/commands/update/schematic/index.ts index 528c501ddb3c..f3eab1c72f5d 100644 --- a/packages/angular/cli/src/commands/update/schematic/index.ts +++ b/packages/angular/cli/src/commands/update/schematic/index.ts @@ -11,7 +11,10 @@ import { Rule, SchematicContext, SchematicsException, Tree } from '@angular-devk import * as npa from 'npm-package-arg'; import * as semver from 'semver'; import { Dependency, JsonSchemaForNpmPackageJsonFiles } from '../../../../utilities/package-json'; -import { NpmRepositoryPackageJson, getNpmPackageJson } from '../../../../utilities/package-metadata'; +import { + NpmRepositoryPackageJson, + getNpmPackageJson, +} from '../../../../utilities/package-metadata'; import { Schema as UpdateSchema } from './schema'; type VersionRange = string & { __VERSION_RANGE: void }; diff --git a/packages/angular/cli/utilities/package-metadata.ts b/packages/angular/cli/utilities/package-metadata.ts index fe7a42b91254..b872848270a8 100644 --- a/packages/angular/cli/utilities/package-metadata.ts +++ b/packages/angular/cli/utilities/package-metadata.ts @@ -149,6 +149,19 @@ function readOptions( } switch (key) { + // Unless auth options are scope with the registry url it appears that npm-registry-fetch ignores them, + // even though they are documented. + // https://github.com/npm/npm-registry-fetch/blob/8954f61d8d703e5eb7f3d93c9b40488f8b1b62ac/README.md + // https://github.com/npm/npm-registry-fetch/blob/8954f61d8d703e5eb7f3d93c9b40488f8b1b62ac/auth.js#L45-L91 + case '_authToken': + case 'token': + case 'username': + case 'password': + case '_auth': + case 'auth': + options['forceAuth'] ??= {}; + options['forceAuth'][key] = substitutedValue; + break; case 'noproxy': case 'no-proxy': options['noProxy'] = substitutedValue;