index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. const inquirer = require('inquirer')
  2. const { semver } = require('@vue/cli-shared-utils')
  3. module.exports = async (api) => {
  4. const pkg = require(api.resolve('package.json'))
  5. let localESLintRange = pkg.devDependencies.eslint
  6. // if project is scaffolded by Vue CLI 3.0.x or earlier,
  7. // the ESLint dependency (ESLint v4) is inside @vue/cli-plugin-eslint;
  8. // in Vue CLI v4 it should be extracted to the project dependency list.
  9. if (api.fromVersion('^3') && !localESLintRange) {
  10. localESLintRange = '^4.19.1'
  11. api.extendPackage({
  12. devDependencies: {
  13. eslint: localESLintRange,
  14. 'babel-eslint': '^8.2.5',
  15. 'eslint-plugin-vue': '^4.5.0'
  16. }
  17. })
  18. }
  19. const localESLintMajor = semver.major(
  20. semver.maxSatisfying(['4.99.0', '5.99.0', '6.99.0', '7.99.0'], localESLintRange) ||
  21. // in case the user does not specify a typical caret range;
  22. // it is used as **fallback** because the user may have not previously
  23. // installed eslint yet, such as in the case that they are from v3.0.x
  24. require('eslint/package.json').version
  25. )
  26. if (localESLintMajor >= 6) {
  27. return
  28. }
  29. const { confirmUpgrade } = await inquirer.prompt([{
  30. name: 'confirmUpgrade',
  31. type: 'confirm',
  32. message:
  33. `Your current ESLint version is v${localESLintMajor}.\n` +
  34. `The latest major version which supported by vue-cli is v6.\n` +
  35. `Do you want to upgrade? (May contain breaking changes)\n`
  36. }])
  37. if (confirmUpgrade) {
  38. const { getDeps } = require('../eslintDeps')
  39. const newDeps = getDeps(api)
  40. if (pkg.devDependencies['@vue/eslint-config-airbnb']) {
  41. Object.assign(newDeps, getDeps(api, 'airbnb'))
  42. }
  43. if (pkg.devDependencies['@vue/eslint-config-standard']) {
  44. Object.assign(newDeps, getDeps(api, 'standard'))
  45. }
  46. if (pkg.devDependencies['@vue/eslint-config-prettier']) {
  47. Object.assign(newDeps, getDeps(api, 'prettier'))
  48. }
  49. api.extendPackage({ devDependencies: newDeps }, { warnIncompatibleVersions: false })
  50. // in case anyone's upgrading from the legacy `typescript-eslint-parser`
  51. if (api.hasPlugin('typescript')) {
  52. api.extendPackage({
  53. eslintConfig: {
  54. parserOptions: {
  55. parser: '@typescript-eslint/parser'
  56. }
  57. }
  58. })
  59. }
  60. // TODO:
  61. // transform `@vue/prettier` to `eslint:recommended` + `@vue/prettier`
  62. // transform `@vue/typescript` to `@vue/typescript/recommended` and also fix prettier compatibility for it
  63. }
  64. }