Skip to content
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

Chore: use a Set for look ups in PATH_KEYS #4472

Merged
merged 1 commit into from
Sep 15, 2017
Merged
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
8 changes: 3 additions & 5 deletions src/rc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {parse} from './lockfile';
import * as rcUtil from './util/rc.js';

// Keys that will get resolved relative to the path of the rc file they belong to
const PATH_KEYS = ['yarn-path', 'cache-folder', 'global-folder', 'modules-folder', 'cwd'];
const PATH_KEYS = new Set(['yarn-path', 'cache-folder', 'global-folder', 'modules-folder', 'cwd']);

// given a cwd, load all .yarnrc files relative to it
export function getRcConfigForCwd(cwd: string): {[key: string]: string} {
Expand All @@ -14,10 +14,8 @@ export function getRcConfigForCwd(cwd: string): {[key: string]: string} {

// some keys reference directories so keep their relativity
for (const key in values) {
for (const pathKey of PATH_KEYS) {
if (key.replace(/^(--)?([^.]+\.)*/, '') === pathKey) {
values[key] = resolve(dirname(filePath), values[key]);
}
if (PATH_KEYS.has(key.replace(/^(--)?([^.]+\.)*/, ''))) {
values[key] = resolve(dirname(filePath), values[key]);
}
}

Expand Down