@@ -10,7 +10,7 @@ import {
10
10
packageName as getPackageName ,
11
11
} from '@embroider/shared-internals' ;
12
12
import semver from 'semver' ;
13
- import type { TransformOptions } from '@babel/core' ;
13
+ import type { PluginItem , TransformOptions } from '@babel/core' ;
14
14
import { MacrosConfig } from '@embroider/macros/src/node' ;
15
15
import minimatch from 'minimatch' ;
16
16
import { stripQuery } from './util' ;
@@ -141,6 +141,19 @@ export default class Package {
141
141
this . _hasBabelDetails = true ;
142
142
}
143
143
144
+ // this is used for two things:
145
+ // - when interoperating with older versions of ember-auto-import, it's used
146
+ // to configure the parser that we use to analyze source code. The parser
147
+ // cares about the user's babel config so it will support all the same
148
+ // syntax. (Newer EAI versions don't need to do this because they use the
149
+ // faster analyzer that happens inside the existing babel parse.)
150
+ // - when transpiling parts of the app itself that are configured with
151
+ // allowAppImports. It would be surprising if these didn't get transpiled
152
+ // with the same babel config that the rest of the app is getting. There is,
153
+ // however, one exception: if the user has added
154
+ // ember-auto-import/babel-plugin to get dynamic import support, we need to
155
+ // remove that because inside the natively webpack-owned area it's not
156
+ // needed and would actually break dynamic imports.
144
157
get babelOptions ( ) : TransformOptions {
145
158
this . _ensureBabelDetails ( ) ;
146
159
return this . _babelOptions ;
@@ -187,7 +200,11 @@ export default class Package {
187
200
188
201
if ( babelOptions . plugins ) {
189
202
babelOptions . plugins = babelOptions . plugins . filter (
190
- ( p : any ) => ! p . _parallelBabel
203
+ // removing the weird "_parallelBabel" entry that's only used by
204
+ // broccoli-babel-transpiler and removing our own dynamic import babel
205
+ // plugin if it was added (because it's only correct to use it against
206
+ // the classic ember build, not the webpack-owned parts of the build.
207
+ ( p : any ) => ! p . _parallelBabel && ! isEAIBabelPlugin ( p )
191
208
) ;
192
209
}
193
210
@@ -674,3 +691,22 @@ function ensureTrailingSlash(url: string): string {
674
691
}
675
692
return url ;
676
693
}
694
+
695
+ function isEAIBabelPlugin ( item : PluginItem ) {
696
+ let pluginPath : string | undefined ;
697
+ if ( typeof item === 'string' ) {
698
+ pluginPath = item ;
699
+ } else if (
700
+ Array . isArray ( item ) &&
701
+ item . length > 0 &&
702
+ typeof item [ 0 ] === 'string'
703
+ ) {
704
+ pluginPath = item [ 0 ] ;
705
+ }
706
+
707
+ if ( pluginPath ) {
708
+ return / e m b e r - a u t o - i m p o r t [ \\ / ] b a b e l - p l u g i n / . test ( pluginPath ) ;
709
+ }
710
+
711
+ return ( item as any ) . baseDir ?.( ) === __dirname ;
712
+ }
0 commit comments