Skip to content

Commit

Permalink
Allow require() of runtime helpers in Node.js 13.2-13.6 (#12893)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Feb 25, 2021
1 parent 039eb27 commit bb558aa
Show file tree
Hide file tree
Showing 7 changed files with 516 additions and 502 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/ci.yml
Expand Up @@ -326,18 +326,18 @@ jobs:
node-version: "13.0" # quoted, otherwise it's just 13
- name: Test Node.js 13.0
run: yarn test:runtime:node
# - name: Use Node.js 13.2
# uses: actions/setup-node@v2-beta
# with:
# node-version: 13.2
# - name: Test Node.js 13.2
# run: yarn test:runtime:node
# - name: Use Node.js 13.6
# uses: actions/setup-node@v2-beta
# with:
# node-version: 13.6
# - name: Test Node.js 13.6
# run: yarn test:runtime:node
- name: Use Node.js 13.2
uses: actions/setup-node@v2-beta
with:
node-version: 13.2
- name: Test Node.js 13.2
run: yarn test:runtime:node
- name: Use Node.js 13.6
uses: actions/setup-node@v2-beta
with:
node-version: 13.6
- name: Test Node.js 13.6
run: yarn test:runtime:node
- name: Use Node.js 13.7
uses: actions/setup-node@v2-beta
with:
Expand Down
11 changes: 7 additions & 4 deletions packages/babel-plugin-transform-runtime/scripts/build-dist.js
Expand Up @@ -159,13 +159,16 @@ function writeHelpers(runtimeName, { corejs } = {}) {
// - Node.js >=13.7.0 and bundlers will succesfully load the first
// array entry:
// * Node.js will always load the CJS file
// * Bundlers when using require() will load the CJS file
// * Everything else will load the ESM file
// - Node.js <13.7.0 will fail resolving the first array entry, and will
// * Modern tools when using "import" will load the ESM file
// * Everything else (old tools, or requrie() in tools) will
// load the CJS file
// - Node.js 13.2-13.7 will ignore the "node" and "import" conditions,
// will fallback to "default" and load the CJS file
// - Node.js <13.2.0 will fail resolving the first array entry, and will
// fallback to the second entry (the CJS file)
// In Babel 8 we can simplify this.
helperSubExports[`./${helperPath}`] = [
{ node: cjs, require: cjs, default: esm },
{ node: cjs, import: esm, default: cjs },
cjs,
];
// For backward compatibility. We can remove this in Babel 8.
Expand Down

0 comments on commit bb558aa

Please sign in to comment.