Skip to content

Commit 736a5f8

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 (cherry picked from commit dbbcf5c)
1 parent 9d48d69 commit 736a5f8

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
@@ -234,15 +234,42 @@ export class WebpackResourceLoader {
234234
const parent = childCompiler.parentCompilation;
235235
if (parent) {
236236
parent.children = parent.children.filter((child) => child !== childCompilation);
237+
let fileDependencies: Set<string> | undefined;
237238

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

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

0 commit comments

Comments
 (0)