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: eslint module path resolver for yarn workspaces #42

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"dependencies": {
"cosmiconfig": "^3.0.1",
"eslint": "^4.5.0",
"find-up": "^2.1.0",
"pify": "3.0.0",
"resolve": "1.7.1",
"throat": "4.1.0",
"worker-farm": "1.5.0"
},
Expand Down
12 changes: 12 additions & 0 deletions src/utils/__tests__/getLocalESLint.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const getLocalESLint = require('../getLocalESLint');
const requiredESLint = require('eslint');

it('requires eslint', () => {
// eslint-disable-next-line global-require
Copy link
Collaborator

Choose a reason for hiding this comment

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

This override shouldn’t be needed?

expect(getLocalESLint({})).toBe(requiredESLint);
});

it('finds eslint with custom rootDir', () => {
// eslint-disable-next-line global-require
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nor this one?

expect(getLocalESLint({ rootDir: __dirname })).toBe(requiredESLint);
});
8 changes: 4 additions & 4 deletions src/utils/getLocalESLint.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const path = require('path');
const findUp = require('find-up');
const resolve = require('resolve');

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

module.exports = getLocalESLint;
6 changes: 6 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2825,6 +2825,12 @@ resolve@1.1.7:
version "1.1.7"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"

resolve@1.7.1:
version "1.7.1"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.7.1.tgz#aadd656374fd298aee895bc026b8297418677fd3"
dependencies:
path-parse "^1.0.5"

resolve@^1.2.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.4.0.tgz#a75be01c53da25d934a98ebd0e4c4a7312f92a86"
Expand Down