Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions change/change-501f9623-19ff-418f-b70c-61580dd1343c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"type": "patch",
"comment": "Defend against missing files in the hashing logic",
"packageName": "@lage-run/hasher",
"email": "dobes@formative.com",
"dependentChangeType": "patch"
}
]
}
26 changes: 19 additions & 7 deletions packages/hasher/src/FileHasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class FileHasher {
const stats = globStat(files, { cwd: this.options.root }) ?? {};

for (const file of files) {
const stat = stats[file];
const stat = stats[file] || { mtime: 0n, size: 0 };

const info = this.#store[file];
if (info && stat.mtime === info.mtime && stat.size == info.size) {
Expand All @@ -113,12 +113,24 @@ export class FileHasher {
const updatedHashes = fastHash(updatedFiles, { cwd: this.options.root, concurrency: 4 }) ?? {};

for (const [file, hash] of Object.entries(updatedHashes)) {
const stat = fs.statSync(path.join(this.options.root, file), { bigint: true });
this.#store[file] = {
mtime: stat.mtimeMs,
size: Number(stat.size),
hash: hash ?? "",
};
try {
const stat = fs.statSync(path.join(this.options.root, file), { bigint: true });
this.#store[file] = {
mtime: stat.mtimeMs,
size: Number(stat.size),
hash: hash ?? "",
};
} catch (e: any) {
if (e.code === "ENOENT") {
this.#store[file] = {
mtime: 0n,
size: 0,
hash: hash ?? "",
};
} else {
throw e;
}
}
hashes[file] = hash ?? "";
}

Expand Down
Loading