@@ -431,6 +431,28 @@ function _getResourcesUrls(refactor: TypeScriptFileRefactor): string[] {
431
431
}
432
432
433
433
434
+ function _getImports ( refactor : TypeScriptFileRefactor ,
435
+ compilerOptions : ts . CompilerOptions ,
436
+ host : ts . ModuleResolutionHost ,
437
+ cache : ts . ModuleResolutionCache ) : string [ ] {
438
+ const containingFile = refactor . fileName ;
439
+
440
+ return refactor . findAstNodes ( null , ts . SyntaxKind . ImportDeclaration , false )
441
+ . map ( ( clause : ts . ImportDeclaration ) => {
442
+ const moduleName = ( clause . moduleSpecifier as ts . StringLiteral ) . text ;
443
+ const resolved = ts . resolveModuleName (
444
+ moduleName , containingFile , compilerOptions , host , cache ) ;
445
+
446
+ if ( resolved . resolvedModule ) {
447
+ return resolved . resolvedModule . resolvedFileName ;
448
+ } else {
449
+ return null ;
450
+ }
451
+ } )
452
+ . filter ( x => x ) ;
453
+ }
454
+
455
+
434
456
/**
435
457
* Recursively calls diagnose on the plugins for all the reverse dependencies.
436
458
* @private
@@ -546,6 +568,7 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
546
568
. then ( ( ) => {
547
569
timeEnd ( timeLabel + '.ngcLoader.AngularCompilerPlugin' ) ;
548
570
const result = plugin . getFile ( sourceFileName ) ;
571
+ const dependencies = plugin . getDependencies ( sourceFileName ) ;
549
572
550
573
if ( result . sourceMap ) {
551
574
// Process sourcemaps for Webpack.
@@ -561,6 +584,8 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
561
584
if ( result . outputText === undefined ) {
562
585
throw new Error ( 'TypeScript compilation failed.' ) ;
563
586
}
587
+
588
+ dependencies . forEach ( dep => this . addDependency ( dep ) ) ;
564
589
cb ( null , result . outputText , result . sourceMap ) ;
565
590
} )
566
591
. catch ( err => {
@@ -577,6 +602,12 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
577
602
const refactor = new TypeScriptFileRefactor (
578
603
sourceFileName , plugin . compilerHost , plugin . program , source ) ;
579
604
605
+ // Force a few compiler options to make sure we get the result we want.
606
+ const compilerOptions : ts . CompilerOptions = Object . assign ( { } , plugin . compilerOptions , {
607
+ inlineSources : true ,
608
+ inlineSourceMap : false ,
609
+ sourceRoot : plugin . basePath
610
+ } ) ;
580
611
581
612
Promise . resolve ( )
582
613
. then ( ( ) => {
@@ -615,6 +646,8 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
615
646
_getResourcesUrls ( refactor ) . forEach ( ( url : string ) => {
616
647
this . addDependency ( path . resolve ( path . dirname ( sourceFileName ) , url ) ) ;
617
648
} ) ;
649
+ _getImports ( refactor , compilerOptions , plugin . compilerHost , plugin . moduleResolutionCache )
650
+ . forEach ( ( importString : string ) => this . addDependency ( importString ) ) ;
618
651
timeEnd ( timeLabel + '.ngcLoader.AotPlugin.addDependency' ) ;
619
652
} )
620
653
. then ( ( ) => {
@@ -642,13 +675,6 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
642
675
timeEnd ( timeLabel + '.ngcLoader.AotPlugin.getDiagnostics' ) ;
643
676
}
644
677
645
- // Force a few compiler options to make sure we get the result we want.
646
- const compilerOptions : ts . CompilerOptions = Object . assign ( { } , plugin . compilerOptions , {
647
- inlineSources : true ,
648
- inlineSourceMap : false ,
649
- sourceRoot : plugin . basePath
650
- } ) ;
651
-
652
678
time ( timeLabel + '.ngcLoader.AotPlugin.transpile' ) ;
653
679
const result = refactor . transpile ( compilerOptions ) ;
654
680
timeEnd ( timeLabel + '.ngcLoader.AotPlugin.transpile' ) ;
0 commit comments