Skip to content

Commit e2d8276

Browse files
committed
fix(@ngtools/webpack): Fix cache invalidation error when watching
Update of #4009 by @rynclark to latest version of codebase. TypeScript caches the contents of source files within the program to minimize redundant compilation of non-changing code. This cache is not invalidated in @ngtools/webpack, causing two issues: 1. When the watcher is triggered, the old version of the source is used. A second save is necessary for changes to take effect. 2. When a change would result in a compilation error, the initial save will pass without errors. Subsequent saves, even saves containing fixes to the original error, will continue to fail with the original error. This is likely caused by TypeScript trying to compare any new programs against an invalid prior program state. Signed-off-by: RandomBK <[email protected]>
1 parent dbd71b7 commit e2d8276

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

packages/@ngtools/webpack/src/plugin.ts

+7
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,13 @@ export class AotPlugin implements Tapable {
388388
return;
389389
}
390390

391+
// Create a new Program before compiling to invalidate source
392+
// cache. Fixes error when watching for changes where the
393+
// pre-save version of the file is used.
394+
this._program = ts.createProgram(
395+
this._rootFilePath, this._compilerOptions, this._compilerHost, this._program
396+
);
397+
391398
// Create the Code Generator.
392399
return __NGTOOLS_PRIVATE_API_2.codeGen({
393400
basePath: this._basePath,

0 commit comments

Comments
 (0)