Skip to content

Commit 2627d52

Browse files
committed
refactor(project): Fix pattern matching and resource comparison
1 parent 10d61c5 commit 2627d52

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export default class BuildTaskCache {
188188
* @param {object} resource - Resource instance to check
189189
* @returns {Promise<boolean>} True if resource is in cache with matching content
190190
*/
191-
async hasResourceInReadCache(resource) {
191+
async matchResourceInReadCache(resource) {
192192
const cachedResource = this.#resourcesRead[resource.getPath()];
193193
if (!cachedResource) {
194194
return false;
@@ -206,7 +206,7 @@ export default class BuildTaskCache {
206206
* @param {object} resource - Resource instance to check
207207
* @returns {Promise<boolean>} True if resource is in cache with matching content
208208
*/
209-
async hasResourceInWriteCache(resource) {
209+
async matchResourceInWriteCache(resource) {
210210
const cachedResource = this.#resourcesWritten[resource.getPath()];
211211
if (!cachedResource) {
212212
return false;
@@ -223,7 +223,7 @@ export default class BuildTaskCache {
223223
if (pathsRead.includes(resourcePath)) {
224224
return true;
225225
}
226-
if (patterns.length && micromatch.isMatch(resourcePath, patterns)) {
226+
if (patterns.length && micromatch(resourcePath, patterns).length > 0) {
227227
return true;
228228
}
229229
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default class ProjectBuildCache {
8181
const changedPaths = new Set((await Promise.all(writtenResourcePaths
8282
.map(async (resourcePath) => {
8383
// Check whether resource content actually changed
84-
if (await taskCache.hasResourceInWriteCache(resourcesWritten[resourcePath])) {
84+
if (await taskCache.matchResourceInWriteCache(resourcesWritten[resourcePath])) {
8585
return undefined;
8686
}
8787
return resourcePath;
@@ -224,7 +224,7 @@ export default class ProjectBuildCache {
224224
if (!taskCache) {
225225
throw new Error(`Failed to validate changed resources for task ${taskName}: Task cache not found`);
226226
}
227-
if (await taskCache.hasResourceInReadCache(resource)) {
227+
if (await taskCache.matchResourceInReadCache(resource)) {
228228
log.verbose(`Resource content has not changed for task ${taskName}, ` +
229229
`removing ${resourcePath} from set of changed resource paths`);
230230
changedResourcePaths.delete(resourcePath);

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ export async function areResourcesEqual(resourceA, resourceB) {
2424
if (resourceA.getOriginalPath() !== resourceB.getOriginalPath()) {
2525
throw new Error("Cannot compare resources with different original paths");
2626
}
27-
if (resourceA.getLastModified() !== resourceB.getLastModified()) {
28-
return false;
27+
if (resourceA.getLastModified() === resourceB.getLastModified()) {
28+
return true;
29+
}
30+
if (await resourceA.getSize() === await resourceB.getSize()) {
31+
return true;
2932
}
30-
if (await resourceA.getSize() !== resourceB.getSize()) {
31-
return false;
33+
if (await resourceA.getIntegrity() === await resourceB.getIntegrity()) {
34+
return true;
3235
}
33-
// if (await resourceA.getString() === await resourceB.getString()) {
34-
// return true;
35-
// }
3636
return false;
3737
}
3838

0 commit comments

Comments
 (0)