Skip to content

Commit

Permalink
Revert Node.js 20.6.0 bug workaround (#15965)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Sep 14, 2023
1 parent 04a4ee3 commit aac99cf
Showing 1 changed file with 0 additions and 51 deletions.
51 changes: 0 additions & 51 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,6 @@ module.exports = function (api) {
].map(normalize),
plugins: [pluginImportMetaUrl],
},
// See comment in the plugin
convertESM && {
test: [
"./packages/babel-core/src/index.ts",
"./packages/babel-types/src/index.ts",
"./packages/babel-traverse/src/index.ts",
],
plugins: [pluginInjectErrorBugNode_20_6_0],
},
{
test: sources.map(source => normalize(source.replace("/src", "/test"))),
plugins: [
Expand Down Expand Up @@ -963,45 +954,3 @@ function pluginReplaceNavigator({ template }) {
},
};
}

// Workaround for https://github.com/nodejs/node/issues/49497, since
// Node.js is taking ages to release the fix.
// This bug only affects CJS packages that are imported from ESM. We only apply
// it to packages that have cycles in their entrypoint. They can be easily
// caught by our CI in ESM mode on Node.js 20.6.0:
// - @babel/core
// - @babel/types
// - @babel/traverse
//
// We will remove this workaround after one week that Node.js 20.6.1 has been
// released, so that all CIs using `node:latest` will be using the new version.
function pluginInjectErrorBugNode_20_6_0({ template }) {
const flag = "___internal__alreadyRunning";

return {
post({ path }) {
path.unshiftContainer(
"body",
// We use `"${flag}" + ""` so that the Node.js ESM-CJS
// integration does not detect it as an export.
template.statement.ast`
if (typeof process === "object" && process.version === "v20.6.0") {
if (exports["${flag}" + ""]) return;
Object.defineProperty(exports, "${flag}", {
value: true,
enumerable: false,
configurable: true,
});
}
`
);
path.pushContainer(
"body",
template.statement.ast`
if (typeof process === "object" && process.version === "v20.6.0")
delete exports["${flag}" + ""];
`
);
},
};
}

0 comments on commit aac99cf

Please sign in to comment.