Skip to content

Commit

Permalink
fix(@ngtools/webpack): don't invalidate cache after first run
Browse files Browse the repository at this point in the history
At the moment, since there are no old files in the compilation it will cause all source files to be invalidate after the first run. This shouldn't be done as it will slow down the 2nd recompilation.
  • Loading branch information
Alan authored and mgechev committed Mar 29, 2019
1 parent 27a84a8 commit 54d2be9
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions packages/ngtools/webpack/src/angular_compiler_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,7 @@ export class AngularCompilerPlugin {

// Use an identity function as all our paths are absolute already.
this._moduleResolutionCache = ts.createModuleResolutionCache(this._basePath, x => x);

const tsProgram = this._getTsProgram();
const oldFiles = new Set(tsProgram ?
tsProgram.getSourceFiles().map(sf => sf.fileName)
: [],
);
const oldTsProgram = this._getTsProgram();

if (this._JitMode) {
// Create the TypeScript program.
Expand All @@ -414,14 +409,9 @@ export class AngularCompilerPlugin {
this._rootNames,
this._compilerOptions,
this._compilerHost,
tsProgram,
oldTsProgram,
);
timeEnd('AngularCompilerPlugin._createOrUpdateProgram.ts.createProgram');

const newFiles = this._program.getSourceFiles().filter(sf => !oldFiles.has(sf.fileName));
for (const newFile of newFiles) {
this._compilerHost.invalidate(newFile.fileName);
}
} else {
time('AngularCompilerPlugin._createOrUpdateProgram.ng.createProgram');
// Create the Angular program.
Expand All @@ -436,9 +426,14 @@ export class AngularCompilerPlugin {
time('AngularCompilerPlugin._createOrUpdateProgram.ng.loadNgStructureAsync');
await this._program.loadNgStructureAsync();
timeEnd('AngularCompilerPlugin._createOrUpdateProgram.ng.loadNgStructureAsync');
}

const newFiles = this._program.getTsProgram()
.getSourceFiles().filter(sf => !oldFiles.has(sf.fileName));
const newTsProgram = this._getTsProgram();
if (oldTsProgram && newTsProgram) {
// The invalidation should only happen if we have an old program
// as otherwise we will invalidate all the sourcefiles.
const oldFiles = new Set(oldTsProgram.getSourceFiles().map(sf => sf.fileName));
const newFiles = newTsProgram.getSourceFiles().filter(sf => !oldFiles.has(sf.fileName));
for (const newFile of newFiles) {
this._compilerHost.invalidate(newFile.fileName);
}
Expand Down Expand Up @@ -1056,7 +1051,8 @@ export class AngularCompilerPlugin {
// We also need to all changed files as dependencies of this file, so that all of them
// will be watched and trigger a rebuild next time.
outputText = '';
errorDependencies = this._getChangedCompilationFiles()
const program = this._getTsProgram();
errorDependencies = (program ? program.getSourceFiles().map(x => x.fileName) : [])
// These paths are used by the loader so we must denormalize them.
.map((p) => this._compilerHost.denormalizePath(p));
}
Expand Down

0 comments on commit 54d2be9

Please sign in to comment.