Skip to content

Commit 36889b6

Browse files
alan-agius4filipesilva
authored andcommitted
fix(@angular/cli): update pacote to version 11
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
1 parent f58ec52 commit 36889b6

File tree

3 files changed

+166
-234
lines changed

3 files changed

+166
-234
lines changed

packages/angular/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"npm-package-arg": "8.1.0",
4040
"npm-pick-manifest": "6.1.0",
4141
"open": "7.3.0",
42-
"pacote": "9.5.12",
42+
"pacote": "11.1.13",
4343
"resolve": "1.19.0",
4444
"rimraf": "3.0.2",
4545
"semver": "7.3.4",

packages/angular/cli/utilities/package-metadata.ts

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,20 @@ export interface PackageMetadata {
5757
'dist-tags'?: unknown;
5858
}
5959

60-
let npmrc: { [key: string]: string };
60+
type PackageManagerOptions = Record<string, unknown>;
61+
62+
let npmrc: PackageManagerOptions;
6163

6264
function ensureNpmrc(logger: logging.LoggerApi, usingYarn: boolean, verbose: boolean): void {
6365
if (!npmrc) {
6466
try {
6567
npmrc = readOptions(logger, false, verbose);
66-
} catch {}
68+
} catch { }
6769

6870
if (usingYarn) {
6971
try {
7072
npmrc = { ...npmrc, ...readOptions(logger, true, verbose) };
71-
} catch {}
73+
} catch { }
7274
}
7375
}
7476
}
@@ -77,7 +79,7 @@ function readOptions(
7779
logger: logging.LoggerApi,
7880
yarn = false,
7981
showPotentials = false,
80-
): Record<string, string> {
82+
): PackageManagerOptions {
8183
const cwd = process.cwd();
8284
const baseFilename = yarn ? 'yarnrc' : 'npmrc';
8385
const dotFilename = '.' + baseFilename;
@@ -107,25 +109,48 @@ function readOptions(
107109
logger.info(`Locating potential ${baseFilename} files:`);
108110
}
109111

110-
let options: { [key: string]: string } = {};
112+
const options: PackageManagerOptions = {};
111113
for (const location of [...defaultConfigLocations, ...projectConfigLocations]) {
112114
if (existsSync(location)) {
113115
if (showPotentials) {
114116
logger.info(`Trying '${location}'...found.`);
115117
}
116118

117119
const data = readFileSync(location, 'utf8');
118-
options = {
119-
...options,
120-
...(yarn ? lockfile.parse(data) : ini.parse(data)),
121-
};
122-
123-
if (options.cafile) {
124-
const cafile = path.resolve(path.dirname(location), options.cafile);
125-
delete options.cafile;
126-
try {
127-
options.ca = readFileSync(cafile, 'utf8').replace(/\r?\n/, '\\n');
128-
} catch {}
120+
// Normalize RC options that are needed by 'npm-registry-fetch'.
121+
// See: https://github.com/npm/npm-registry-fetch/blob/ebddbe78a5f67118c1f7af2e02c8a22bcaf9e850/index.js#L99-L126
122+
const rcConfig: PackageManagerOptions = yarn ? lockfile.parse(data) : ini.parse(data);
123+
for (const [key, value] of Object.entries(rcConfig)) {
124+
switch (key) {
125+
case 'noproxy':
126+
case 'no-proxy':
127+
options['noProxy'] = value;
128+
break;
129+
case 'maxsockets':
130+
options['maxSockets'] = value;
131+
break;
132+
case 'https-proxy':
133+
case 'proxy':
134+
options['proxy'] = value;
135+
break;
136+
case 'strict-ssl':
137+
options['strictSSL'] = value;
138+
break;
139+
case 'local-address':
140+
options['localAddress'] = value;
141+
break;
142+
case 'cafile':
143+
if (typeof value === 'string') {
144+
const cafile = path.resolve(path.dirname(location), value);
145+
try {
146+
options['ca'] = readFileSync(cafile, 'utf8').replace(/\r?\n/, '\\n');
147+
} catch { }
148+
}
149+
break;
150+
default:
151+
options[key] = value;
152+
break;
153+
}
129154
}
130155
} else if (showPotentials) {
131156
logger.info(`Trying '${location}'...not found.`);
@@ -134,8 +159,9 @@ function readOptions(
134159

135160
// Substitute any environment variable references
136161
for (const key in options) {
137-
if (typeof options[key] === 'string') {
138-
options[key] = options[key].replace(/\$\{([^\}]+)\}/, (_, name) => process.env[name] || '');
162+
const value = options[key];
163+
if (typeof value === 'string') {
164+
options[key] = value.replace(/\$\{([^\}]+)\}/, (_, name) => process.env[name] || '');
139165
}
140166
}
141167

0 commit comments

Comments
 (0)