Skip to content

Commit

Permalink
fix(@angular/cli): update pacote to version 11
Browse files Browse the repository at this point in the history
With this change Pacote is updated to version 11.1.13.

This also requires normalization of options because Pacote now passes the options to `npm-registry-fetch` which requires some options to be camelCased.

Partially addresses #19624
  • Loading branch information
alan-agius4 authored and filipesilva committed Dec 16, 2020
1 parent f58ec52 commit 36889b6
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 234 deletions.
2 changes: 1 addition & 1 deletion packages/angular/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"npm-package-arg": "8.1.0",
"npm-pick-manifest": "6.1.0",
"open": "7.3.0",
"pacote": "9.5.12",
"pacote": "11.1.13",
"resolve": "1.19.0",
"rimraf": "3.0.2",
"semver": "7.3.4",
Expand Down
62 changes: 44 additions & 18 deletions packages/angular/cli/utilities/package-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,20 @@ export interface PackageMetadata {
'dist-tags'?: unknown;
}

let npmrc: { [key: string]: string };
type PackageManagerOptions = Record<string, unknown>;

let npmrc: PackageManagerOptions;

function ensureNpmrc(logger: logging.LoggerApi, usingYarn: boolean, verbose: boolean): void {
if (!npmrc) {
try {
npmrc = readOptions(logger, false, verbose);
} catch {}
} catch { }

if (usingYarn) {
try {
npmrc = { ...npmrc, ...readOptions(logger, true, verbose) };
} catch {}
} catch { }
}
}
}
Expand All @@ -77,7 +79,7 @@ function readOptions(
logger: logging.LoggerApi,
yarn = false,
showPotentials = false,
): Record<string, string> {
): PackageManagerOptions {
const cwd = process.cwd();
const baseFilename = yarn ? 'yarnrc' : 'npmrc';
const dotFilename = '.' + baseFilename;
Expand Down Expand Up @@ -107,25 +109,48 @@ function readOptions(
logger.info(`Locating potential ${baseFilename} files:`);
}

let options: { [key: string]: string } = {};
const options: PackageManagerOptions = {};
for (const location of [...defaultConfigLocations, ...projectConfigLocations]) {
if (existsSync(location)) {
if (showPotentials) {
logger.info(`Trying '${location}'...found.`);
}

const data = readFileSync(location, 'utf8');
options = {
...options,
...(yarn ? lockfile.parse(data) : ini.parse(data)),
};

if (options.cafile) {
const cafile = path.resolve(path.dirname(location), options.cafile);
delete options.cafile;
try {
options.ca = readFileSync(cafile, 'utf8').replace(/\r?\n/, '\\n');
} catch {}
// Normalize RC options that are needed by 'npm-registry-fetch'.
// See: https://github.com/npm/npm-registry-fetch/blob/ebddbe78a5f67118c1f7af2e02c8a22bcaf9e850/index.js#L99-L126
const rcConfig: PackageManagerOptions = yarn ? lockfile.parse(data) : ini.parse(data);
for (const [key, value] of Object.entries(rcConfig)) {
switch (key) {
case 'noproxy':
case 'no-proxy':
options['noProxy'] = value;
break;
case 'maxsockets':
options['maxSockets'] = value;
break;
case 'https-proxy':
case 'proxy':
options['proxy'] = value;
break;
case 'strict-ssl':
options['strictSSL'] = value;
break;
case 'local-address':
options['localAddress'] = value;
break;
case 'cafile':
if (typeof value === 'string') {
const cafile = path.resolve(path.dirname(location), value);
try {
options['ca'] = readFileSync(cafile, 'utf8').replace(/\r?\n/, '\\n');
} catch { }
}
break;
default:
options[key] = value;
break;
}
}
} else if (showPotentials) {
logger.info(`Trying '${location}'...not found.`);
Expand All @@ -134,8 +159,9 @@ function readOptions(

// Substitute any environment variable references
for (const key in options) {
if (typeof options[key] === 'string') {
options[key] = options[key].replace(/\$\{([^\}]+)\}/, (_, name) => process.env[name] || '');
const value = options[key];
if (typeof value === 'string') {
options[key] = value.replace(/\$\{([^\}]+)\}/, (_, name) => process.env[name] || '');
}
}

Expand Down

0 comments on commit 36889b6

Please sign in to comment.