Skip to content

Commit dbbcf5c

Browse files
alan-agius4clydin
authored andcommitted
fix(@ngtools/webpack): only track file dependencies
`fileDependencies` can contain directories and not just files which can cause incorrect cache invalidation on rebuilds. Example ``` '/Users/***/tailwindcss-angular12-replica/src/app/component19/component19.component.scss', '/Users/***/tailwindcss-angular12-replica/tailwind.config.js', '/var/folders/mp/zsgl3srd389_js72bk4_bkgh0000gn/T/tmp-19814-FDsnpPo5zlQK', '/Users/***/tailwindcss-angular12-replica/package.json', '/Users/***/tailwindcss-angular12-replica/src/app/component19', '/Users/***/tailwindcss-angular12-replica/src/app', '/Users/***/tailwindcss-angular12-replica/src', '/Users/***/tailwindcss-angular12-replica', '/Users/***', '/Users/****', '/Users', '/' ``` Closes #21228
1 parent 8383c6b commit dbbcf5c

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

packages/ngtools/webpack/src/resource_loader.ts

+30-25
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,42 @@ export class WebpackResourceLoader {
232232
const parent = childCompiler.parentCompilation;
233233
if (parent) {
234234
parent.children = parent.children.filter((child) => child !== childCompilation);
235+
let fileDependencies: Set<string> | undefined;
235236

236-
for (const fileDependency of childCompilation.fileDependencies) {
237-
if (data && containingFile && fileDependency.endsWith(entry)) {
237+
for (const dependency of childCompilation.fileDependencies) {
238+
// Skip paths that do not appear to be files (have no extension).
239+
// `fileDependencies` can contain directories and not just files which can
240+
// cause incorrect cache invalidation on rebuilds.
241+
if (!path.extname(dependency)) {
242+
continue;
243+
}
244+
245+
if (data && containingFile && dependency.endsWith(entry)) {
238246
// use containing file if the resource was inline
239247
parent.fileDependencies.add(containingFile);
240248
} else {
241-
parent.fileDependencies.add(fileDependency);
249+
parent.fileDependencies.add(dependency);
250+
}
251+
252+
// Save the dependencies for this resource.
253+
if (filePath) {
254+
const resolvedFile = normalizePath(dependency);
255+
const entry = this._reverseDependencies.get(resolvedFile);
256+
if (entry) {
257+
entry.add(filePath);
258+
} else {
259+
this._reverseDependencies.set(resolvedFile, new Set([filePath]));
260+
}
261+
262+
if (fileDependencies) {
263+
fileDependencies.add(dependency);
264+
} else {
265+
fileDependencies = new Set([dependency]);
266+
this._fileDependencies.set(filePath, fileDependencies);
267+
}
242268
}
243269
}
270+
244271
parent.contextDependencies.addAll(childCompilation.contextDependencies);
245272
parent.missingDependencies.addAll(childCompilation.missingDependencies);
246273
parent.buildDependencies.addAll(childCompilation.buildDependencies);
@@ -256,28 +283,6 @@ export class WebpackResourceLoader {
256283
}
257284
}
258285

259-
// Save the dependencies for this resource.
260-
if (filePath) {
261-
this._fileDependencies.set(filePath, new Set(childCompilation.fileDependencies));
262-
for (const file of childCompilation.fileDependencies) {
263-
const resolvedFile = normalizePath(file);
264-
265-
// Skip paths that do not appear to be files (have no extension).
266-
// `fileDependencies` can contain directories and not just files which can
267-
// cause incorrect cache invalidation on rebuilds.
268-
if (!path.extname(resolvedFile)) {
269-
continue;
270-
}
271-
272-
const entry = this._reverseDependencies.get(resolvedFile);
273-
if (entry) {
274-
entry.add(filePath);
275-
} else {
276-
this._reverseDependencies.set(resolvedFile, new Set([filePath]));
277-
}
278-
}
279-
}
280-
281286
resolve({
282287
content: finalContent ?? '',
283288
success: childCompilation.errors?.length === 0,

0 commit comments

Comments
 (0)