Skip to content

Commit 529d9c0

Browse files
Tyler Kellenphated
authored andcommitted
Fix: Bail gracefully on unknown extensions when nothrow is specified
1 parent 77cbc95 commit 529d9c0

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ exports.prepare = function (extensions, filepath, cwd, nothrow) {
1515
}
1616
var config = normalize(extensions[ext]);
1717
if (!config) {
18-
throw new Error('No module loader found for "'+ext+'".');
18+
if (nothrow) {
19+
return;
20+
} else {
21+
throw new Error('No module loader found for "'+ext+'".');
22+
}
1923
}
2024
if (!cwd) {
2125
cwd = path.dirname(path.resolve(filepath));

test/fixtures/.testrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
data: {
3+
trueKey: true,
4+
falseKey: false,
5+
subKey: {
6+
subProp: 1
7+
}
8+
}
9+
};

test/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ describe('rechoir', function () {
3939
}).to.throw(/No module loader found for/);
4040
});
4141

42+
it('should return undefined if an unknown extension is specified when nothrow is enabled', function () {
43+
expect(rechoir.prepare(extensions, './test/fixtures/.testrc', null, true)).to.be.undefined;
44+
});
45+
4246
it('should throw if a module loader cannot be found or loaded', function () {
4347
expect(function () {
4448
require(testFilePath);

0 commit comments

Comments
 (0)