Skip to content

Commit 0af02c9

Browse files
committed
refactor(project): Fix cache invalidation tracking
1 parent 55afabe commit 0af02c9

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

packages/project/lib/build/cache/ProjectBuildCache.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,10 +815,10 @@ export default class ProjectBuildCache {
815815
// Source index is up-to-date, awaiting dependency indices validation
816816
// Status remains at initializing
817817
this.#cacheState = CACHE_STATES.INITIALIZING;
818+
this.#cachedSourceSignature = resourceIndex.getSignature();
818819
}
819820
this.#sourceIndex = resourceIndex;
820-
this.#cachedSourceSignature = resourceIndex.getSignature();
821-
this.#changedProjectSourcePaths = changedPaths;
821+
// Since all source files are part of the result, declare any detected changes as newly written resources
822822
this.#writtenResultResourcePaths = changedPaths;
823823
} else {
824824
// No index cache found, create new index
@@ -853,6 +853,7 @@ export default class ProjectBuildCache {
853853
log.verbose(`Source resource index for project ${this.#project.getName()} updated: ` +
854854
`${removed.length} removed, ${added.length} added, ${updated.length} updated resources.`);
855855
const changedPaths = [...removed, ...added, ...updated];
856+
// Since all source files are part of the result, declare any detected changes as newly written resources
856857
for (const resourcePath of changedPaths) {
857858
if (!this.#writtenResultResourcePaths.includes(resourcePath)) {
858859
this.#writtenResultResourcePaths.push(resourcePath);

packages/project/lib/build/cache/ResourceRequestManager.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,16 @@ class ResourceRequestManager {
244244
await resourceIndex.upsertResources(resourcesToUpdate);
245245
}
246246
}
247+
let hasChanges;
247248
if (this.#useDifferentialUpdate) {
248-
return await this.#flushTreeChangesWithDiffTracking();
249+
hasChanges = await this.#flushTreeChangesWithDiffTracking();
249250
} else {
250-
return await this.#flushTreeChangesWithoutDiffTracking();
251+
hasChanges = await this.#flushTreeChangesWithoutDiffTracking();
251252
}
253+
if (hasChanges) {
254+
this.#hasNewOrModifiedCacheEntries = true;
255+
}
256+
return hasChanges;
252257
}
253258

254259
/**
@@ -461,6 +466,9 @@ class ResourceRequestManager {
461466
* @returns {string} Special signature "X" indicating no requests
462467
*/
463468
recordNoRequests() {
469+
if (!this.#unusedAtLeastOnce) {
470+
this.#hasNewOrModifiedCacheEntries = true;
471+
}
464472
this.#unusedAtLeastOnce = true;
465473
return "X"; // Signature for when no requests were made
466474
}
@@ -477,6 +485,7 @@ class ResourceRequestManager {
477485
* @returns {Promise<object>} Object containing setId and signature of the resource index
478486
*/
479487
async #addRequestSet(requests, reader) {
488+
this.#hasNewOrModifiedCacheEntries = true;
480489
// Try to find an existing request set that we can reuse
481490
let setId = this.#requestGraph.findExactMatch(requests);
482491
let resourceIndex;

0 commit comments

Comments
 (0)