Skip to content

Commit cbef14b

Browse files
authored
Ensure @babel/runtime-corejs3/core-js/*.js can be imported on Node.js 17+ (#15060)
* Add Node 19 test and build Babel on latest node * bump webpack 5 to latest version * test262 does not require yarn cache * use sha256 for webpack 3/4 config * fix: add * exports support for runtime-corejs * avoid invoking yarn for runtime integration tests * polish test title
1 parent db2789f commit cbef14b

10 files changed

Lines changed: 299 additions & 272 deletions

File tree

.github/workflows/ci.yml

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ jobs:
1919
- name: Use Node.js latest
2020
uses: actions/setup-node@v3
2121
with:
22-
node-version: "*"
22+
node-version: latest
23+
check-latest: true
2324
cache: "yarn"
2425
- name: 'Check or update Yarn cache (fix w/ "yarn install")'
2526
env:
@@ -38,7 +39,8 @@ jobs:
3839
- name: Use Node.js latest
3940
uses: actions/setup-node@v3
4041
with:
41-
node-version: "*"
42+
node-version: latest
43+
check-latest: true
4244
cache: "yarn"
4345
- name: 'Check for unmet constraints (fix w/ "yarn constraints --fix")'
4446
run: |
@@ -60,7 +62,8 @@ jobs:
6062
- name: Use Node.js latest
6163
uses: actions/setup-node@v3
6264
with:
63-
node-version: 18
65+
node-version: latest
66+
check-latest: true
6467
cache: "yarn"
6568
- name: Generate coverage report
6669
run: |
@@ -79,7 +82,8 @@ jobs:
7982
- name: Use Node.js latest
8083
uses: actions/setup-node@v3
8184
with:
82-
node-version: "*"
85+
node-version: latest
86+
check-latest: true
8387
cache: "yarn"
8488
- name: Use ESM and build
8589
run: make use-esm
@@ -106,7 +110,8 @@ jobs:
106110
- name: Use Node.js latest
107111
uses: actions/setup-node@v3
108112
with:
109-
node-version: "*"
113+
node-version: latest
114+
check-latest: true
110115
cache: "yarn"
111116
- name: Build babel artifacts
112117
run: |
@@ -142,7 +147,8 @@ jobs:
142147
- name: Use Node.js latest
143148
uses: actions/setup-node@v3
144149
with:
145-
node-version: "*"
150+
node-version: latest
151+
check-latest: true
146152
cache: "yarn"
147153
- name: Build babel artifacts
148154
shell: bash
@@ -165,7 +171,8 @@ jobs:
165171
- name: Use Node.js latest
166172
uses: actions/setup-node@v3
167173
with:
168-
node-version: "*"
174+
node-version: latest
175+
check-latest: true
169176
cache: "yarn"
170177
- name: Install
171178
run: yarn install
@@ -182,14 +189,15 @@ jobs:
182189
strategy:
183190
fail-fast: false
184191
matrix:
185-
node-version: [16, 14, 12, 10, 8, 6]
192+
node-version: [18, 16, 14, 12, 10, 8, 6]
186193
steps:
187194
- name: Checkout code
188195
uses: actions/checkout@v3
189196
- name: Use Node.js latest # Run yarn on latest node
190197
uses: actions/setup-node@v3
191198
with:
192-
node-version: "*" # Build Babel on latest node LTS versions
199+
node-version: latest
200+
check-latest: true
193201
cache: "yarn"
194202
- name: Install
195203
run: |
@@ -232,7 +240,7 @@ jobs:
232240
if: matrix.node-version == '6' || matrix.node-version == '8' || matrix.node-version == '10'
233241
uses: actions/setup-node@v3
234242
with:
235-
node-version: "*"
243+
node-version: latest
236244

237245
build-babel8:
238246
name: Build Babel 8 Artifacts for tests
@@ -315,7 +323,8 @@ jobs:
315323
- name: Use Node.js 18
316324
uses: actions/setup-node@v3
317325
with:
318-
node-version: 18
326+
node-version: latest
327+
check-latest: true
319328
cache: "yarn"
320329
- name: Install
321330
run: yarn install
@@ -341,7 +350,8 @@ jobs:
341350
- name: Use Node.js latest
342351
uses: actions/setup-node@v3
343352
with:
344-
node-version: "*"
353+
node-version: latest
354+
check-latest: true
345355
cache: "yarn"
346356
- name: Install
347357
run: yarn install
@@ -367,7 +377,8 @@ jobs:
367377
- name: Use Node.js latest
368378
uses: actions/setup-node@v3
369379
with:
370-
node-version: "*"
380+
node-version: latest
381+
check-latest: true
371382
cache: "yarn"
372383
# See https://github.com/babel/babel/pull/12906
373384
- name: Support self-references on old Node.js
@@ -400,8 +411,8 @@ jobs:
400411
run: yarn test:runtime:generate-absolute-runtime
401412
- name: Test bundlers
402413
run: yarn test:runtime:bundlers
403-
- name: Test Node.js
404-
run: yarn test:runtime:node
414+
- name: Test Node.js latest
415+
run: node test/runtime-integration/node.cjs
405416
- name: Use Node.js 10
406417
uses: actions/setup-node@v3
407418
with:
@@ -413,55 +424,55 @@ jobs:
413424
with:
414425
node-version: "12.0" # quoted, otherwise it's just 13
415426
- name: Test Node.js 12.0
416-
run: yarn test:runtime:node
427+
run: node test/runtime-integration/node.cjs
417428
- name: Use Node.js 12.17
418429
uses: actions/setup-node@v3
419430
with:
420431
node-version: 12.17
421432
- name: Test Node.js 12.17
422-
run: yarn test:runtime:node
433+
run: node test/runtime-integration/node.cjs
423434
- name: Use Node.js 13.0
424435
uses: actions/setup-node@v3
425436
with:
426437
node-version: "13.0" # quoted, otherwise it's just 13
427438
- name: Test Node.js 13.0
428-
run: yarn test:runtime:node
439+
run: node test/runtime-integration/node.cjs
429440
- name: Use Node.js 13.2
430441
uses: actions/setup-node@v3
431442
with:
432443
node-version: 13.2
433444
- name: Test Node.js 13.2
434-
run: yarn test:runtime:node
445+
run: node test/runtime-integration/node.cjs
435446
- name: Use Node.js 13.6
436447
uses: actions/setup-node@v3
437448
with:
438449
node-version: 13.6
439450
- name: Test Node.js 13.6
440-
run: yarn test:runtime:node
451+
run: node test/runtime-integration/node.cjs
441452
- name: Use Node.js 13.7
442453
uses: actions/setup-node@v3
443454
with:
444455
node-version: 13.7
445456
- name: Test Node.js 13.7
446-
run: yarn test:runtime:node
457+
run: node test/runtime-integration/node.cjs
447458
- name: Use Node.js 14.2
448459
uses: actions/setup-node@v3
449460
with:
450461
node-version: 14.2
451462
- name: Test Node.js 14.2
452-
run: yarn test:runtime:node
463+
run: node test/runtime-integration/node.cjs
453464
- name: Use Node.js 16.5
454465
uses: actions/setup-node@v3
455466
with:
456467
node-version: 16.5
457468
- name: Test Node.js 16.5
458-
run: yarn test:runtime:node
469+
run: node test/runtime-integration/node.cjs
459470
- name: Use Node.js 16.6
460471
uses: actions/setup-node@v3
461472
with:
462473
node-version: 16.6
463474
- name: Test Node.js 16.6
464-
run: yarn test:runtime:node
475+
run: node test/runtime-integration/node.cjs
465476

466477
eslint7-test:
467478
name: Test @babel/eslint-* with ESLint 7.5.0
@@ -473,7 +484,8 @@ jobs:
473484
- name: Use Node.js latest
474485
uses: actions/setup-node@v3
475486
with:
476-
node-version: "*"
487+
node-version: latest
488+
check-latest: true
477489
cache: "yarn"
478490
- name: Install
479491
run: yarn install
@@ -493,6 +505,9 @@ jobs:
493505
uses: actions/checkout@v3
494506
- name: Use Node.js latest
495507
uses: actions/setup-node@v3
508+
with:
509+
node-version: latest
510+
check-latest: true
496511
- name: Checkout test runner
497512
uses: actions/checkout@v3
498513
with:
@@ -527,8 +542,8 @@ jobs:
527542
- name: Use Node.js latest
528543
uses: actions/setup-node@v3
529544
with:
530-
node-version: "*"
531-
cache: "yarn"
545+
node-version: latest
546+
check-latest: true
532547
- name: Install
533548
run: yarn install
534549
- uses: actions/download-artifact@v3

packages/babel-plugin-transform-runtime/scripts/build-dist.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ function writeCorejsExports(pkgDirname, runtimeRoot, paths) {
101101
const pkgJson = require(pkgJsonPath);
102102
const exports = pkgJson.exports;
103103
// Export `./core-js/` so `import "@babel/runtime-corejs3/core-js/some-feature.js"` works
104+
// Node < 17
104105
exports[`./${runtimeRoot}/`] = `./${runtimeRoot}/`;
106+
// Node >= 17
107+
exports[`./${runtimeRoot}/*.js`] = `./${runtimeRoot}/*.js`;
105108
for (const corejsPath of paths) {
106109
// Export `./core-js/some-feature` so `import "@babel/runtime-corejs3/core-js/some-feature"` also works
107110
const corejsExportPath = `./${runtimeRoot}/${corejsPath}`;
@@ -188,6 +191,7 @@ function writeHelperExports(runtimeName, helperSubExports) {
188191
// These patterns are deprecated, but since patterns
189192
// containing * are not supported in every Node.js
190193
// version we keep them for better compatibility.
194+
// For node < 17
191195
"./regenerator/": "./regenerator/",
192196
};
193197
const pkgDirname = getRuntimeRoot(runtimeName);

packages/babel-runtime-corejs2/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,7 @@
888888
"./regenerator/*.js": "./regenerator/*.js",
889889
"./regenerator/": "./regenerator/",
890890
"./core-js/": "./core-js/",
891+
"./core-js/*.js": "./core-js/*.js",
891892
"./core-js/is-iterable": "./core-js/is-iterable.js",
892893
"./core-js/get-iterator": "./core-js/get-iterator.js",
893894
"./core-js/symbol/async-iterator": "./core-js/symbol/async-iterator.js",

packages/babel-runtime-corejs3/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,7 @@
887887
"./regenerator/*.js": "./regenerator/*.js",
888888
"./regenerator/": "./regenerator/",
889889
"./core-js-stable/": "./core-js-stable/",
890+
"./core-js-stable/*.js": "./core-js-stable/*.js",
890891
"./core-js-stable/map": "./core-js-stable/map.js",
891892
"./core-js-stable/promise": "./core-js-stable/promise.js",
892893
"./core-js-stable/set": "./core-js-stable/set.js",
@@ -1021,6 +1022,7 @@
10211022
"./core-js-stable/instance/trim-start": "./core-js-stable/instance/trim-start.js",
10221023
"./core-js-stable/instance/values": "./core-js-stable/instance/values.js",
10231024
"./core-js/": "./core-js/",
1025+
"./core-js/*.js": "./core-js/*.js",
10241026
"./core-js/is-iterable": "./core-js/is-iterable.js",
10251027
"./core-js/get-iterator": "./core-js/get-iterator.js",
10261028
"./core-js/get-iterator-method": "./core-js/get-iterator-method.js",

test/runtime-integration/webpack-3/webpack.absolute.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
output: {
66
path: __dirname,
77
filename: "output-absolute.js",
8+
hashFunction: "sha256",
89
},
910

1011
devtool: false,

test/runtime-integration/webpack-3/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
output: {
66
path: __dirname,
77
filename: "output.js",
8+
hashFunction: "sha256",
89
},
910

1011
devtool: false,

test/runtime-integration/webpack-4/webpack.absolute.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = {
77
output: {
88
path: __dirname,
99
filename: "output-absolute.js",
10+
hashFunction: "sha256",
1011
},
1112

1213
devtool: false,

test/runtime-integration/webpack-4/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = {
77
output: {
88
path: __dirname,
99
filename: "output.js",
10+
hashFunction: "sha256",
1011
},
1112

1213
devtool: false,

test/runtime-integration/webpack-5/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"exports": "./index.js",
55
"devDependencies": {
66
"@babel/runtime": "workspace:^",
7-
"webpack": "^5.24.1",
8-
"webpack-cli": "^4.5.0"
7+
"webpack": "^5.74.0",
8+
"webpack-cli": "^4.10.0"
99
},
1010
"type": "commonjs"
1111
}

0 commit comments

Comments
 (0)