Skip to content

Commit c500512

Browse files
michalsnikhaoqunjiang
authored andcommitted
fix(cli-plugin-eslint): Resolve proper ESLint package (#2560)
1 parent 38efc03 commit c500512

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

packages/@vue/cli-plugin-eslint/index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ const path = require('path')
33
module.exports = (api, options) => {
44
if (options.lintOnSave) {
55
const extensions = require('./eslintOptions').extensions(api)
6+
const { loadModule } = require('@vue/cli-shared-utils')
7+
const cwd = api.getCwd()
8+
const eslintPkg = loadModule('eslint/package.json', cwd, true)
69

710
// eslint-loader doesn't bust cache when eslint config changes
811
// so we have to manually generate a cache identifier that takes the config
@@ -11,7 +14,7 @@ module.exports = (api, options) => {
1114
'eslint-loader',
1215
{
1316
'eslint-loader': require('eslint-loader/package.json').version,
14-
'eslint': require('eslint/package.json').version
17+
'eslint': eslintPkg.version
1518
},
1619
[
1720
'.eslintrc.js',
@@ -42,7 +45,7 @@ module.exports = (api, options) => {
4245
cacheIdentifier,
4346
emitWarning: options.lintOnSave !== 'error',
4447
emitError: options.lintOnSave === 'error',
45-
formatter: require('eslint/lib/formatters/codeframe')
48+
formatter: loadModule('eslint/lib/formatters/codeframe', cwd, true)
4649
})
4750
})
4851
}

packages/@vue/cli-plugin-eslint/lint.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ const defaultFilesToLint = [
2828
module.exports = function lint (args = {}, api) {
2929
const path = require('path')
3030
const cwd = api.resolve('.')
31-
const { CLIEngine } = require('eslint')
32-
const { log, done, exit, chalk } = require('@vue/cli-shared-utils')
31+
const { log, done, exit, chalk, loadModule } = require('@vue/cli-shared-utils')
32+
const { CLIEngine } = loadModule('eslint', cwd, true)
3333
const extensions = require('./eslintOptions').extensions(api)
3434

3535
const argsConfig = normalizeConfig(args)

0 commit comments

Comments
 (0)