@@ -327,12 +327,6 @@ export class AngularCompilerPlugin {
327
327
return this . _JitMode ? this . _program as ts . Program : ( this . _program as Program ) . getTsProgram ( ) ;
328
328
}
329
329
330
- private _getChangedTsFiles ( ) {
331
- return this . _compilerHost . getChangedFilePaths ( )
332
- . filter ( k => ( k . endsWith ( '.ts' ) || k . endsWith ( '.tsx' ) ) && ! k . endsWith ( '.d.ts' ) )
333
- . filter ( k => this . _compilerHost . fileExists ( k ) ) ;
334
- }
335
-
336
330
updateChangedFileExtensions ( extension : string ) {
337
331
if ( extension ) {
338
332
this . _changedFileExtensions . add ( extension ) ;
@@ -873,35 +867,16 @@ export class AngularCompilerPlugin {
873
867
// Make a new program and load the Angular structure.
874
868
await this . _createOrUpdateProgram ( ) ;
875
869
876
- // Try to find lazy routes if we have an entry module.
877
- // We need to run the `listLazyRoutes` the first time because it also navigates libraries
878
- // and other things that we might miss using the (faster) findLazyRoutesInAst.
879
- // Lazy routes modules will be read with compilerHost and added to the changed files.
870
+ // Find lazy routes
880
871
const lazyRouteMap : LazyRouteMap = {
881
- ... ( this . _entryModule || ! this . _JitMode ? this . _listLazyRoutesFromProgram ( ) : { } ) ,
872
+ ...this . _listLazyRoutesFromProgram ( ) ,
882
873
...this . _options . additionalLazyModules ,
883
874
} ;
884
-
885
875
this . _processLazyRoutes ( lazyRouteMap ) ;
886
876
887
- // Emit and report errors.
888
-
889
- // We now have the final list of changed TS files.
890
- // Go through each changed file and add transforms as needed.
891
- const sourceFiles = this . _getChangedTsFiles ( )
892
- . map ( ( fileName ) => ( this . _getTsProgram ( ) as ts . Program ) . getSourceFile ( fileName ) )
893
- // At this point we shouldn't need to filter out undefined files, because any ts file
894
- // that changed should be emitted.
895
- // But due to hostReplacementPaths there can be files (the environment files)
896
- // that changed but aren't part of the compilation, specially on `ng test`.
897
- // So we ignore missing source files files here.
898
- // hostReplacementPaths needs to be fixed anyway to take care of the following issue.
899
- // https://github.com/angular/angular-cli/issues/7305#issuecomment-332150230
900
- . filter ( ( x ) => ! ! x ) as ts . SourceFile [ ] ;
901
-
902
877
// Emit files.
903
878
time ( 'AngularCompilerPlugin._update._emit' ) ;
904
- const { emitResult, diagnostics } = this . _emit ( sourceFiles ) ;
879
+ const { emitResult, diagnostics } = this . _emit ( ) ;
905
880
timeEnd ( 'AngularCompilerPlugin._update._emit' ) ;
906
881
907
882
// Report diagnostics.
@@ -1042,7 +1017,7 @@ export class AngularCompilerPlugin {
1042
1017
// This code mostly comes from `performCompilation` in `@angular/compiler-cli`.
1043
1018
// It skips the program creation because we need to use `loadNgStructureAsync()`,
1044
1019
// and uses CustomTransformers.
1045
- private _emit ( sourceFiles : ts . SourceFile [ ] ) {
1020
+ private _emit ( ) {
1046
1021
time ( 'AngularCompilerPlugin._emit' ) ;
1047
1022
const program = this . _program ;
1048
1023
const allDiagnostics : Array < ts . Diagnostic | Diagnostic > = [ ] ;
@@ -1053,19 +1028,33 @@ export class AngularCompilerPlugin {
1053
1028
try {
1054
1029
if ( this . _JitMode ) {
1055
1030
const tsProgram = program as ts . Program ;
1031
+ const changedTsFiles = new Set < string > ( ) ;
1056
1032
1057
1033
if ( this . _firstRun ) {
1058
1034
// Check parameter diagnostics.
1059
1035
time ( 'AngularCompilerPlugin._emit.ts.getOptionsDiagnostics' ) ;
1060
1036
allDiagnostics . push ( ...tsProgram . getOptionsDiagnostics ( ) ) ;
1061
1037
timeEnd ( 'AngularCompilerPlugin._emit.ts.getOptionsDiagnostics' ) ;
1038
+ } else {
1039
+ // generate a list of changed files for emit
1040
+ // not needed on first run since a full program emit is required
1041
+ for ( const changedFile of this . _compilerHost . getChangedFilePaths ( ) ) {
1042
+ if ( ! changedFile . endsWith ( '.ts' ) && ! changedFile . endsWith ( '.tsx' ) ) {
1043
+ continue ;
1044
+ }
1045
+ // existing type definitions are not emitted
1046
+ if ( changedFile . endsWith ( '.d.ts' ) ) {
1047
+ continue ;
1048
+ }
1049
+ changedTsFiles . add ( changedFile ) ;
1050
+ }
1062
1051
}
1063
1052
1064
1053
allDiagnostics . push ( ...gatherDiagnostics ( tsProgram , this . _JitMode ,
1065
1054
'AngularCompilerPlugin._emit.ts' , diagMode ) ) ;
1066
1055
1067
1056
if ( ! hasErrors ( allDiagnostics ) ) {
1068
- if ( this . _firstRun || sourceFiles . length > 20 ) {
1057
+ if ( this . _firstRun || changedTsFiles . size > 20 ) {
1069
1058
emitResult = tsProgram . emit (
1070
1059
undefined ,
1071
1060
undefined ,
@@ -1075,15 +1064,20 @@ export class AngularCompilerPlugin {
1075
1064
) ;
1076
1065
allDiagnostics . push ( ...emitResult . diagnostics ) ;
1077
1066
} else {
1078
- sourceFiles . forEach ( ( sf ) => {
1079
- const timeLabel = `AngularCompilerPlugin._emit.ts+${ sf . fileName } +.emit` ;
1067
+ for ( const changedFile of changedTsFiles ) {
1068
+ const sourceFile = tsProgram . getSourceFile ( changedFile ) ;
1069
+ if ( ! sourceFile ) {
1070
+ continue ;
1071
+ }
1072
+
1073
+ const timeLabel = `AngularCompilerPlugin._emit.ts+${ sourceFile . fileName } +.emit` ;
1080
1074
time ( timeLabel ) ;
1081
- emitResult = tsProgram . emit ( sf , undefined , undefined , undefined ,
1075
+ emitResult = tsProgram . emit ( sourceFile , undefined , undefined , undefined ,
1082
1076
{ before : this . _transformers } ,
1083
1077
) ;
1084
1078
allDiagnostics . push ( ...emitResult . diagnostics ) ;
1085
1079
timeEnd ( timeLabel ) ;
1086
- } ) ;
1080
+ }
1087
1081
}
1088
1082
}
1089
1083
} else {
0 commit comments