Skip to content

Commit dea0118

Browse files
committed
refactor(@ngtools/webpack): simplify changed file handling
1 parent 6038efb commit dea0118

File tree

1 file changed

+17
-28
lines changed

1 file changed

+17
-28
lines changed

packages/ngtools/webpack/src/angular_compiler_plugin.ts

+17-28
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ export class AngularCompilerPlugin {
850850

851851
// If nothing we care about changed and it isn't the first run, don't do anything.
852852
if (changedFiles.length === 0 && !this._firstRun) {
853-
return Promise.resolve();
853+
return;
854854
}
855855

856856
// Make a new program and load the Angular structure.
@@ -876,24 +876,9 @@ export class AngularCompilerPlugin {
876876
}
877877
}
878878

879-
// Emit and report errors.
880-
881-
// We now have the final list of changed TS files.
882-
// Go through each changed file and add transforms as needed.
883-
const sourceFiles = this._getChangedTsFiles()
884-
.map((fileName) => (this._getTsProgram() as ts.Program).getSourceFile(fileName))
885-
// At this point we shouldn't need to filter out undefined files, because any ts file
886-
// that changed should be emitted.
887-
// But due to hostReplacementPaths there can be files (the environment files)
888-
// that changed but aren't part of the compilation, specially on `ng test`.
889-
// So we ignore missing source files files here.
890-
// hostReplacementPaths needs to be fixed anyway to take care of the following issue.
891-
// https://github.com/angular/angular-cli/issues/7305#issuecomment-332150230
892-
.filter((x) => !!x) as ts.SourceFile[];
893-
894879
// Emit files.
895880
time('AngularCompilerPlugin._update._emit');
896-
const { emitResult, diagnostics } = this._emit(sourceFiles);
881+
const { emitResult, diagnostics } = this._emit(changedFiles);
897882
timeEnd('AngularCompilerPlugin._update._emit');
898883

899884
// Report diagnostics.
@@ -1036,7 +1021,7 @@ export class AngularCompilerPlugin {
10361021
// This code mostly comes from `performCompilation` in `@angular/compiler-cli`.
10371022
// It skips the program creation because we need to use `loadNgStructureAsync()`,
10381023
// and uses CustomTransformers.
1039-
private _emit(sourceFiles: ts.SourceFile[]) {
1024+
private _emit(changedFiles: string[]) {
10401025
time('AngularCompilerPlugin._emit');
10411026
const program = this._program;
10421027
const allDiagnostics: Array<ts.Diagnostic | Diagnostic> = [];
@@ -1059,7 +1044,7 @@ export class AngularCompilerPlugin {
10591044
}
10601045

10611046
if (!hasErrors(allDiagnostics)) {
1062-
if (this._firstRun || sourceFiles.length > 20) {
1047+
if (this._firstRun) {
10631048
emitResult = tsProgram.emit(
10641049
undefined,
10651050
undefined,
@@ -1069,15 +1054,19 @@ export class AngularCompilerPlugin {
10691054
);
10701055
allDiagnostics.push(...emitResult.diagnostics);
10711056
} else {
1072-
sourceFiles.forEach((sf) => {
1073-
const timeLabel = `AngularCompilerPlugin._emit.ts+${sf.fileName}+.emit`;
1074-
time(timeLabel);
1075-
emitResult = tsProgram.emit(sf, undefined, undefined, undefined,
1076-
{ before: this._transformers },
1077-
);
1078-
allDiagnostics.push(...emitResult.diagnostics);
1079-
timeEnd(timeLabel);
1080-
});
1057+
for (const file of changedFiles) {
1058+
const sourceFile = tsProgram.getSourceFile(file);
1059+
1060+
if (sourceFile) {
1061+
const timeLabel = `AngularCompilerPlugin._emit.ts+${sourceFile.fileName}+.emit`;
1062+
time(timeLabel);
1063+
emitResult = tsProgram.emit(sourceFile, undefined, undefined, undefined,
1064+
{ before: this._transformers },
1065+
);
1066+
allDiagnostics.push(...emitResult.diagnostics);
1067+
timeEnd(timeLabel);
1068+
}
1069+
}
10811070
}
10821071
}
10831072
} else {

0 commit comments

Comments
 (0)