diff --git a/babel.config.js b/babel.config.js index e8d5c00ccb49..46f77cd22add 100644 --- a/babel.config.js +++ b/babel.config.js @@ -154,44 +154,24 @@ module.exports = function(api) { return config; }; -// !!! WARNING !!! Hacks are coming - // import() uses file:// URLs for absolute imports, while require() uses // file paths. // Since this isn't handled by @babel/plugin-transform-modules-commonjs, // we must handle it here. -// However, fileURLToPath is only supported starting from Node.js 10. -// In older versions, we can remove the pathToFileURL call so that it keeps -// the original absolute path. // NOTE: This plugin must run before @babel/plugin-transform-modules-commonjs, // and assumes that the target is the current node version. function dynamicImportUrlToPath({ template }) { - const currentNodeSupportsURL = !!require("url").pathToFileURL; - - if (currentNodeSupportsURL) { - return { - visitor: { - CallExpression(path) { - if (path.get("callee").isImport()) { - path.get("arguments.0").replaceWith( - template.expression.ast` - require("url").fileURLToPath(${path.node.arguments[0]}) - ` - ); - } - }, - }, - }; - } else { - // TODO: Remove in Babel 8 (it's not needed when using Node 10) - return { - visitor: { - CallExpression(path) { - if (path.get("callee").isIdentifier({ name: "pathToFileURL" })) { - path.replaceWith(path.get("arguments.0")); - } - }, + return { + visitor: { + CallExpression(path) { + if (path.get("callee").isImport()) { + path.get("arguments.0").replaceWith( + template.expression.ast` + require("url").fileURLToPath(${path.node.arguments[0]}) + ` + ); + } }, - }; - } + }, + }; }