Skip to content

Commit f0bbb68

Browse files
authored
Do not swallow errors in exists() and only call exists if option is string (#495)
1 parent 62ae6cc commit f0bbb68

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ module.exports = function(source, inputSourceMap) {
113113
const fileSystem = this.fs ? this.fs : fs;
114114
let babelrcPath = null;
115115
if (loaderOptions.babelrc !== false) {
116-
babelrcPath = exists(fileSystem, loaderOptions.babelrc)
116+
babelrcPath = typeof loaderOptions.babelrc === "string" &&
117+
exists(fileSystem, loaderOptions.babelrc)
117118
? loaderOptions.babelrc
118119
: resolveRc(fileSystem, path.dirname(filename));
119120
}

src/utils/exists.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ module.exports = function(fileSystem, filename) {
33

44
try {
55
exists = fileSystem.statSync(filename).isFile();
6-
} catch (e) {}
6+
} catch (err) {
7+
if (err.code !== "ENOENT") throw err;
8+
}
79

810
return exists;
911
};

test/utils/exists.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ test("should return boolean if file exists", t => {
1515
t.true(realFile);
1616
t.false(fakeFile);
1717
});
18+
19+
test("should rethrow errors besides ENOENT", t => {
20+
t.throws(() => exists(fs, false), /path must be a string/);
21+
t.throws(() => exists(fs, undefined), /path must be a string/);
22+
});

0 commit comments

Comments
 (0)