Skip to content

Commit

Permalink
Do not swallow errors in exists() and only call exists if option is s…
Browse files Browse the repository at this point in the history
…tring (#495)
  • Loading branch information
danez authored Jul 29, 2017
1 parent 62ae6cc commit f0bbb68
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ module.exports = function(source, inputSourceMap) {
const fileSystem = this.fs ? this.fs : fs;
let babelrcPath = null;
if (loaderOptions.babelrc !== false) {
babelrcPath = exists(fileSystem, loaderOptions.babelrc)
babelrcPath = typeof loaderOptions.babelrc === "string" &&
exists(fileSystem, loaderOptions.babelrc)
? loaderOptions.babelrc
: resolveRc(fileSystem, path.dirname(filename));
}
Expand Down
4 changes: 3 additions & 1 deletion src/utils/exists.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ module.exports = function(fileSystem, filename) {

try {
exists = fileSystem.statSync(filename).isFile();
} catch (e) {}
} catch (err) {
if (err.code !== "ENOENT") throw err;
}

return exists;
};
5 changes: 5 additions & 0 deletions test/utils/exists.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ test("should return boolean if file exists", t => {
t.true(realFile);
t.false(fakeFile);
});

test("should rethrow errors besides ENOENT", t => {
t.throws(() => exists(fs, false), /path must be a string/);
t.throws(() => exists(fs, undefined), /path must be a string/);
});

0 comments on commit f0bbb68

Please sign in to comment.