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

Makes the CLI 2 forwarding stricter #7931

Merged
merged 2 commits into from
Feb 24, 2020
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
2 changes: 1 addition & 1 deletion src/cli/commands/policies.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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