Skip to content

Commit

Permalink
Fix: global config should be looked up in ${PREFIX}/etc/ (#3958)
Browse files Browse the repository at this point in the history
**Summary**

This searches for the global `rc` files at `${PREFIX}/etc/{npm,yarn}rc`, whereas previously it looked in `${PREFIX}/.{npm,yarn}rc`.  By code inspection it looks like the NPM code does the same thing on windows and posix, but the documentation suggests it doesn't use the `/etc` path component.

**Test plan**

N/A
  • Loading branch information
Parakleta authored and BYK committed Jul 20, 2017
1 parent 1d06624 commit fa0fb69
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/registries/npm-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,18 @@ export default class NpmRegistry extends Registry {
}

async getPossibleConfigLocations(filename: string, reporter: Reporter): Promise<Array<[boolean, string, string]>> {
// npmrc --> ./.npmrc, ~/.npmrc, ${prefix}/etc/npmrc
const localfile = '.' + filename;
const possibles = [
[false, path.join(this.cwd, filename)],
[true, this.config.userconfig || path.join(userHome, filename)],
[false, path.join(getGlobalPrefix(), filename)],
[false, path.join(this.cwd, localfile)],
[true, this.config.userconfig || path.join(userHome, localfile)],
[false, path.join(getGlobalPrefix(), 'etc', filename)],
];

// npmrc --> ../.npmrc, ../../.npmrc, etc.
const foldersFromRootToCwd = getPosixPath(this.cwd).split('/');
while (foldersFromRootToCwd.length > 1) {
possibles.push([false, path.join(foldersFromRootToCwd.join(path.sep), filename)]);
possibles.push([false, path.join(foldersFromRootToCwd.join(path.sep), localfile)]);
foldersFromRootToCwd.pop();
}

Expand Down Expand Up @@ -167,7 +170,7 @@ export default class NpmRegistry extends Registry {
// docs: https://docs.npmjs.com/misc/config
this.mergeEnv('npm_config_');

for (const [, loc, file] of await this.getPossibleConfigLocations('.npmrc', this.reporter)) {
for (const [, loc, file] of await this.getPossibleConfigLocations('npmrc', this.reporter)) {
const config = NpmRegistry.normalizeConfig(ini.parse(file));

// normalize offline mirror path relative to the current npmrc
Expand Down
2 changes: 1 addition & 1 deletion src/registries/yarn-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default class YarnRegistry extends NpmRegistry {
}

async loadConfig(): Promise<void> {
for (const [isHome, loc, file] of await this.getPossibleConfigLocations('.yarnrc', this.reporter)) {
for (const [isHome, loc, file] of await this.getPossibleConfigLocations('yarnrc', this.reporter)) {
const {object: config} = parse(file, loc);

if (isHome) {
Expand Down

0 comments on commit fa0fb69

Please sign in to comment.