diff --git a/packages/hasher/src/FileHasher.ts b/packages/hasher/src/FileHasher.ts index 1f7ebc684..5ad41660b 100644 --- a/packages/hasher/src/FileHasher.ts +++ b/packages/hasher/src/FileHasher.ts @@ -94,7 +94,7 @@ export class FileHasher { const stats = stat(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) { @@ -107,12 +107,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 ?? ""; }