Always load the CJS helpers when using require (#12865)

This commit is contained in:
Nicolò Ribaudo
2021-02-23 11:21:01 +01:00
committed by GitHub
parent f47737c31c
commit a2114d452c
4 changed files with 259 additions and 253 deletions

View File

@@ -139,17 +139,23 @@ function writeHelpers(runtimeName, { corejs } = {}) {
for (const helperName of helpers.list) {
const helperPath = path.join("helpers", helperName);
helperSubExports[`./${helperPath}`] = {
module: writeHelperFile(runtimeName, pkgDirname, helperPath, helperName, {
esm: true,
corejs,
}),
node: writeHelperFile(runtimeName, pkgDirname, helperPath, helperName, {
esm: false,
corejs,
}),
get default() {
return this.module;
get node() {
return this.require;
},
require: writeHelperFile(
runtimeName,
pkgDirname,
helperPath,
helperName,
{ esm: false, corejs }
),
default: writeHelperFile(
runtimeName,
pkgDirname,
helperPath,
helperName,
{ esm: true, corejs }
),
};
writeHelperLegacyESMFile(pkgDirname, helperName);
}