Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/add-error-message-for-other-module-not-found #8

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ module.exports = {
// Similar to native `require` behavior, but doesn't check in `node_modules` folders
// Based on https://github.com/js-cli/node-findup-sync
function requireUp(filename, cwd) {
var filepath = path.resolve(cwd, filename);
var filepath = path.resolve(cwd, filename) + exts[i];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cletusw I missed this earlier, but filepath needs to be defined within the scope of the for loop so that it can access i

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In v1.1.1, the filepath variable evaluates to /path/to/eslint-local-rulesundefined.

This will cause MODULE_NOT_FOUND errors, an example might look like:

Error: Cannot find module '/path/to/eslint-local-rulesundefined'

Since this error message matches the pattern Cannot find module '${filepath}' that we check for, an error is not thrown, and this results in the standard 'Failed to load plugin' error being logged


for (var i = 0; i < exts.length; i++) {
try {
return require(filepath + exts[i]);
return require(filepath);
} catch(error) {
// Ignore OS errors (will recurse to parent directory)
if (error.code !== 'MODULE_NOT_FOUND') {
var filepathNotFound = error.code === 'MODULE_NOT_FOUND' &&
error.message.includes(`Cannot find module '${filepath}'`);

// Rethrow unless error is just saying `filepath` not found (in that case,
// let next loop check parent directory instead).
if (!filepathNotFound) {
throw error;
}
}
Expand Down