@@ -431,6 +431,28 @@ function _getResourcesUrls(refactor: TypeScriptFileRefactor): string[] {
431431}
432432
433433
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+
434456/**
435457 * Recursively calls diagnose on the plugins for all the reverse dependencies.
436458 * @private
@@ -546,6 +568,7 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
546568 . then ( ( ) => {
547569 timeEnd ( timeLabel + '.ngcLoader.AngularCompilerPlugin' ) ;
548570 const result = plugin . getFile ( sourceFileName ) ;
571+ const dependencies = plugin . getDependencies ( sourceFileName ) ;
549572
550573 if ( result . sourceMap ) {
551574 // Process sourcemaps for Webpack.
@@ -561,6 +584,8 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
561584 if ( result . outputText === undefined ) {
562585 throw new Error ( 'TypeScript compilation failed.' ) ;
563586 }
587+
588+ dependencies . forEach ( dep => this . addDependency ( dep ) ) ;
564589 cb ( null , result . outputText , result . sourceMap ) ;
565590 } )
566591 . catch ( err => {
@@ -577,6 +602,12 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
577602 const refactor = new TypeScriptFileRefactor (
578603 sourceFileName , plugin . compilerHost , plugin . program , source ) ;
579604
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+ } ) ;
580611
581612 Promise . resolve ( )
582613 . then ( ( ) => {
@@ -615,6 +646,8 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
615646 _getResourcesUrls ( refactor ) . forEach ( ( url : string ) => {
616647 this . addDependency ( path . resolve ( path . dirname ( sourceFileName ) , url ) ) ;
617648 } ) ;
649+ _getImports ( refactor , compilerOptions , plugin . compilerHost , plugin . moduleResolutionCache )
650+ . forEach ( ( importString : string ) => this . addDependency ( importString ) ) ;
618651 timeEnd ( timeLabel + '.ngcLoader.AotPlugin.addDependency' ) ;
619652 } )
620653 . then ( ( ) => {
@@ -642,13 +675,6 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
642675 timeEnd ( timeLabel + '.ngcLoader.AotPlugin.getDiagnostics' ) ;
643676 }
644677
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-
652678 time ( timeLabel + '.ngcLoader.AotPlugin.transpile' ) ;
653679 const result = refactor . transpile ( compilerOptions ) ;
654680 timeEnd ( timeLabel + '.ngcLoader.AotPlugin.transpile' ) ;
0 commit comments