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 = {}; const helperSubExports = {};
for (const helperName of helpers.list) { for (const helperName of helpers.list) {
const helperPath = path.join("helpers", helperName); const helperPath = path.join("helpers", helperName);
helperSubExports[`./${helperPath}`] = { const cjs = writeHelperFile(
get node() { runtimeName,
return this.require; pkgDirname,
}, helperPath,
require: writeHelperFile( helperName,
runtimeName, { esm: false, corejs }
pkgDirname, );
helperPath, const esm = writeHelperFile(
helperName, runtimeName,
{ esm: false, corejs } pkgDirname,
), helperPath,
default: writeHelperFile( helperName,
runtimeName, { esm: true, corejs }
pkgDirname, );
helperPath,
helperName, // Node.js versions >=13.0.0, <13.7.0 support the `exports` field but
{ esm: true, corejs } // 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); 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