Skip to content

Commit

Permalink
Adds basic support for .yamlrc.yml (yarnPath only, v2) (yarnpkg#7350)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanis authored and VincentBailly committed Jun 10, 2020
1 parent 01f6177 commit b5ca1c7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
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

0 comments on commit b5ca1c7

Please sign in to comment.