forked from vuejs/vue-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement a migrator to upgrade to eslint 6 (vuejs#5085)
* refactor: extract deps & config logic to separate files * feat: implement a migrator to upgrade to eslint 6 * fix: add required deps for eslint v4 * test: move migrator tests to each standalone plugins * refactor: use spread operator instead of Object.assign
- Loading branch information
1 parent
15679de
commit a468abf
Showing
8 changed files
with
236 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
packages/@vue/cli-plugin-eslint/__tests__/eslintMigrator.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
jest.setTimeout(300000) | ||
jest.mock('inquirer') | ||
|
||
beforeEach(() => { | ||
process.env.VUE_CLI_TEST_DO_INSTALL_PLUGIN = true | ||
}) | ||
|
||
const create = require('@vue/cli-test-utils/createUpgradableProject') | ||
const { expectPrompts } = require('inquirer') | ||
|
||
test('upgrade: should add eslint to devDependencies', async () => { | ||
const project = await create('plugin-eslint-v3.0', { | ||
plugins: { | ||
'@vue/cli-plugin-eslint': { | ||
version: '3.0.0' | ||
} | ||
} | ||
}) | ||
|
||
const pkg = JSON.parse(await project.read('package.json')) | ||
expect(pkg.devDependencies).not.toHaveProperty('eslint') | ||
|
||
expectPrompts([ | ||
{ | ||
message: `Your current ESLint version is v4`, | ||
confirm: false | ||
} | ||
]) | ||
|
||
await project.upgrade('eslint') | ||
|
||
const updatedPkg = JSON.parse(await project.read('package.json')) | ||
expect(updatedPkg.devDependencies.eslint).toMatch('^4') | ||
}) | ||
|
||
test.only('upgrade: should upgrade eslint from v5 to v6', async () => { | ||
const project = await create('plugin-eslint-with-eslint-5', { | ||
plugins: { | ||
'@vue/cli-plugin-eslint': { | ||
version: '3.12.1', | ||
config: 'airbnb' | ||
} | ||
} | ||
}) | ||
|
||
const pkg = JSON.parse(await project.read('package.json')) | ||
expect(pkg.devDependencies.eslint).toMatch('^5') | ||
|
||
expectPrompts([ | ||
{ | ||
message: `Your current ESLint version is v5`, | ||
confirm: true | ||
} | ||
]) | ||
|
||
try { | ||
await project.upgrade('eslint') | ||
} catch (e) { | ||
// TODO: | ||
// Currently the `afterInvoke` hook will fail, | ||
// because deps are not correctly installed in test env. | ||
// Need to fix later. | ||
} | ||
|
||
const updatedPkg = JSON.parse(await project.read('package.json')) | ||
expect(updatedPkg.devDependencies.eslint).toMatch('^6') | ||
expect(updatedPkg.devDependencies).toHaveProperty('eslint-plugin-import') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const DEPS_MAP = { | ||
base: { | ||
eslint: '^6.7.2', | ||
'eslint-plugin-vue': '^6.1.2' | ||
}, | ||
airbnb: { | ||
'@vue/eslint-config-airbnb': '^5.0.1', | ||
'eslint-plugin-import': '^2.18.2' | ||
}, | ||
prettier: { | ||
'@vue/eslint-config-prettier': '^6.0.0', | ||
'eslint-plugin-prettier': '^3.1.1', | ||
prettier: '^1.19.1' | ||
}, | ||
standard: { | ||
'@vue/eslint-config-standard': '^5.1.0', | ||
'eslint-plugin-import': '^2.18.2', | ||
'eslint-plugin-node': '^9.1.0', | ||
'eslint-plugin-promise': '^4.2.1', | ||
'eslint-plugin-standard': '^4.0.0' | ||
}, | ||
typescript: { | ||
'@vue/eslint-config-typescript': '^5.0.1', | ||
'@typescript-eslint/eslint-plugin': '^2.10.0', | ||
'@typescript-eslint/parser': '^2.10.0' | ||
} | ||
} | ||
|
||
exports.DEPS_MAP = DEPS_MAP | ||
|
||
exports.getDeps = function (api, preset) { | ||
const deps = Object.assign({}, DEPS_MAP.base, DEPS_MAP[preset]) | ||
|
||
if (api.hasPlugin('typescript')) { | ||
Object.assign(deps, DEPS_MAP.typescript) | ||
} | ||
|
||
if (api.hasPlugin('babel') && !api.hasPlugin('typescript')) { | ||
Object.assign(deps, { | ||
'babel-eslint': '^10.0.3' | ||
}) | ||
} | ||
|
||
return deps | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.