@@ -314,6 +314,10 @@ export class AngularCompilerPlugin {
314
314
}
315
315
316
316
private _getTsProgram ( ) {
317
+ if ( ! this . _program ) {
318
+ return undefined ;
319
+ }
320
+
317
321
return this . _JitMode ? this . _program as ts . Program : ( this . _program as Program ) . getTsProgram ( ) ;
318
322
}
319
323
@@ -360,17 +364,28 @@ export class AngularCompilerPlugin {
360
364
// Use an identity function as all our paths are absolute already.
361
365
this . _moduleResolutionCache = ts . createModuleResolutionCache ( this . _basePath , x => x ) ;
362
366
367
+ const tsProgram = this . _getTsProgram ( ) ;
368
+ const oldFiles = new Set ( tsProgram ?
369
+ tsProgram . getSourceFiles ( ) . map ( sf => sf . fileName )
370
+ : [ ] ,
371
+ ) ;
372
+
363
373
if ( this . _JitMode ) {
364
374
// Create the TypeScript program.
365
375
time ( 'AngularCompilerPlugin._createOrUpdateProgram.ts.createProgram' ) ;
366
376
this . _program = ts . createProgram (
367
377
this . _rootNames ,
368
378
this . _compilerOptions ,
369
379
this . _compilerHost ,
370
- this . _program as ts . Program ,
380
+ tsProgram ,
371
381
) ;
372
382
timeEnd ( 'AngularCompilerPlugin._createOrUpdateProgram.ts.createProgram' ) ;
373
383
384
+ const newFiles = this . _program . getSourceFiles ( ) . filter ( sf => ! oldFiles . has ( sf . fileName ) ) ;
385
+ for ( const newFile of newFiles ) {
386
+ this . _compilerHost . invalidate ( newFile . fileName ) ;
387
+ }
388
+
374
389
return Promise . resolve ( ) ;
375
390
} else {
376
391
time ( 'AngularCompilerPlugin._createOrUpdateProgram.ng.createProgram' ) ;
@@ -388,6 +403,12 @@ export class AngularCompilerPlugin {
388
403
return this . _program . loadNgStructureAsync ( )
389
404
. then ( ( ) => {
390
405
timeEnd ( 'AngularCompilerPlugin._createOrUpdateProgram.ng.loadNgStructureAsync' ) ;
406
+
407
+ const newFiles = ( this . _program as Program ) . getTsProgram ( )
408
+ . getSourceFiles ( ) . filter ( sf => ! oldFiles . has ( sf . fileName ) ) ;
409
+ for ( const newFile of newFiles ) {
410
+ this . _compilerHost . invalidate ( newFile . fileName ) ;
411
+ }
391
412
} ) ;
392
413
}
393
414
} )
@@ -396,7 +417,7 @@ export class AngularCompilerPlugin {
396
417
if ( ! this . _entryModule && this . _mainPath ) {
397
418
time ( 'AngularCompilerPlugin._make.resolveEntryModuleFromMain' ) ;
398
419
this . _entryModule = resolveEntryModuleFromMain (
399
- this . _mainPath , this . _compilerHost , this . _getTsProgram ( ) ) ;
420
+ this . _mainPath , this . _compilerHost , this . _getTsProgram ( ) as ts . Program ) ;
400
421
timeEnd ( 'AngularCompilerPlugin._make.resolveEntryModuleFromMain' ) ;
401
422
}
402
423
} ) ;
@@ -621,7 +642,6 @@ export class AngularCompilerPlugin {
621
642
this . _basePath ,
622
643
host ,
623
644
) ;
624
- webpackCompilerHost . enableCaching ( ) ;
625
645
626
646
// Create and set a new WebpackResourceLoader.
627
647
this . _resourceLoader = new WebpackResourceLoader ( ) ;
@@ -811,7 +831,7 @@ export class AngularCompilerPlugin {
811
831
? { path : workaroundResolve ( this . entryModule . path ) , className : this . entryModule . className }
812
832
: this . entryModule ;
813
833
const getLazyRoutes = ( ) => this . _lazyRoutes ;
814
- const getTypeChecker = ( ) => this . _getTsProgram ( ) . getTypeChecker ( ) ;
834
+ const getTypeChecker = ( ) => ( this . _getTsProgram ( ) as ts . Program ) . getTypeChecker ( ) ;
815
835
816
836
if ( this . _JitMode ) {
817
837
// Replace resources in JIT.
@@ -868,13 +888,15 @@ export class AngularCompilerPlugin {
868
888
// We need to run the `listLazyRoutes` the first time because it also navigates libraries
869
889
// and other things that we might miss using the (faster) findLazyRoutesInAst.
870
890
// Lazy routes modules will be read with compilerHost and added to the changed files.
871
- const changedTsFiles = this . _getChangedTsFiles ( ) ;
872
891
if ( this . _ngCompilerSupportsNewApi ) {
873
892
this . _processLazyRoutes ( this . _listLazyRoutesFromProgram ( ) ) ;
874
893
} else if ( this . _firstRun ) {
875
894
this . _processLazyRoutes ( this . _getLazyRoutesFromNgtools ( ) ) ;
876
- } else if ( changedTsFiles . length > 0 ) {
877
- this . _processLazyRoutes ( this . _findLazyRoutesInAst ( changedTsFiles ) ) ;
895
+ } else {
896
+ const changedTsFiles = this . _getChangedTsFiles ( ) ;
897
+ if ( changedTsFiles . length > 0 ) {
898
+ this . _processLazyRoutes ( this . _findLazyRoutesInAst ( changedTsFiles ) ) ;
899
+ }
878
900
}
879
901
if ( this . _options . additionalLazyModules ) {
880
902
this . _processLazyRoutes ( this . _options . additionalLazyModules ) ;
@@ -887,7 +909,7 @@ export class AngularCompilerPlugin {
887
909
// We now have the final list of changed TS files.
888
910
// Go through each changed file and add transforms as needed.
889
911
const sourceFiles = this . _getChangedTsFiles ( )
890
- . map ( ( fileName ) => this . _getTsProgram ( ) . getSourceFile ( fileName ) )
912
+ . map ( ( fileName ) => ( this . _getTsProgram ( ) as ts . Program ) . getSourceFile ( fileName ) )
891
913
// At this point we shouldn't need to filter out undefined files, because any ts file
892
914
// that changed should be emitted.
893
915
// But due to hostReplacementPaths there can be files (the environment files)
@@ -973,7 +995,7 @@ export class AngularCompilerPlugin {
973
995
} else {
974
996
// Check if the TS input file and the JS output file exist.
975
997
if ( ( ( fileName . endsWith ( '.ts' ) || fileName . endsWith ( '.tsx' ) )
976
- && ! this . _compilerHost . fileExists ( fileName , false ) )
998
+ && ! this . _compilerHost . fileExists ( fileName ) )
977
999
|| ! this . _compilerHost . fileExists ( outputFile , false ) ) {
978
1000
let msg = `${ fileName } is missing from the TypeScript compilation. `
979
1001
+ `Please make sure it is in your tsconfig via the 'files' or 'include' property.` ;
@@ -1066,15 +1088,26 @@ export class AngularCompilerPlugin {
1066
1088
}
1067
1089
1068
1090
if ( ! hasErrors ( allDiagnostics ) ) {
1069
- sourceFiles . forEach ( ( sf ) => {
1070
- const timeLabel = `AngularCompilerPlugin._emit.ts+${ sf . fileName } +.emit` ;
1071
- time ( timeLabel ) ;
1072
- emitResult = tsProgram . emit ( sf , undefined , undefined , undefined ,
1091
+ if ( this . _firstRun || sourceFiles . length > 20 ) {
1092
+ emitResult = tsProgram . emit (
1093
+ undefined ,
1094
+ undefined ,
1095
+ undefined ,
1096
+ undefined ,
1073
1097
{ before : this . _transformers } ,
1074
1098
) ;
1075
1099
allDiagnostics . push ( ...emitResult . diagnostics ) ;
1076
- timeEnd ( timeLabel ) ;
1077
- } ) ;
1100
+ } else {
1101
+ sourceFiles . forEach ( ( sf ) => {
1102
+ const timeLabel = `AngularCompilerPlugin._emit.ts+${ sf . fileName } +.emit` ;
1103
+ time ( timeLabel ) ;
1104
+ emitResult = tsProgram . emit ( sf , undefined , undefined , undefined ,
1105
+ { before : this . _transformers } ,
1106
+ ) ;
1107
+ allDiagnostics . push ( ...emitResult . diagnostics ) ;
1108
+ timeEnd ( timeLabel ) ;
1109
+ } ) ;
1110
+ }
1078
1111
}
1079
1112
} else {
1080
1113
const angularProgram = program as Program ;
0 commit comments