@@ -555,21 +555,15 @@ export class AngularCompilerPlugin {
555
555
// Add lazy modules to the context module for @angular /core
556
556
compiler . hooks . contextModuleFactory . tap ( 'angular-compiler' , ( cmf : any ) => {
557
557
const angularCorePackagePath = require . resolve ( '@angular/core/package.json' ) ;
558
- const angularCorePackageJson = require ( angularCorePackagePath ) ;
559
- const angularCoreModulePath = path . resolve ( path . dirname ( angularCorePackagePath ) ,
560
- angularCorePackageJson [ 'module' ] ) ;
561
- // Pick the last part after the last node_modules instance. We do this to let people have
562
- // a linked @angular /core or cli which would not be under the same path as the project
563
- // being built.
564
- const angularCoreModuleDir = path . dirname ( angularCoreModulePath ) . split ( / n o d e _ m o d u l e s / ) . pop ( ) ;
565
-
566
- // Also support the es2015 in Angular versions that have it.
567
- let angularCoreEs2015Dir : string | undefined ;
568
- if ( angularCorePackageJson [ 'es2015' ] ) {
569
- const angularCoreEs2015Path = path . resolve ( path . dirname ( angularCorePackagePath ) ,
570
- angularCorePackageJson [ 'es2015' ] ) ;
571
- angularCoreEs2015Dir = path . dirname ( angularCoreEs2015Path ) . split ( / n o d e _ m o d u l e s / ) . pop ( ) ;
572
- }
558
+
559
+ // APFv6 does not have single FESM anymore. Instead of verifying if we're pointing to
560
+ // FESMs, we resolve the `@angular/core` path and verify that the path for the
561
+ // module starts with it.
562
+
563
+ // This may be slower but it will be compatible with both APF5, 6 and potential future
564
+ // versions (until the dynamic import appears outside of core I suppose).
565
+ // We resolve any symbolic links in order to get the real path that would be used in webpack.
566
+ const angularCoreDirname = fs . realpathSync ( path . dirname ( angularCorePackagePath ) ) ;
573
567
574
568
cmf . hooks . afterResolve . tapAsync ( 'angular-compiler' ,
575
569
( result : any , callback : ( err ?: any , request ?: any ) => void ) => {
@@ -578,8 +572,7 @@ export class AngularCompilerPlugin {
578
572
}
579
573
580
574
// Alter only request from Angular.
581
- if ( ! ( angularCoreModuleDir && result . resource . endsWith ( angularCoreModuleDir ) )
582
- && ! ( angularCoreEs2015Dir && result . resource . endsWith ( angularCoreEs2015Dir ) ) ) {
575
+ if ( ! result . resource . startsWith ( angularCoreDirname ) ) {
583
576
return callback ( null , result ) ;
584
577
}
585
578
0 commit comments