Skip to content

Commit 3739bad

Browse files
filipesilvavikerman
authored andcommitted
fix(@ngtools/webpack): invalidate ngcc processor cache
Fix #16397
1 parent dc2d460 commit 3739bad

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

packages/ngtools/webpack/src/compiler_host.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Stats } from 'fs';
1010
import * as ts from 'typescript';
1111
import { NgccProcessor } from './ngcc_processor';
1212
import { WebpackResourceLoader } from './resource_loader';
13-
import { workaroundResolve } from './utils';
13+
import { forwardSlashPath, workaroundResolve } from './utils';
1414

1515
export interface OnErrorFn {
1616
(message: string): void;
@@ -101,6 +101,11 @@ export class WebpackCompilerHost implements ts.CompilerHost {
101101
const fullPath = this.resolve(fileName);
102102
this._sourceFileCache.delete(fullPath);
103103

104+
if (this.ngccProcessor) {
105+
// Delete the ngcc processor cache using the TS-format file names.
106+
this.ngccProcessor.invalidate(forwardSlashPath(fileName));
107+
}
108+
104109
let exists = false;
105110
try {
106111
exists = this._syncHost.isFile(fullPath);

packages/ngtools/webpack/src/ngcc_processor.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,16 @@ export class NgccProcessor {
5454
resolvedModule: ts.ResolvedModule | ts.ResolvedTypeReferenceDirective,
5555
): void {
5656
const resolvedFileName = resolvedModule.resolvedFileName;
57-
if (!resolvedFileName || moduleName.startsWith('.') || this._processedModules.has(moduleName)) {
57+
if (!resolvedFileName || moduleName.startsWith('.')
58+
|| this._processedModules.has(resolvedFileName)) {
5859
// Skip when module is unknown, relative or NGCC compiler is not found or already processed.
5960
return;
6061
}
6162

6263
const packageJsonPath = this.tryResolvePackage(moduleName, resolvedFileName);
6364
if (!packageJsonPath) {
6465
// add it to processed so the second time round we skip this.
65-
this._processedModules.add(moduleName);
66+
this._processedModules.add(resolvedFileName);
6667

6768
return;
6869
}
@@ -73,7 +74,7 @@ export class NgccProcessor {
7374
accessSync(packageJsonPath, constants.W_OK);
7475
} catch {
7576
// add it to processed so the second time round we skip this.
76-
this._processedModules.add(moduleName);
77+
this._processedModules.add(resolvedFileName);
7778

7879
return;
7980
}
@@ -97,7 +98,11 @@ export class NgccProcessor {
9798
// tslint:disable-next-line:no-any
9899
(this.inputFileSystem as any).purge(packageJsonPath);
99100

100-
this._processedModules.add(moduleName);
101+
this._processedModules.add(resolvedFileName);
102+
}
103+
104+
invalidate(fileName: string) {
105+
this._processedModules.delete(fileName);
101106
}
102107

103108
/**

0 commit comments

Comments
 (0)