Skip to content

Commit 312c14b

Browse files
committed
fix(core): avoid calling file existsSync before reading
1 parent e3c4b09 commit 312c14b

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

Diff for: src/utils/yaml.js

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { readFileSync, existsSync } from "fs";
1+
import { readFileSync } from "fs";
22

33
import { safeLoad, safeDump } from "js-yaml";
44
/* eslint-disable import/no-extraneous-dependencies */
@@ -18,20 +18,17 @@ const toYAML = function(object) {
1818
};
1919

2020
const loadYAMLFile = function(configFile) {
21-
if (existsSync(configFile)) {
22-
try {
23-
const config = readFileSync(configFile, "utf8");
24-
const contents = safeLoad(config, {
25-
filename: configFile,
26-
onWarning: debug
27-
});
28-
return contents;
29-
} catch (e) {
30-
debug(e.message, e.name);
31-
return false;
32-
}
21+
try {
22+
const config = readFileSync(configFile, "utf8");
23+
const contents = safeLoad(config, {
24+
filename: configFile,
25+
onWarning: debug
26+
});
27+
return contents;
28+
} catch (e) {
29+
debug(e.message, e.name);
30+
return false;
3331
}
34-
return false;
3532
};
3633

3734
export { toYAML, loadYAMLFile };

0 commit comments

Comments
 (0)