From 45a678166806da50a31985637f2383e4e285fe18 Mon Sep 17 00:00:00 2001 From: Elco Klingen Date: Thu, 12 Dec 2024 01:16:41 +0100 Subject: [PATCH] Fixed possible race condition in `fileHasChanged` function. --- CHANGELOG.md | 1 + index.js | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2c2fb7..90b7bd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog +v1.1.3 - Fixed possible race condition in `fileHasChanged` function. v1.1.2 - Some small changes for Windows compatibility v1.1.1 - Added `enableBypass` option to the constructor, to enable quick disabling of the whole caching mechanism. v1.1.0 - Addd `removeEntriesByKeys(...key)` function. diff --git a/index.js b/index.js index 7b9f531..f2174e8 100644 --- a/index.js +++ b/index.js @@ -107,12 +107,13 @@ export default class FileHashCache { return true } + const fileKey = relativePath(this.projectRoot, filepath) + const fileHash = await this.#getFileHash(filepath, encoding) + if (!this.hashCache[key]) { await this.load(key) } - const fileKey = relativePath(this.projectRoot, filepath) - const fileHash = await this.#getFileHash(filepath, encoding) const cachedHash = this.hashCache[key][fileKey] || '' const fileHasChanged = (fileHash !== cachedHash)