Improve @babel/runtime esm stability (#12883)
This commit is contained in:
@@ -248,6 +248,7 @@ function buildHelper(
|
||||
[transformRuntime, { corejs, version: runtimeVersion }],
|
||||
buildRuntimeRewritePlugin(runtimeName, helperName),
|
||||
esm ? null : addDefaultCJSExport,
|
||||
esm ? useRelativeImports : null,
|
||||
].filter(Boolean),
|
||||
overrides: [
|
||||
{
|
||||
@@ -318,3 +319,18 @@ function addDefaultCJSExport({ template }) {
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function useRelativeImports() {
|
||||
const RE = /^@babel\/runtime(?:-corejs[23])?\/helpers\/(?<name>.+)$/;
|
||||
|
||||
return {
|
||||
visitor: {
|
||||
ImportDeclaration(path) {
|
||||
path.node.source.value = path.node.source.value.replace(
|
||||
RE,
|
||||
"../$<name>/_index.mjs"
|
||||
);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -88,13 +88,6 @@ export default declare((api, options, dirname) => {
|
||||
// TODO(Babel 8): Remove this check, it's always true
|
||||
const DUAL_MODE_RUNTIME = "7.13.0";
|
||||
const supportsCJSDefault = hasMinVersion(DUAL_MODE_RUNTIME, runtimeVersion);
|
||||
if (supportsCJSDefault && useESModules && !absoluteRuntime) {
|
||||
console.warn(
|
||||
`[@babel/plugin-transform-runtime] The 'useESModules' option is not necessary when using` +
|
||||
` a @babel/runtime version >= ${DUAL_MODE_RUNTIME} and not using the 'absoluteRuntime'` +
|
||||
` option, because it automatically detects the necessary module format.`,
|
||||
);
|
||||
}
|
||||
|
||||
function has(obj, key) {
|
||||
return Object.prototype.hasOwnProperty.call(obj, key);
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
[@babel/plugin-transform-runtime] The 'useESModules' option is not necessary when using a @babel/runtime version >= 7.13.0 and not using the 'absoluteRuntime' option, because it automatically detects the necessary module format.
|
||||
Reference in New Issue
Block a user