Skip to content

Commit b63fbd9

Browse files
committed
Collapse double statSync in FileEntryCache.reconcile
1 parent 25a7982 commit b63fbd9

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

packages/knip/src/util/file-entry-cache.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,20 @@ export class FileEntryCache<T> {
112112
}
113113

114114
reconcile() {
115-
this.removeNotFoundFiles();
116-
117115
for (const [entryName, cacheEntry] of this.normalizedEntries) {
118116
try {
119-
const meta = this._getMetaForFileUsingMtimeAndSize(cacheEntry);
117+
const stat = fs.statSync(entryName);
118+
const meta = Object.assign(cacheEntry.meta ?? {}, {
119+
size: stat.size,
120+
mtime: stat.mtime.getTime(),
121+
});
120122
this.cache.set(entryName, meta);
121123
} catch (error) {
122124
// @ts-expect-error
123-
if (error.code !== 'ENOENT') throw error;
125+
if (error.code === 'ENOENT') {
126+
this.normalizedEntries.delete(entryName);
127+
this.cache.delete(entryName);
128+
} else throw error;
124129
}
125130
}
126131

0 commit comments

Comments
 (0)