Skip to content

Commit 94b41c9

Browse files
committed
feat!: upgrade to core-js 3 (#3912)
1 parent dfe3987 commit 94b41c9

File tree

7 files changed

+36
-31
lines changed

7 files changed

+36
-31
lines changed

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const defaultOptions = {
77
filename: 'test-entry-file.js'
88
}
99

10-
const genCoreJSImportRegExp = mod => {
10+
const getAbsolutePolyfill = mod => {
1111
// expected to include a `node_modules` in the import path because we use absolute path for core-js
1212
return new RegExp(`import "${['.*node_modules', 'core-js', 'modules', mod].join(`[\\${path.sep}]+`)}`)
1313
}
@@ -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(getAbsolutePolyfill('es.promise'))
3131
// usage-based detection
32-
expect(code).not.toMatch(genCoreJSImportRegExp('es6.map'))
32+
expect(code).not.toMatch('import "core-js/modules/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(getAbsolutePolyfill('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(getAbsolutePolyfill('es.array.iterator'))
4747
// usage-based detection
48-
expect(code).toMatch(/import "core-js\/modules\/es6.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(getAbsolutePolyfill('es.promise'))
6565
// usage-based detection
66-
expect(code).not.toMatch(/import "core-js\/modules\/es6.map"/)
66+
expect(code).not.toMatch('import "core-js/modules/es.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(getAbsolutePolyfill('es.promise'))
8080
// usage-based detection
81-
expect(code).not.toMatch(/import "core-js\/modules\/es6.map"/)
81+
expect(code).not.toMatch('import "core-js/modules/es.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(getAbsolutePolyfill('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"')
156-
expect(code).not.toMatch(genCoreJSImportRegExp('es6.promise'))
155+
expect(code).toMatch('import _toConsumableArray from "@babel/runtime-corejs3/helpers/esm/toConsumableArray"')
156+
expect(code).not.toMatch(getAbsolutePolyfill('es.promise'))
157157
})

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ 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

1616
function getPolyfills (targets, includes, { ignoreBrowserslistConfig, configPath }) {
1717
const { isPluginRequired } = require('@babel/preset-env')
18-
const builtInsList = require('@babel/preset-env/data/built-ins.json')
18+
const builtInsList = require('core-js-compat/data')
1919
const getTargets = require('@babel/preset-env/lib/targets-parser').default
2020
const builtInTargets = getTargets(targets, {
2121
ignoreBrowserslistConfig,
@@ -116,6 +116,7 @@ module.exports = (context, options = {}) => {
116116
}
117117

118118
const envOptions = {
119+
corejs: 3,
119120
spec,
120121
loose,
121122
debug,
@@ -165,18 +166,18 @@ module.exports = (context, options = {}) => {
165166
absoluteRuntime
166167
}])
167168

168-
// use @babel/runtime-corejs2 so that helpers that need polyfillable APIs will reference core-js instead.
169+
// use @babel/runtime-corejs3 so that helpers that need polyfillable APIs will reference core-js instead.
169170
// if useBuiltIns is not set to 'usage', then it means users would take care of the polyfills on their own,
170-
// i.e., core-js is no longer needed.
171+
// i.e., core-js 3 is no longer needed.
171172
// this extra plugin can be removed once one of the two issues resolves:
172173
// https://github.com/babel/babel/issues/7597
173174
// https://github.com/babel/babel/issues/9903
174175
if (useBuiltIns === 'usage' && !process.env.VUE_CLI_MODERN_BUILD) {
175-
const runtimeCoreJs2Path = path.dirname(require.resolve('@babel/runtime-corejs2/package.json'))
176+
const runtimeCoreJs3Path = path.dirname(require.resolve('@babel/runtime-corejs3/package.json'))
176177
plugins.push([require('babel-plugin-module-resolver'), {
177178
alias: {
178-
'@babel/runtime': '@babel/runtime-corejs2',
179-
[runtimePath]: runtimeCoreJs2Path
179+
'@babel/runtime': '@babel/runtime-corejs3',
180+
[runtimePath]: runtimeCoreJs3Path
180181
}
181182
}])
182183
}

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@
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-
"babel-plugin-module-resolver": "3.2.0",
37-
"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"
3839
}
3940
}

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.7.0",
2323
"@vue/cli-service": "^3.7.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.7.0",
2323
"@vue/cli-service": "^3.7.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
@@ -71,6 +71,7 @@
7171
"@vue/eslint-config-standard": "^4.0.0",
7272
"@vue/ui": "^0.9.1",
7373
"ansi_up": "^3.0.0",
74+
"core-js": "^3.0.1",
7475
"cross-env": "^5.1.5",
7576
"eslint": "^5.16.0",
7677
"eslint-plugin-graphql": "^3.0.3",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy