Skip to content

Commit 095a8b6

Browse files
committed
Makes the CLI 2 forwarding stricter (#7931)
* Makes the CLI 2 forwarding stricter * Fixes a test
1 parent eee67d0 commit 095a8b6

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

src/cli/commands/policies.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ const {run, setFlags, examples} = buildSubCommands('policies', {
167167
const rcPath = `${config.lockfileFolder}/.yarnrc.yml`;
168168
reporter.log(`Updating ${chalk.magenta(rcPath)}...`);
169169

170-
await fs.writeFilePreservingEol(rcPath, `yarnPath: ${JSON.stringify(yarnPath)}\n`);
170+
await fs.writeFilePreservingEol(rcPath, `yarnPath: ${JSON.stringify(targetPath)}\n`);
171171
} else {
172172
const rcPath = `${config.lockfileFolder}/.yarnrc`;
173173
reporter.log(`Updating ${chalk.magenta(rcPath)}...`);

src/lockfile/parse.js

+15-8
Original file line numberDiff line numberDiff line change
@@ -384,16 +384,23 @@ function hasMergeConflicts(str: string): boolean {
384384
function parse(str: string, fileLoc: string): Object {
385385
const parser = new Parser(str, fileLoc);
386386
parser.next();
387-
try {
388-
return parser.parse();
389-
} catch (error1) {
387+
388+
if (!fileLoc.endsWith(`.yml`)) {
390389
try {
391-
return safeLoad(str, {
392-
schema: FAILSAFE_SCHEMA,
393-
});
394-
} catch (error2) {
395-
throw error1;
390+
return parser.parse();
391+
} catch (error1) {
392+
try {
393+
return safeLoad(str, {
394+
schema: FAILSAFE_SCHEMA,
395+
});
396+
} catch (error2) {
397+
throw error1;
398+
}
396399
}
400+
} else {
401+
return safeLoad(str, {
402+
schema: FAILSAFE_SCHEMA,
403+
});
397404
}
398405
}
399406

src/rc.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ export function getRcConfigForFolder(cwd: string): {[key: string]: string} {
5353
}
5454

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

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

src/util/rc.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ function parseRcPaths(paths: Array<string>, parser: Function): Object {
6868
try {
6969
return parser(readFileSync(path).toString(), path);
7070
} catch (error) {
71-
return {};
71+
if (error.code === 'ENOENT' || error.code === 'EISDIR') {
72+
return {};
73+
} else {
74+
throw error;
75+
}
7276
}
7377
}),
7478
);

0 commit comments

Comments
 (0)