|
1 | 1 | import { memoize } from "lodash"; |
2 | 2 | import path from "node:path"; |
3 | | -import lockfile from "proper-lockfile"; |
4 | 3 | import { HashProvider } from "./hash-provider"; |
5 | 4 | import { getSelectivityHashesPath, readHashFileContents, shallowSortObject } from "./utils"; |
6 | 5 | import { writeJsonWithCompression } from "./json-utils"; |
@@ -138,44 +137,28 @@ export class HashWriter { |
138 | 137 | ...Object.values(this._stagedPatternHashes), |
139 | 138 | ]); |
140 | 139 |
|
141 | | - const releaseLock = await lockfile.lock(this._selectivityHashesPath, { |
142 | | - stale: 5000, |
143 | | - update: 1000, |
144 | | - retries: { minTimeout: 100, maxTimeout: 1000, retries: 15 }, |
145 | | - realpath: false, |
146 | | - }); |
147 | | - |
148 | | - try { |
149 | | - const existingHashesContent = await readHashFileContents(this._selectivityHashesPath, this._compresion); |
150 | | - |
151 | | - const [updatedModules, updatedFiles, updatedPatterns] = await Promise.all([ |
152 | | - filterMatchingHashes(stagedModuleNames, this._stagedModuleHashes, existingHashesContent.modules), |
153 | | - filterMatchingHashes(stagedFileNames, this._stagedFileHashes, existingHashesContent.files), |
154 | | - filterMatchingHashes(stagedPatternNames, this._stagedPatternHashes, existingHashesContent.patterns), |
155 | | - ]); |
156 | | - |
157 | | - if (!updatedFiles.length && !updatedModules.length && !updatedPatterns.length) { |
158 | | - await releaseLock(); |
159 | | - return; |
160 | | - } |
| 140 | + const existingHashesContent = await readHashFileContents(this._selectivityHashesPath, this._compresion); |
161 | 141 |
|
162 | | - await Promise.all([ |
163 | | - writeTo(updatedModules, this._stagedModuleHashes, existingHashesContent.modules), |
164 | | - writeTo(updatedFiles, this._stagedFileHashes, existingHashesContent.files), |
165 | | - writeTo(updatedPatterns, this._stagedPatternHashes, existingHashesContent.patterns), |
166 | | - ]); |
| 142 | + const [updatedModules, updatedFiles, updatedPatterns] = await Promise.all([ |
| 143 | + filterMatchingHashes(stagedModuleNames, this._stagedModuleHashes, existingHashesContent.modules), |
| 144 | + filterMatchingHashes(stagedFileNames, this._stagedFileHashes, existingHashesContent.files), |
| 145 | + filterMatchingHashes(stagedPatternNames, this._stagedPatternHashes, existingHashesContent.patterns), |
| 146 | + ]); |
167 | 147 |
|
168 | | - await writeJsonWithCompression(this._selectivityHashesPath, existingHashesContent, this._compresion); |
| 148 | + if (!updatedFiles.length && !updatedModules.length && !updatedPatterns.length) { |
| 149 | + return; |
| 150 | + } |
169 | 151 |
|
170 | | - await releaseLock(); |
| 152 | + await Promise.all([ |
| 153 | + writeTo(updatedModules, this._stagedModuleHashes, existingHashesContent.modules), |
| 154 | + writeTo(updatedFiles, this._stagedFileHashes, existingHashesContent.files), |
| 155 | + writeTo(updatedPatterns, this._stagedPatternHashes, existingHashesContent.patterns), |
| 156 | + ]); |
171 | 157 |
|
172 | | - markAsCommited(updatedModules, this._stagedModuleHashes); |
173 | | - markAsCommited(updatedFiles, this._stagedFileHashes); |
174 | | - } catch (err) { |
175 | | - await releaseLock(); |
| 158 | + await writeJsonWithCompression(this._selectivityHashesPath, existingHashesContent, this._compresion); |
176 | 159 |
|
177 | | - throw err; |
178 | | - } |
| 160 | + markAsCommited(updatedModules, this._stagedModuleHashes); |
| 161 | + markAsCommited(updatedFiles, this._stagedFileHashes); |
179 | 162 | } |
180 | 163 | } |
181 | 164 |
|
|
0 commit comments