fix(@angular/cli): handle `YARN_` environment variables during `ng up… · angular/angular-cli@c1eddbd

@@ -131,7 +131,7 @@ function readOptions(

131131

logger.info(`Locating potential ${baseFilename} files:`);

132132

}

133133134-

let options: PackageManagerOptions = {};

134+

let rcOptions: PackageManagerOptions = {};

135135

for (const location of [...defaultConfigLocations, ...projectConfigLocations]) {

136136

if (existsSync(location)) {

137137

if (showPotentials) {

@@ -143,25 +143,33 @@ function readOptions(

143143

// See: https://github.com/npm/npm-registry-fetch/blob/ebddbe78a5f67118c1f7af2e02c8a22bcaf9e850/index.js#L99-L126

144144

const rcConfig: PackageManagerOptions = yarn ? lockfile.parse(data) : ini.parse(data);

145145146-

options = normalizeOptions(rcConfig, location);

146+

rcOptions = normalizeOptions(rcConfig, location);

147147

}

148148

}

149149150+

const envVariablesOptions: PackageManagerOptions = {};

150151

for (const [key, value] of Object.entries(process.env)) {

151-

if (!value || !key.toLowerCase().startsWith('npm_config_')) {

152+

if (!value) {

152153

continue;

153154

}

154155155-

const normalizedName = key

156-

.substr(11)

157-

.replace(/(?!^)_/g, '-') // don't replace _ at the start of the key

158-

.toLowerCase();

159-

options[normalizedName] = value;

160-

}

156+

let normalizedName = key.toLowerCase();

157+

if (normalizedName.startsWith('npm_config_')) {

158+

normalizedName = normalizedName.substring(11);

159+

} else if (yarn && normalizedName.startsWith('yarn_')) {

160+

normalizedName = normalizedName.substring(5);

161+

} else {

162+

continue;

163+

}

161164162-

options = normalizeOptions(options);

165+

normalizedName = normalizedName.replace(/(?!^)_/g, '-'); // don't replace _ at the start of the key.s

166+

envVariablesOptions[normalizedName] = value;

167+

}

163168164-

return options;

169+

return {

170+

...rcOptions,

171+

...normalizeOptions(envVariablesOptions),

172+

};

165173

}

166174167175

function normalizeOptions(

@@ -302,7 +310,6 @@ export async function fetchPackageManifest(

302310

} = {},

303311

): Promise<PackageManifest> {

304312

const { usingYarn = false, verbose = false, registry } = options;

305-306313

ensureNpmrc(logger, usingYarn, verbose);

307314308315

const response = await pacote.manifest(name, {

@@ -329,18 +336,7 @@ export function getNpmPackageJson(

329336

}

330337331338

const { usingYarn = false, verbose = false, registry } = options;

332-333-

if (!npmrc) {

334-

try {

335-

npmrc = readOptions(logger, false, verbose);

336-

} catch {}

337-338-

if (usingYarn) {

339-

try {

340-

npmrc = { ...npmrc, ...readOptions(logger, true, verbose) };

341-

} catch {}

342-

}

343-

}

339+

ensureNpmrc(logger, usingYarn, verbose);

344340345341

const resultPromise: Promise<NpmRepositoryPackageJson> = pacote.packument(packageName, {

346342

fullMetadata: true,