@@ -165,9 +165,6 @@ module.exports = function (api) {
165165 [ "@babel/proposal-object-rest-spread" , { useBuiltIns : true } ] ,
166166
167167 convertESM ? "@babel/proposal-export-namespace-from" : null ,
168- convertESM
169- ? [ "@babel/transform-modules-commonjs" , { importInterop } ]
170- : null ,
171168 convertESM ? pluginImportMetaUrl : null ,
172169
173170 pluginPackageJsonMacro ,
@@ -202,7 +199,10 @@ module.exports = function (api) {
202199 ] . map ( normalize ) ,
203200 plugins : [
204201 // Explicitly use the lazy version of CommonJS modules.
205- [ "@babel/transform-modules-commonjs" , { importInterop, lazy : true } ] ,
202+ [
203+ "@babel/transform-modules-commonjs" ,
204+ { importInterop : importInteropSrc , lazy : true } ,
205+ ] ,
206206 ] ,
207207 } ,
208208 convertESM && {
@@ -215,6 +215,24 @@ module.exports = function (api) {
215215 assumptions : sourceAssumptions ,
216216 plugins : [ transformNamedBabelTypesImportToDestructuring ] ,
217217 } ,
218+ convertESM && {
219+ test : sources . map ( normalize ) ,
220+ plugins : [
221+ [
222+ "@babel/transform-modules-commonjs" ,
223+ { importInterop : importInteropSrc } ,
224+ ] ,
225+ ] ,
226+ } ,
227+ {
228+ test : sources . map ( source => normalize ( source . replace ( "/src" , "/test" ) ) ) ,
229+ plugins : [
230+ [
231+ "@babel/transform-modules-commonjs" ,
232+ { importInterop : importInteropTest } ,
233+ ] ,
234+ ] ,
235+ } ,
218236 {
219237 test : unambiguousSources . map ( normalize ) ,
220238 sourceType : "unambiguous" ,
@@ -244,7 +262,7 @@ const monorepoPackages = ["codemods", "eslint", "packages"]
244262 . reduce ( ( a , b ) => a . concat ( b ) )
245263 . map ( name => name . replace ( / ^ b a b e l - / , "@babel/" ) ) ;
246264
247- function importInterop ( source ) {
265+ function importInteropSrc ( source ) {
248266 if (
249267 // These internal files are "real CJS" (whose default export is
250268 // on module.exports) and not compiled ESM.
@@ -266,6 +284,22 @@ function importInterop(source) {
266284 return "node" ;
267285}
268286
287+ function importInteropTest ( source ) {
288+ // This file will soon have an esm entrypoint
289+ if ( source === "@babel/helper-plugin-test-runner" ) {
290+ return "none" ;
291+ }
292+ if (
293+ // non-test files
294+ ! source . startsWith ( "." ) ||
295+ // lib files
296+ / (?: \. \. \/ ) + (?: b a b e l - [ a - z - ] + \/ ) ? l i b / . test ( source )
297+ ) {
298+ return "node" ;
299+ }
300+ return "babel" ;
301+ }
302+
269303// env vars from the cli are always strings, so !!ENV_VAR returns true for "false"
270304function bool ( value ) {
271305 return value && value !== "false" && value !== "0" ;
0 commit comments