Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure @babel/runtime-corejs3/core-js/*.js can be imported on Node.js 17+ #15060

Merged
merged 7 commits into from Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ensures that setup-node will always fetch the latest node version instead of using a locally cached node version. https://github.com/actions/setup-node/blob/main/docs/advanced-usage.md#check-latest-version

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
Copy link
Contributor Author

@JLHwung JLHwung Oct 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The runtime integration test has been failing since Node.js 17+. However we didn't catch the error because previously setup-node used the latest cached node versions, i.e. Node 16.x.

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",
Copy link
Contributor Author

@JLHwung JLHwung Oct 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default hashFunction is md4, since webpack 5.61, webpack has included a wasm MD4 implementation so we don't have to specify an overkilling cryptographic hasher for webpack 5.

(I am confident that sha256 will outlive webpack 3 / 4)

},

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"
}