Skip to content

Commit

Permalink
Makes the CLI 2 forwarding stricter (#7931)
Browse files Browse the repository at this point in the history
* Makes the CLI 2 forwarding stricter

* Fixes a test
  • Loading branch information
arcanis committed Mar 6, 2020
1 parent eee67d0 commit 095a8b6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/cli/commands/policies.js
Expand Up @@ -167,7 +167,7 @@ const {run, setFlags, examples} = buildSubCommands('policies', {
const rcPath = `${config.lockfileFolder}/.yarnrc.yml`;
reporter.log(`Updating ${chalk.magenta(rcPath)}...`);

await fs.writeFilePreservingEol(rcPath, `yarnPath: ${JSON.stringify(yarnPath)}\n`);
await fs.writeFilePreservingEol(rcPath, `yarnPath: ${JSON.stringify(targetPath)}\n`);
} else {
const rcPath = `${config.lockfileFolder}/.yarnrc`;
reporter.log(`Updating ${chalk.magenta(rcPath)}...`);
Expand Down
23 changes: 15 additions & 8 deletions src/lockfile/parse.js
Expand Up @@ -384,16 +384,23 @@ function hasMergeConflicts(str: string): boolean {
function parse(str: string, fileLoc: string): Object {
const parser = new Parser(str, fileLoc);
parser.next();
try {
return parser.parse();
} catch (error1) {

if (!fileLoc.endsWith(`.yml`)) {
try {
return safeLoad(str, {
schema: FAILSAFE_SCHEMA,
});
} catch (error2) {
throw error1;
return parser.parse();
} catch (error1) {
try {
return safeLoad(str, {
schema: FAILSAFE_SCHEMA,
});
} catch (error2) {
throw error1;
}
}
} else {
return safeLoad(str, {
schema: FAILSAFE_SCHEMA,
});
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/rc.js
Expand Up @@ -53,9 +53,9 @@ export function getRcConfigForFolder(cwd: string): {[key: string]: string} {
}

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

if (filePath.match(/\.yml$/)) {
if (filePath.match(/\.yml$/) && typeof values.yarnPath === 'string') {
values = {'yarn-path': values.yarnPath};
}

Expand Down
6 changes: 5 additions & 1 deletion src/util/rc.js
Expand Up @@ -68,7 +68,11 @@ function parseRcPaths(paths: Array<string>, parser: Function): Object {
try {
return parser(readFileSync(path).toString(), path);
} catch (error) {
return {};
if (error.code === 'ENOENT' || error.code === 'EISDIR') {
return {};
} else {
throw error;
}
}
}),
);
Expand Down

0 comments on commit 095a8b6

Please sign in to comment.