Define fallback exports for @babel/runtime on old Node (#12877)

* Define fallback `exports` for `@babel/runtime` on old Node

* Update .github/workflows/ci.yml
This commit is contained in:
Nicolò Ribaudo 2021-02-23 18:32:48 +01:00 committed by GitHub
parent 4acb73449f
commit ac7ac540ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1975 additions and 1234 deletions

View File

@ -138,25 +138,37 @@ function writeHelpers(runtimeName, { corejs } = {}) {
const helperSubExports = {};
for (const helperName of helpers.list) {
const helperPath = path.join("helpers", helperName);
helperSubExports[`./${helperPath}`] = {
get node() {
return this.require;
},
require: writeHelperFile(
runtimeName,
pkgDirname,
helperPath,
helperName,
{ esm: false, corejs }
),
default: writeHelperFile(
runtimeName,
pkgDirname,
helperPath,
helperName,
{ esm: true, corejs }
),
};
const cjs = writeHelperFile(
runtimeName,
pkgDirname,
helperPath,
helperName,
{ esm: false, corejs }
);
const esm = writeHelperFile(
runtimeName,
pkgDirname,
helperPath,
helperName,
{ esm: true, corejs }
);
// Node.js versions >=13.0.0, <13.7.0 support the `exports` field but
// not conditional exports (`require`/`node`/`default`)
// We can specify exports with an array of fallbacks:
// - 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
// fallback to the second entry (the CJS file)
// In Babel 8 we can simplify this.
helperSubExports[`./${helperPath}`] = [
{ node: cjs, require: cjs, default: esm },
cjs,
];
writeHelperLegacyESMFile(pkgDirname, helperName);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff