@@ -424,6 +424,28 @@ function _getResourcesUrls(refactor: TypeScriptFileRefactor): string[] {
424
424
}
425
425
426
426
427
+ function _getImports ( refactor : TypeScriptFileRefactor ,
428
+ compilerOptions : ts . CompilerOptions ,
429
+ host : ts . ModuleResolutionHost ,
430
+ cache : ts . ModuleResolutionCache ) : string [ ] {
431
+ const containingFile = refactor . fileName ;
432
+
433
+ return refactor . findAstNodes ( null , ts . SyntaxKind . ImportDeclaration , false )
434
+ . map ( ( clause : ts . ImportDeclaration ) => {
435
+ const moduleName = ( clause . moduleSpecifier as ts . StringLiteral ) . text ;
436
+ const resolved = ts . resolveModuleName (
437
+ moduleName , containingFile , compilerOptions , host , cache ) ;
438
+
439
+ if ( resolved . resolvedModule ) {
440
+ return resolved . resolvedModule . resolvedFileName ;
441
+ } else {
442
+ return null ;
443
+ }
444
+ } )
445
+ . filter ( x => x ) ;
446
+ }
447
+
448
+
427
449
/**
428
450
* Recursively calls diagnose on the plugins for all the reverse dependencies.
429
451
* @private
@@ -539,6 +561,13 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
539
561
const refactor = new TypeScriptFileRefactor (
540
562
sourceFileName , plugin . compilerHost , plugin . program , source ) ;
541
563
564
+ // Force a few compiler options to make sure we get the result we want.
565
+ const compilerOptions : ts . CompilerOptions = Object . assign ( { } , plugin . compilerOptions , {
566
+ inlineSources : true ,
567
+ inlineSourceMap : false ,
568
+ sourceRoot : plugin . basePath
569
+ } ) ;
570
+
542
571
Promise . resolve ( )
543
572
. then ( ( ) => {
544
573
if ( ! plugin . skipCodeGeneration ) {
@@ -570,6 +599,8 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
570
599
_getResourcesUrls ( refactor ) . forEach ( ( url : string ) => {
571
600
this . addDependency ( path . resolve ( path . dirname ( sourceFileName ) , url ) ) ;
572
601
} ) ;
602
+ _getImports ( refactor , compilerOptions , plugin . compilerHost , plugin . moduleResolutionCache )
603
+ . forEach ( ( importString : string ) => this . addDependency ( importString ) ) ;
573
604
} )
574
605
. then ( ( ) => {
575
606
if ( source ) {
@@ -594,13 +625,6 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
594
625
}
595
626
}
596
627
597
- // Force a few compiler options to make sure we get the result we want.
598
- const compilerOptions : ts . CompilerOptions = Object . assign ( { } , plugin . compilerOptions , {
599
- inlineSources : true ,
600
- inlineSourceMap : false ,
601
- sourceRoot : plugin . basePath
602
- } ) ;
603
-
604
628
const result = refactor . transpile ( compilerOptions ) ;
605
629
606
630
if ( plugin . failedCompilation ) {
0 commit comments