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

Adds basic support for .yamlrc.yml (yarnPath only, v2) #7350

Merged
merged 1 commit into from Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/rc.js
Expand Up @@ -43,7 +43,11 @@ export function getRcConfigForCwd(cwd: string, args: Array<string>): {[key: stri
}

function loadRcFile(fileText: string, filePath: string): {[key: string]: string} {
const {object: values} = parse(fileText, 'yarnrc');
let {object: values} = parse(fileText, 'yarnrc');

if (filePath.match(/\.yml$/)) {
values = {yarnPath: values.yarnPath};
}

// some keys reference directories so keep their relativity
for (const key in values) {
Expand Down
30 changes: 20 additions & 10 deletions src/util/rc.js
Expand Up @@ -11,26 +11,36 @@ const home = isWin ? process.env.USERPROFILE : process.env.HOME;
function getRcPaths(name: string, cwd: string): Array<string> {
const configPaths = [];

function addConfigPath(...segments) {
function pushConfigPath(...segments) {
configPaths.push(path.join(...segments));
if (segments[segments.length - 1] === `.${name}rc`) {
configPaths.push(path.join(...segments.slice(0, -1), `.${name}rc.yml`));
}
}

function unshiftConfigPath(...segments) {
configPaths.unshift(path.join(...segments));
if (segments[segments.length - 1] === `.${name}rc`) {
configPaths.unshift(path.join(...segments.slice(0, -1), `.${name}rc.yml`));
}
}

if (!isWin) {
addConfigPath(etc, name, 'config');
addConfigPath(etc, `${name}rc`);
pushConfigPath(etc, name, 'config');
pushConfigPath(etc, `${name}rc`);
}

if (home) {
addConfigPath(CONFIG_DIRECTORY);
addConfigPath(home, '.config', name, 'config');
addConfigPath(home, '.config', name);
addConfigPath(home, `.${name}`, 'config');
addConfigPath(home, `.${name}rc`);
pushConfigPath(CONFIG_DIRECTORY);
pushConfigPath(home, '.config', name, 'config');
pushConfigPath(home, '.config', name);
pushConfigPath(home, `.${name}`, 'config');
pushConfigPath(home, `.${name}rc`);
}

// add .yarnrc locations relative to the cwd
while (true) {
configPaths.unshift(path.join(cwd, `.${name}rc`));
unshiftConfigPath(cwd, `.${name}rc`);

const upperCwd = path.dirname(cwd);
if (upperCwd === cwd) {
Expand All @@ -45,7 +55,7 @@ function getRcPaths(name: string, cwd: string): Array<string> {
const envVariable = `${name}_config`.toUpperCase();

if (process.env[envVariable]) {
addConfigPath(process.env[envVariable]);
pushConfigPath(process.env[envVariable]);
}

return configPaths;
Expand Down