Skip to content

fix(@angular/cli): normalize yarnrc/npmrc options #17339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions packages/angular/cli/utilities/package-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ function ensureNpmrc(logger: logging.LoggerApi, usingYarn: boolean, verbose: boo
if (!npmrc) {
try {
npmrc = readOptions(logger, false, verbose);
} catch {}
} catch { }

if (usingYarn) {
try {
npmrc = { ...npmrc, ...readOptions(logger, true, verbose) };
} catch {}
} catch { }
}
}
}
Expand Down Expand Up @@ -106,25 +106,45 @@ function readOptions(
logger.info(`Locating potential ${baseFilename} files:`);
}

let options: { [key: string]: string } = {};
const options: Record<string, string> = {};
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)),
};
// Normalize RC options that are needed by 'npm-registry-fetch'.
// See: https://github.com/npm/npm-registry-fetch/blob/ebddbe78a5f67118c1f7af2e02c8a22bcaf9e850/index.js#L99-L126
for (const [key, value] of Object.entries<string>(yarn ? lockfile.parse(data) : ini.parse(data))) {
switch (key) {
case 'noproxy':
options['noProxy'] = value;
break;
case 'maxsockets':
options['maxSockets'] = value;
break;
case 'https-proxy':
options['httpsProxy'] = value;
break;
case 'strict-ssl':
options['strictSSL'] = value;
break;
case 'local-address':
options['localAddress'] = value;
break;
default:
options[key] = value;
break;
}
}

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 {}
} catch { }
}
} else if (showPotentials) {
logger.info(`Trying '${location}'...not found.`);
Expand Down
30 changes: 25 additions & 5 deletions packages/schematics/update/update/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,38 @@ function readOptions(
logger.info(`Locating potential ${baseFilename} files:`);
}

let options: { [key: string]: string } = {};
const options: Record<string, string> = {};
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)),
};
// Normalize RC options that are needed by 'npm-registry-fetch'.
// See: https://github.com/npm/npm-registry-fetch/blob/ebddbe78a5f67118c1f7af2e02c8a22bcaf9e850/index.js#L99-L126
for (const [key, value] of Object.entries<string>(yarn ? lockfile.parse(data) : ini.parse(data))) {
switch (key) {
case 'noproxy':
options['noProxy'] = value;
break;
case 'maxsockets':
options['maxSockets'] = value;
break;
case 'https-proxy':
options['httpsProxy'] = value;
break;
case 'strict-ssl':
options['strictSSL'] = value;
break;
case 'local-address':
options['localAddress'] = value;
break;
default:
options[key] = value;
break;
}
}

if (options.cafile) {
const cafile = path.resolve(path.dirname(location), options.cafile);
Expand Down