From b6a4e9ba84240eccad8003ee58b1f0fffa4a46f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Mon, 24 Feb 2020 14:43:03 +0100 Subject: [PATCH 1/2] Makes the CLI 2 forwarding stricter --- src/cli/commands/policies.js | 2 +- src/lockfile/parse.js | 15 ++++++--------- src/rc.js | 4 ++-- src/util/rc.js | 6 +++++- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/cli/commands/policies.js b/src/cli/commands/policies.js index 037121caf2..79a11dd57a 100644 --- a/src/cli/commands/policies.js +++ b/src/cli/commands/policies.js @@ -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)}...`); diff --git a/src/lockfile/parse.js b/src/lockfile/parse.js index d5c089c9c6..1cb261a0b2 100644 --- a/src/lockfile/parse.js +++ b/src/lockfile/parse.js @@ -384,16 +384,13 @@ function hasMergeConflicts(str: string): boolean { function parse(str: string, fileLoc: string): Object { const parser = new Parser(str, fileLoc); parser.next(); - try { + + if (!fileLoc.endsWith(`.yml`)) { return parser.parse(); - } catch (error1) { - try { - return safeLoad(str, { - schema: FAILSAFE_SCHEMA, - }); - } catch (error2) { - throw error1; - } + } else { + return safeLoad(str, { + schema: FAILSAFE_SCHEMA, + }); } } diff --git a/src/rc.js b/src/rc.js index 973d86d714..c8f48131c0 100644 --- a/src/rc.js +++ b/src/rc.js @@ -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}; } diff --git a/src/util/rc.js b/src/util/rc.js index 4be6cbba21..2e167ca214 100644 --- a/src/util/rc.js +++ b/src/util/rc.js @@ -68,7 +68,11 @@ function parseRcPaths(paths: Array, parser: Function): Object { try { return parser(readFileSync(path).toString(), path); } catch (error) { - return {}; + if (error.code === 'ENOENT' || error.code === 'EISDIR') { + return {}; + } else { + throw error; + } } }), ); From 5d3a5d6613f272baaa4a744b08274432150c21b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Mon, 24 Feb 2020 15:01:27 +0100 Subject: [PATCH 2/2] Fixes a test --- src/lockfile/parse.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/lockfile/parse.js b/src/lockfile/parse.js index 1cb261a0b2..14eaaa1a5a 100644 --- a/src/lockfile/parse.js +++ b/src/lockfile/parse.js @@ -386,7 +386,17 @@ function parse(str: string, fileLoc: string): Object { parser.next(); if (!fileLoc.endsWith(`.yml`)) { - return parser.parse(); + try { + return parser.parse(); + } catch (error1) { + try { + return safeLoad(str, { + schema: FAILSAFE_SCHEMA, + }); + } catch (error2) { + throw error1; + } + } } else { return safeLoad(str, { schema: FAILSAFE_SCHEMA,