Skip to content

Commit e95ca30

Browse files
authored
fix/add-error-message-for-other-module-not-found (#8)
Throwing an error if a 'MODULE_NOT_FOUND' error occurs when importing a module other than 'eslint-local-rules'
1 parent aad8528 commit e95ca30

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@ module.exports = {
2424
// Similar to native `require` behavior, but doesn't check in `node_modules` folders
2525
// Based on https://github.com/js-cli/node-findup-sync
2626
function requireUp(filename, cwd) {
27-
var filepath = path.resolve(cwd, filename);
27+
var filepath = path.resolve(cwd, filename) + exts[i];
2828

2929
for (var i = 0; i < exts.length; i++) {
3030
try {
31-
return require(filepath + exts[i]);
31+
return require(filepath);
3232
} catch(error) {
33-
// Ignore OS errors (will recurse to parent directory)
34-
if (error.code !== 'MODULE_NOT_FOUND') {
33+
var filepathNotFound = error.code === 'MODULE_NOT_FOUND' &&
34+
error.message.includes(`Cannot find module '${filepath}'`);
35+
36+
// Rethrow unless error is just saying `filepath` not found (in that case,
37+
// let next loop check parent directory instead).
38+
if (!filepathNotFound) {
3539
throw error;
3640
}
3741
}

0 commit comments

Comments
 (0)