mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-03-12 20:19:55 -05:00
feat(babel): transform preset names in the plugin migrator (#4629)
This commit is contained in:
@@ -4,3 +4,4 @@ packages/test
|
||||
temp
|
||||
entry-wc.js
|
||||
dist
|
||||
__testfixtures__
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
module.exports = {
|
||||
presets: [
|
||||
["@vue/app", {
|
||||
polyfills: []
|
||||
}]
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
module.exports = {
|
||||
presets: [
|
||||
["@vue/cli-plugin-babel/preset", {
|
||||
polyfills: []
|
||||
}]
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
presets: ["@vue/app"]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
presets: ["@vue/cli-plugin-babel/preset"]
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
const config = {
|
||||
presets: [
|
||||
[require("@vue/babel-preset-app"), {
|
||||
polyfills: []
|
||||
}]
|
||||
]
|
||||
}
|
||||
|
||||
module.exports = config
|
||||
@@ -0,0 +1,9 @@
|
||||
const config = {
|
||||
presets: [
|
||||
[require("@vue/cli-plugin-babel/preset"), {
|
||||
polyfills: []
|
||||
}]
|
||||
]
|
||||
}
|
||||
|
||||
module.exports = config
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
presets: [`@vue/app`]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
presets: [`@vue/cli-plugin-babel/preset`]
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
jest.autoMockOff()
|
||||
|
||||
const { defineTest } = require('jscodeshift/dist/testUtils')
|
||||
|
||||
defineTest(__dirname, 'usePluginPreset', null, 'default')
|
||||
defineTest(__dirname, 'usePluginPreset', null, 'customConfig')
|
||||
defineTest(__dirname, 'usePluginPreset', null, 'require')
|
||||
defineTest(__dirname, 'usePluginPreset', null, 'templateLiteral')
|
||||
|
||||
41
packages/@vue/cli-plugin-babel/codemods/usePluginPreset.js
Normal file
41
packages/@vue/cli-plugin-babel/codemods/usePluginPreset.js
Normal file
@@ -0,0 +1,41 @@
|
||||
module.exports = function (fileInfo, api) {
|
||||
const j = api.jscodeshift
|
||||
const root = j(fileInfo.source)
|
||||
|
||||
root
|
||||
.find(j.Literal, { value: '@vue/app' })
|
||||
.forEach(({ node }) => {
|
||||
node.value = '@vue/cli-plugin-babel/preset'
|
||||
})
|
||||
root
|
||||
.find(j.Literal, { value: '@vue/babel-preset-app' })
|
||||
.forEach(({ node }) => {
|
||||
node.value = '@vue/cli-plugin-babel/preset'
|
||||
})
|
||||
|
||||
const templateLiterals = root
|
||||
.find(j.TemplateLiteral, {
|
||||
expressions: { length: 0 }
|
||||
})
|
||||
|
||||
templateLiterals
|
||||
.find(j.TemplateElement, {
|
||||
value: {
|
||||
cooked: '@vue/app'
|
||||
}
|
||||
})
|
||||
.forEach(({ node }) => {
|
||||
node.value = { cooked: '@vue/cli-plugin-babel/preset', raw: '@vue/cli-plugin-babel/preset' }
|
||||
})
|
||||
templateLiterals
|
||||
.find(j.TemplateElement, {
|
||||
value: {
|
||||
cooked: '@vue/babel-preset-app'
|
||||
}
|
||||
})
|
||||
.forEach(({ node }) => {
|
||||
node.value = { cooked: '@vue/cli-plugin-babel/preset', raw: '@vue/cli-plugin-babel/preset' }
|
||||
})
|
||||
|
||||
return root.toSource()
|
||||
}
|
||||
@@ -1,16 +1,6 @@
|
||||
const { chalk } = require('@vue/cli-shared-utils')
|
||||
|
||||
module.exports = (api) => {
|
||||
// TODO: backport this part to v3
|
||||
// if (api.fromVersion('<=3.5.3')) {
|
||||
// // add core-js@2 as dependency
|
||||
// api.extendPackage({
|
||||
// dependencies: {
|
||||
// 'core-js': '^2.6.5'
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
|
||||
if (api.fromVersion('^3')) {
|
||||
api.extendPackage({
|
||||
dependencies: {
|
||||
@@ -18,6 +8,8 @@ module.exports = (api) => {
|
||||
}
|
||||
}, true)
|
||||
|
||||
api.transformScript('babel.config.js', require('../codemods/usePluginPreset'))
|
||||
|
||||
// TODO: implement a codemod to migrate polyfills
|
||||
api.exitLog(`core-js has been upgraded from v2 to v3.
|
||||
If you have any custom polyfills defined in ${chalk.yellow('babael.config.js')}, please be aware their names may have been changed.
|
||||
|
||||
@@ -29,6 +29,9 @@
|
||||
"peerDependencies": {
|
||||
"@vue/cli-service": "^3.0.0 || ^4.0.0-0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jscodeshift": "^0.6.4"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user