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

Use env var to override local eslint location #35

Closed
wants to merge 4 commits into from
Closed
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
15 changes: 13 additions & 2 deletions src/utils/getLocalESLint.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@ const findUp = require('find-up');

const getLocalESLint = config => {
const nodeModulesPath = findUp.sync('node_modules', { cwd: config.rootDir });
// eslint-disable-next-line import/no-dynamic-require, global-require
return require(path.resolve(nodeModulesPath, 'eslint'));
try {
// eslint-disable-next-line import/no-dynamic-require, global-require
return require(path.resolve(nodeModulesPath, 'eslint'));
Copy link
Member

Choose a reason for hiding this comment

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

what about just using https://www.npmjs.com/package/resolve-from here?

Replace the whole getLocalESLint with just a resolveFrom(config.rootDir, 'eslint');.

I think that should be enough (and it means findUp should not be needed)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I’d prefer not to use that package due to its aggressive dropping of support of older platforms. Could resolve work here?

Copy link
Member

Choose a reason for hiding this comment

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

seems like it takes basedir, so resolve.sync('eslint', { basedir: config.rootDir }) should in theory do the trick as well

} catch (e) {
// try resolving eslint using normal node resolution mechanism
try {
// eslint-disable-next-line global-require
return require('eslint');
} catch (ee) {
// ignore
}
throw e;
}
};

module.exports = getLocalESLint;