Skip to content

Commit

Permalink
Ensure @babel/runtime-corejs3/core-js/*.js can be imported on Node.…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
JLHwung committed Oct 20, 2022
1 parent db2789f commit cbef14b
Show file tree
Hide file tree
Showing 10 changed files with 299 additions and 272 deletions.
69 changes: 42 additions & 27 deletions .github/workflows/ci.yml
Expand Up @@ -19,7 +19,8 @@ jobs:
- name: Use Node.js latest
uses: actions/setup-node@v3
with:
node-version: "*"
node-version: latest
check-latest: true
cache: "yarn"
- name: 'Check or update Yarn cache (fix w/ "yarn install")'
env:
Expand All @@ -38,7 +39,8 @@ jobs:
- name: Use Node.js latest
uses: actions/setup-node@v3
with:
node-version: "*"
node-version: latest
check-latest: true
cache: "yarn"
- name: 'Check for unmet constraints (fix w/ "yarn constraints --fix")'
run: |
Expand All @@ -60,7 +62,8 @@ jobs:
- name: Use Node.js latest
uses: actions/setup-node@v3
with:
node-version: 18
node-version: latest
check-latest: true
cache: "yarn"
- name: Generate coverage report
run: |
Expand All @@ -79,7 +82,8 @@ jobs:
- name: Use Node.js latest
uses: actions/setup-node@v3
with:
node-version: "*"
node-version: latest
check-latest: true
cache: "yarn"
- name: Use ESM and build
run: make use-esm
Expand All @@ -106,7 +110,8 @@ jobs:
- name: Use Node.js latest
uses: actions/setup-node@v3
with:
node-version: "*"
node-version: latest
check-latest: true
cache: "yarn"
- name: Build babel artifacts
run: |
Expand Down Expand Up @@ -142,7 +147,8 @@ jobs:
- name: Use Node.js latest
uses: actions/setup-node@v3
with:
node-version: "*"
node-version: latest
check-latest: true
cache: "yarn"
- name: Build babel artifacts
shell: bash
Expand All @@ -165,7 +171,8 @@ jobs:
- name: Use Node.js latest
uses: actions/setup-node@v3
with:
node-version: "*"
node-version: latest
check-latest: true
cache: "yarn"
- name: Install
run: yarn install
Expand All @@ -182,14 +189,15 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [16, 14, 12, 10, 8, 6]
node-version: [18, 16, 14, 12, 10, 8, 6]
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Use Node.js latest # Run yarn on latest node
uses: actions/setup-node@v3
with:
node-version: "*" # Build Babel on latest node LTS versions
node-version: latest
check-latest: true
cache: "yarn"
- name: Install
run: |
Expand Down Expand Up @@ -232,7 +240,7 @@ jobs:
if: matrix.node-version == '6' || matrix.node-version == '8' || matrix.node-version == '10'
uses: actions/setup-node@v3
with:
node-version: "*"
node-version: latest

build-babel8:
name: Build Babel 8 Artifacts for tests
Expand Down Expand Up @@ -315,7 +323,8 @@ jobs:
- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18
node-version: latest
check-latest: true
cache: "yarn"
- name: Install
run: yarn install
Expand All @@ -341,7 +350,8 @@ jobs:
- name: Use Node.js latest
uses: actions/setup-node@v3
with:
node-version: "*"
node-version: latest
check-latest: true
cache: "yarn"
- name: Install
run: yarn install
Expand All @@ -367,7 +377,8 @@ jobs:
- name: Use Node.js latest
uses: actions/setup-node@v3
with:
node-version: "*"
node-version: latest
check-latest: true
cache: "yarn"
# See https://github.com/babel/babel/pull/12906
- name: Support self-references on old Node.js
Expand Down Expand Up @@ -400,8 +411,8 @@ jobs:
run: yarn test:runtime:generate-absolute-runtime
- name: Test bundlers
run: yarn test:runtime:bundlers
- name: Test Node.js
run: yarn test:runtime:node
- name: Test Node.js latest
run: node test/runtime-integration/node.cjs
- name: Use Node.js 10
uses: actions/setup-node@v3
with:
Expand All @@ -413,55 +424,55 @@ jobs:
with:
node-version: "12.0" # quoted, otherwise it's just 13
- name: Test Node.js 12.0
run: yarn test:runtime:node
run: node test/runtime-integration/node.cjs
- name: Use Node.js 12.17
uses: actions/setup-node@v3
with:
node-version: 12.17
- name: Test Node.js 12.17
run: yarn test:runtime:node
run: node test/runtime-integration/node.cjs
- name: Use Node.js 13.0
uses: actions/setup-node@v3
with:
node-version: "13.0" # quoted, otherwise it's just 13
- name: Test Node.js 13.0
run: yarn test:runtime:node
run: node test/runtime-integration/node.cjs
- name: Use Node.js 13.2
uses: actions/setup-node@v3
with:
node-version: 13.2
- name: Test Node.js 13.2
run: yarn test:runtime:node
run: node test/runtime-integration/node.cjs
- name: Use Node.js 13.6
uses: actions/setup-node@v3
with:
node-version: 13.6
- name: Test Node.js 13.6
run: yarn test:runtime:node
run: node test/runtime-integration/node.cjs
- name: Use Node.js 13.7
uses: actions/setup-node@v3
with:
node-version: 13.7
- name: Test Node.js 13.7
run: yarn test:runtime:node
run: node test/runtime-integration/node.cjs
- name: Use Node.js 14.2
uses: actions/setup-node@v3
with:
node-version: 14.2
- name: Test Node.js 14.2
run: yarn test:runtime:node
run: node test/runtime-integration/node.cjs
- name: Use Node.js 16.5
uses: actions/setup-node@v3
with:
node-version: 16.5
- name: Test Node.js 16.5
run: yarn test:runtime:node
run: node test/runtime-integration/node.cjs
- name: Use Node.js 16.6
uses: actions/setup-node@v3
with:
node-version: 16.6
- name: Test Node.js 16.6
run: yarn test:runtime:node
run: node test/runtime-integration/node.cjs

eslint7-test:
name: Test @babel/eslint-* with ESLint 7.5.0
Expand All @@ -473,7 +484,8 @@ jobs:
- name: Use Node.js latest
uses: actions/setup-node@v3
with:
node-version: "*"
node-version: latest
check-latest: true
cache: "yarn"
- name: Install
run: yarn install
Expand All @@ -493,6 +505,9 @@ jobs:
uses: actions/checkout@v3
- name: Use Node.js latest
uses: actions/setup-node@v3
with:
node-version: latest
check-latest: true
- name: Checkout test runner
uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -527,8 +542,8 @@ jobs:
- name: Use Node.js latest
uses: actions/setup-node@v3
with:
node-version: "*"
cache: "yarn"
node-version: latest
check-latest: true
- name: Install
run: yarn install
- uses: actions/download-artifact@v3
Expand Down
4 changes: 4 additions & 0 deletions packages/babel-plugin-transform-runtime/scripts/build-dist.js
Expand Up @@ -101,7 +101,10 @@ function writeCorejsExports(pkgDirname, runtimeRoot, paths) {
const pkgJson = require(pkgJsonPath);
const exports = pkgJson.exports;
// Export `./core-js/` so `import "@babel/runtime-corejs3/core-js/some-feature.js"` works
// Node < 17
exports[`./${runtimeRoot}/`] = `./${runtimeRoot}/`;
// Node >= 17
exports[`./${runtimeRoot}/*.js`] = `./${runtimeRoot}/*.js`;
for (const corejsPath of paths) {
// Export `./core-js/some-feature` so `import "@babel/runtime-corejs3/core-js/some-feature"` also works
const corejsExportPath = `./${runtimeRoot}/${corejsPath}`;
Expand Down Expand Up @@ -188,6 +191,7 @@ function writeHelperExports(runtimeName, helperSubExports) {
// These patterns are deprecated, but since patterns
// containing * are not supported in every Node.js
// version we keep them for better compatibility.
// For node < 17
"./regenerator/": "./regenerator/",
};
const pkgDirname = getRuntimeRoot(runtimeName);
Expand Down
1 change: 1 addition & 0 deletions packages/babel-runtime-corejs2/package.json
Expand Up @@ -888,6 +888,7 @@
"./regenerator/*.js": "./regenerator/*.js",
"./regenerator/": "./regenerator/",
"./core-js/": "./core-js/",
"./core-js/*.js": "./core-js/*.js",
"./core-js/is-iterable": "./core-js/is-iterable.js",
"./core-js/get-iterator": "./core-js/get-iterator.js",
"./core-js/symbol/async-iterator": "./core-js/symbol/async-iterator.js",
Expand Down
2 changes: 2 additions & 0 deletions packages/babel-runtime-corejs3/package.json
Expand Up @@ -887,6 +887,7 @@
"./regenerator/*.js": "./regenerator/*.js",
"./regenerator/": "./regenerator/",
"./core-js-stable/": "./core-js-stable/",
"./core-js-stable/*.js": "./core-js-stable/*.js",
"./core-js-stable/map": "./core-js-stable/map.js",
"./core-js-stable/promise": "./core-js-stable/promise.js",
"./core-js-stable/set": "./core-js-stable/set.js",
Expand Down Expand Up @@ -1021,6 +1022,7 @@
"./core-js-stable/instance/trim-start": "./core-js-stable/instance/trim-start.js",
"./core-js-stable/instance/values": "./core-js-stable/instance/values.js",
"./core-js/": "./core-js/",
"./core-js/*.js": "./core-js/*.js",
"./core-js/is-iterable": "./core-js/is-iterable.js",
"./core-js/get-iterator": "./core-js/get-iterator.js",
"./core-js/get-iterator-method": "./core-js/get-iterator-method.js",
Expand Down
Expand Up @@ -5,6 +5,7 @@ module.exports = {
output: {
path: __dirname,
filename: "output-absolute.js",
hashFunction: "sha256",
},

devtool: false,
Expand Down
1 change: 1 addition & 0 deletions test/runtime-integration/webpack-3/webpack.config.js
Expand Up @@ -5,6 +5,7 @@ module.exports = {
output: {
path: __dirname,
filename: "output.js",
hashFunction: "sha256",
},

devtool: false,
Expand Down
Expand Up @@ -7,6 +7,7 @@ module.exports = {
output: {
path: __dirname,
filename: "output-absolute.js",
hashFunction: "sha256",
},

devtool: false,
Expand Down
1 change: 1 addition & 0 deletions test/runtime-integration/webpack-4/webpack.config.js
Expand Up @@ -7,6 +7,7 @@ module.exports = {
output: {
path: __dirname,
filename: "output.js",
hashFunction: "sha256",
},

devtool: false,
Expand Down
4 changes: 2 additions & 2 deletions test/runtime-integration/webpack-5/package.json
Expand Up @@ -4,8 +4,8 @@
"exports": "./index.js",
"devDependencies": {
"@babel/runtime": "workspace:^",
"webpack": "^5.24.1",
"webpack-cli": "^4.5.0"
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
},
"type": "commonjs"
}

0 comments on commit cbef14b

Please sign in to comment.