Skip to content

Commit 54a8163

Browse files
authored
feat!: upgrade to core-js 3 (#3912)
1 parent 3f364b1 commit 54a8163

File tree

7 files changed

+51
-28
lines changed

7 files changed

+51
-28
lines changed

packages/@vue/babel-preset-app/__tests__/babel-preset.spec.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ test('polyfill detection', () => {
2727
filename: 'test-entry-file.js'
2828
})
2929
// default includes
30-
expect(code).not.toMatch(genCoreJSImportRegExp('es6.promise'))
30+
expect(code).not.toMatch(genCoreJSImportRegExp('es.promise'))
3131
// usage-based detection
32-
expect(code).not.toMatch(genCoreJSImportRegExp('es6.map'))
32+
expect(code).not.toMatch(genCoreJSImportRegExp('es.map'))
3333

3434
;({ code } = babel.transformSync(`
3535
const a = new Map()
@@ -41,11 +41,11 @@ test('polyfill detection', () => {
4141
filename: 'test-entry-file.js'
4242
}))
4343
// default includes
44-
expect(code).toMatch(genCoreJSImportRegExp('es6.promise'))
44+
expect(code).toMatch(genCoreJSImportRegExp('es.promise'))
4545
// promise polyfill alone doesn't work in IE, needs this as well. fix: #1642
46-
expect(code).toMatch(genCoreJSImportRegExp('es6.array.iterator'))
46+
expect(code).toMatch(genCoreJSImportRegExp('es.array.iterator'))
4747
// usage-based detection
48-
expect(code).toMatch(/import _Map from ".*runtime-corejs2\/core-js\/map"/)
48+
expect(code).toMatch('import "core-js/modules/es.map"')
4949
})
5050

5151
test('modern mode always skips polyfills', () => {
@@ -61,9 +61,9 @@ test('modern mode always skips polyfills', () => {
6161
filename: 'test-entry-file.js'
6262
})
6363
// default includes
64-
expect(code).not.toMatch(genCoreJSImportRegExp('es6.promise'))
64+
expect(code).not.toMatch(genCoreJSImportRegExp('es.promise'))
6565
// usage-based detection
66-
expect(code).not.toMatch(/import _Map from ".*runtime-corejs2\/core-js\/map"/)
66+
expect(code).not.toMatch(/import _Map from ".*runtime-corejs3\/core-js\/map"/)
6767

6868
;({ code } = babel.transformSync(`
6969
const a = new Map()
@@ -76,9 +76,9 @@ test('modern mode always skips polyfills', () => {
7676
filename: 'test-entry-file.js'
7777
}))
7878
// default includes
79-
expect(code).not.toMatch(genCoreJSImportRegExp('es6.promise'))
79+
expect(code).not.toMatch(genCoreJSImportRegExp('es.promise'))
8080
// usage-based detection
81-
expect(code).not.toMatch(/import _Map from ".*runtime-corejs2\/core-js\/map"/)
81+
expect(code).not.toMatch(/import _Map from ".*runtime-corejs3\/core-js\/map"/)
8282
delete process.env.VUE_CLI_MODERN_BUILD
8383
})
8484

@@ -103,11 +103,11 @@ test('async/await', () => {
103103
}
104104
hello()
105105
`.trim(), defaultOptions)
106-
expect(code).toMatch(genCoreJSImportRegExp('es6.promise'))
106+
expect(code).toMatch(genCoreJSImportRegExp('es.promise'))
107107
// should use regenerator runtime
108108
expect(code).toMatch(`import "regenerator-runtime/runtime"`)
109109
// should use required helper instead of inline
110-
expect(code).toMatch(/import _asyncToGenerator from ".*runtime-corejs2\/helpers\/esm\/asyncToGenerator\"/)
110+
expect(code).toMatch(/import _asyncToGenerator from ".*runtime-corejs3\/helpers\/esm\/asyncToGenerator\"/)
111111
})
112112

113113
test('jsx', () => {
@@ -152,6 +152,6 @@ test('disable absoluteRuntime', () => {
152152
filename: 'test-entry-file.js'
153153
})
154154

155-
expect(code).toMatch('import _toConsumableArray from "@babel/runtime-corejs2/helpers/esm/toConsumableArray"')
155+
expect(code).toMatch('import _toConsumableArray from "@babel/runtime-corejs3/helpers/esm/toConsumableArray"')
156156
// expect(code).not.toMatch(genCoreJSImportRegExp('es6.promise'))
157157
})

packages/@vue/babel-preset-app/index.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@ const path = require('path')
33
const defaultPolyfills = [
44
// promise polyfill alone doesn't work in IE,
55
// needs this as well. see: #1642
6-
'es6.array.iterator',
6+
'es.array.iterator',
77
// this is required for webpack code splitting, vuex etc.
8-
'es6.promise',
8+
'es.promise',
99
// this is needed for object rest spread support in templates
1010
// as vue-template-es2015-compiler 1.8+ compiles it to Object.assign() calls.
11-
'es6.object.assign',
11+
'es.object.assign',
1212
// #2012 es6.promise replaces native Promise in FF and causes missing finally
13-
'es7.promise.finally'
13+
'es.promise.finally'
1414
]
1515

16+
// FIXME:
1617
function getPolyfills (targets, includes, { ignoreBrowserslistConfig, configPath }) {
1718
const { isPluginRequired } = require('@babel/preset-env')
18-
const builtInsList = require('@babel/preset-env/data/built-ins.json')
19+
const builtInsList = require('core-js-compat/data')
1920
const getTargets = require('@babel/preset-env/lib/targets-parser').default
2021
const builtInTargets = getTargets(targets, {
2122
ignoreBrowserslistConfig,
@@ -37,6 +38,7 @@ module.exports = (context, options = {}) => {
3738
presets.push([require('@vue/babel-preset-jsx'), typeof options.jsx === 'object' ? options.jsx : {}])
3839
}
3940

41+
const runtimePath = path.dirname(require.resolve('@babel/runtime/package.json'))
4042
const {
4143
polyfills: userPolyfills,
4244
loose = false,
@@ -62,7 +64,7 @@ module.exports = (context, options = {}) => {
6264
// However, this may cause hash inconsitency if the project is moved to another directory.
6365
// So here we allow user to explicit disable this option if hash consistency is a requirement
6466
// and the runtime version is sure to be correct.
65-
absoluteRuntime = path.dirname(require.resolve('@babel/runtime/package.json'))
67+
absoluteRuntime = runtimePath
6668
} = options
6769

6870
// resolve targets
@@ -115,6 +117,7 @@ module.exports = (context, options = {}) => {
115117
}
116118

117119
const envOptions = {
120+
corejs: 3,
118121
spec,
119122
loose,
120123
debug,
@@ -154,16 +157,31 @@ module.exports = (context, options = {}) => {
154157
// transform runtime, but only for helpers
155158
plugins.push([require('@babel/plugin-transform-runtime'), {
156159
regenerator: useBuiltIns !== 'usage',
157-
// use @babel/runtime-corejs2 so that helpers that need polyfillable APIs will reference core-js instead.
158-
// if useBuiltIns is not set to 'usage', then it means users would take care of the polyfills on their own,
159-
// i.e., core-js 2 is no longer needed.
160-
corejs: (useBuiltIns === 'usage' && !process.env.VUE_CLI_MODERN_BUILD) ? 2 : false,
160+
161+
// polyfills are injected by preset-env & polyfillsPlugin, so no need to add them again
162+
corejs: false,
163+
161164
helpers: useBuiltIns === 'usage',
162165
useESModules: !process.env.VUE_CLI_BABEL_TRANSPILE_MODULES,
163166

164167
absoluteRuntime
165168
}])
166169

170+
// use @babel/runtime-corejs3 so that helpers that need polyfillable APIs will reference core-js instead.
171+
// if useBuiltIns is not set to 'usage', then it means users would take care of the polyfills on their own,
172+
// i.e., core-js 3 is no longer needed.
173+
// this extra plugin can be removed once this issue resolves:
174+
// https://github.com/babel/babel/issues/9903
175+
if (useBuiltIns === 'usage' && !process.env.VUE_CLI_MODERN_BUILD) {
176+
const runtimeCoreJs3Path = path.dirname(require.resolve('@babel/runtime-corejs3/package.json'))
177+
plugins.push([require('babel-plugin-module-resolver'), {
178+
alias: {
179+
'@babel/runtime': '@babel/runtime-corejs3',
180+
[runtimePath]: runtimeCoreJs3Path
181+
}
182+
}])
183+
}
184+
167185
return {
168186
presets,
169187
plugins

packages/@vue/babel-preset-app/package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@
2727
"@babel/plugin-proposal-decorators": "^7.1.0",
2828
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
2929
"@babel/plugin-syntax-jsx": "^7.0.0",
30-
"@babel/plugin-transform-runtime": "^7.4.0",
31-
"@babel/preset-env": "^7.0.0 < 7.4.0",
32-
"@babel/runtime": "^7.0.0",
33-
"@babel/runtime-corejs2": "^7.2.0",
30+
"@babel/plugin-transform-runtime": "^7.4.3",
31+
"@babel/preset-env": "^7.4.3",
32+
"@babel/runtime": "^7.4.3",
33+
"@babel/runtime-corejs3": "^7.4.3",
3434
"@vue/babel-preset-jsx": "^1.0.0-beta.3",
3535
"babel-plugin-dynamic-import-node": "^2.2.0",
36-
"core-js": "^2.6.5"
36+
"babel-plugin-module-resolver": "^3.2.0",
37+
"core-js": "^3.0.1",
38+
"core-js-compat": "^3.0.1"
3739
},
3840
"gitHead": "0dc793497281718762a5477a3de4a7ee439cdda6"
3941
}

packages/@vue/cli-plugin-babel/generator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = api => {
1010
presets: ['@vue/app']
1111
},
1212
dependencies: {
13-
'core-js': '^2.6.5'
13+
'core-js': '^3.0.1'
1414
}
1515
})
1616
}

packages/@vue/cli-ui-addon-webpack/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@vue/cli-plugin-eslint": "^3.6.0",
2323
"@vue/cli-service": "^3.6.0",
2424
"@vue/eslint-config-standard": "^4.0.0",
25+
"core-js": "^3.0.1",
2526
"eslint": "^5.16.0",
2627
"stylus": "^0.54.5",
2728
"stylus-loader": "^3.0.2",

packages/@vue/cli-ui-addon-widgets/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@vue/cli-plugin-eslint": "^3.6.0",
2323
"@vue/cli-service": "^3.6.0",
2424
"@vue/eslint-config-standard": "^4.0.0",
25+
"core-js": "^3.0.1",
2526
"eslint": "^5.16.0",
2627
"stylus": "^0.54.5",
2728
"stylus-loader": "^3.0.2",

packages/@vue/cli-ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"@vue/eslint-config-standard": "^4.0.0",
7373
"@vue/ui": "^0.9.1",
7474
"ansi_up": "^3.0.0",
75+
"core-js": "^3.0.1",
7576
"cross-env": "^5.1.5",
7677
"eslint": "^5.16.0",
7778
"eslint-plugin-graphql": "^3.0.3",

0 commit comments

Comments
 (0)