@@ -59,7 +59,6 @@ export interface AngularCompilerPluginOptions {
59
59
entryModule ?: string ;
60
60
mainPath ?: string ;
61
61
skipCodeGeneration ?: boolean ;
62
- hostOverrideFileSystem ?: { [ path : string ] : string } ;
63
62
hostReplacementPaths ?: { [ path : string ] : string } ;
64
63
i18nInFile ?: string ;
65
64
i18nInFormat ?: string ;
@@ -240,13 +239,6 @@ export class AngularCompilerPlugin implements Tapable {
240
239
tsHost : webpackCompilerHost
241
240
} ) as CompilerHost & WebpackCompilerHost ;
242
241
243
- // Override some files in the FileSystem.
244
- if ( this . _options . hostOverrideFileSystem ) {
245
- for ( const filePath of Object . keys ( this . _options . hostOverrideFileSystem ) ) {
246
- this . _compilerHost . writeFile ( filePath ,
247
- this . _options . hostOverrideFileSystem [ filePath ] , false ) ;
248
- }
249
- }
250
242
// Override some files in the FileSystem with paths from the actual file system.
251
243
if ( this . _options . hostReplacementPaths ) {
252
244
for ( const filePath of Object . keys ( this . _options . hostReplacementPaths ) ) {
@@ -645,9 +637,8 @@ export class AngularCompilerPlugin implements Tapable {
645
637
646
638
private _makeTransformers ( ) {
647
639
648
- // TODO use compilerhost.denormalize when #8210 is merged.
649
640
const isAppPath = ( fileName : string ) =>
650
- this . _rootNames . includes ( fileName . replace ( / \/ / g , path . sep ) ) ;
641
+ ! fileName . endsWith ( '.ngfactory.ts' ) && ! fileName . endsWith ( '.ngstyle.ts' ) ;
651
642
const isMainPath = ( fileName : string ) => fileName === this . _mainPath ;
652
643
const getEntryModule = ( ) => this . entryModule ;
653
644
const getLazyRoutes = ( ) => this . _lazyRoutes ;
@@ -693,34 +684,36 @@ export class AngularCompilerPlugin implements Tapable {
693
684
// Make a new program and load the Angular structure.
694
685
. then ( ( ) => this . _createOrUpdateProgram ( ) )
695
686
. then ( ( ) => {
696
- // Try to find lazy routes.
697
- // We need to run the `listLazyRoutes` the first time because it also navigates libraries
698
- // and other things that we might miss using the (faster) findLazyRoutesInAst.
699
- // Lazy routes modules will be read with compilerHost and added to the changed files.
700
- const changedTsFiles = this . _getChangedTsFiles ( ) ;
701
- if ( this . _ngCompilerSupportsNewApi ) {
702
- this . _processLazyRoutes ( this . _listLazyRoutesFromProgram ( ) ) ;
703
- } else if ( this . _firstRun ) {
704
- this . _processLazyRoutes ( this . _getLazyRoutesFromNgtools ( ) ) ;
705
- } else if ( changedTsFiles . length > 0 ) {
706
- this . _processLazyRoutes ( this . _findLazyRoutesInAst ( changedTsFiles ) ) ;
687
+ if ( this . entryModule ) {
688
+ // Try to find lazy routes if we have an entry module.
689
+ // We need to run the `listLazyRoutes` the first time because it also navigates libraries
690
+ // and other things that we might miss using the (faster) findLazyRoutesInAst.
691
+ // Lazy routes modules will be read with compilerHost and added to the changed files.
692
+ const changedTsFiles = this . _getChangedTsFiles ( ) ;
693
+ if ( this . _ngCompilerSupportsNewApi ) {
694
+ this . _processLazyRoutes ( this . _listLazyRoutesFromProgram ( ) ) ;
695
+ } else if ( this . _firstRun ) {
696
+ this . _processLazyRoutes ( this . _getLazyRoutesFromNgtools ( ) ) ;
697
+ } else if ( changedTsFiles . length > 0 ) {
698
+ this . _processLazyRoutes ( this . _findLazyRoutesInAst ( changedTsFiles ) ) ;
699
+ }
707
700
}
708
701
} )
709
702
. then ( ( ) => {
710
703
// Emit and report errors.
711
704
712
705
// We now have the final list of changed TS files.
713
706
// Go through each changed file and add transforms as needed.
714
- const sourceFiles = this . _getChangedTsFiles ( ) . map ( ( fileName ) => {
715
- time ( 'AngularCompilerPlugin._update .getSourceFile' ) ;
716
- const sourceFile = this . _getTsProgram ( ) . getSourceFile ( fileName ) ;
717
- if ( ! sourceFile ) {
718
- throw new Error ( ` ${ fileName } is not part of the TypeScript compilation. `
719
- + `Please include it in your tsconfig via the 'files' or 'include' property.` ) ;
720
- }
721
- timeEnd ( 'AngularCompilerPlugin._update.getSourceFile' ) ;
722
- return sourceFile ;
723
- } ) ;
707
+ const sourceFiles = this . _getChangedTsFiles ( )
708
+ . map ( ( fileName ) => this . _getTsProgram ( ) . getSourceFile ( fileName ) )
709
+ // At this point we shouldn't need to filter out undefined files, because any ts file
710
+ // that changed should be emitted.
711
+ // But due to hostReplacementPaths there can be files ( the environment files)
712
+ // that changed but aren't part of the compilation, specially on `ng test`.
713
+ // So we ignore missing source files files here.
714
+ // hostReplacementPaths needs to be fixed anyway to take care of the following issue.
715
+ // https://github.com/angular/angular-cli/issues/7305#issuecomment-332150230
716
+ . filter ( ( x ) => ! ! x ) ;
724
717
725
718
// Emit files.
726
719
time ( 'AngularCompilerPlugin._update._emit' ) ;
0 commit comments