@kenkaiiii/gg-core 5.91.2 → 5.93.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1309,6 +1309,7 @@ var import_promises2 = require("timers/promises");
1309
1309
  var STALE_TIMEOUT_MS = 1e4;
1310
1310
  var RETRY_INTERVAL_MS = 50;
1311
1311
  var MAX_WAIT_MS = 5e3;
1312
+ var PENDING_DELETE_CODES = /* @__PURE__ */ new Set(["EACCES", "EBUSY", "EPERM"]);
1312
1313
  async function withFileLock(filePath, fn) {
1313
1314
  const lockPath = filePath + ".lock";
1314
1315
  await acquireLock(lockPath);
@@ -1320,13 +1321,22 @@ async function withFileLock(filePath, fn) {
1320
1321
  }
1321
1322
  async function acquireLock(lockPath) {
1322
1323
  const startTime = Date.now();
1324
+ let refusedWithoutLock = 0;
1323
1325
  while (true) {
1324
1326
  try {
1325
1327
  const info = { pid: process.pid, timestamp: Date.now() };
1326
1328
  await import_promises.default.writeFile(lockPath, JSON.stringify(info), { flag: "wx" });
1327
1329
  return;
1328
1330
  } catch (err) {
1329
- if (err.code !== "EEXIST") throw err;
1331
+ const code = err.code;
1332
+ if (code !== "EEXIST") {
1333
+ if (process.platform !== "win32" || !code || !PENDING_DELETE_CODES.has(code)) throw err;
1334
+ const lockPresent = await lockFileExists(lockPath);
1335
+ if (!lockPresent && ++refusedWithoutLock > 3) throw err;
1336
+ if (Date.now() - startTime > MAX_WAIT_MS) throw err;
1337
+ await (0, import_promises2.setTimeout)(RETRY_INTERVAL_MS);
1338
+ continue;
1339
+ }
1330
1340
  try {
1331
1341
  const content = await import_promises.default.readFile(lockPath, "utf-8");
1332
1342
  const info = JSON.parse(content);
@@ -1355,6 +1365,14 @@ async function acquireLock(lockPath) {
1355
1365
  }
1356
1366
  }
1357
1367
  }
1368
+ async function lockFileExists(lockPath) {
1369
+ try {
1370
+ await import_promises.default.stat(lockPath);
1371
+ return true;
1372
+ } catch (err) {
1373
+ return err.code !== "ENOENT";
1374
+ }
1375
+ }
1358
1376
  async function releaseLock(lockPath) {
1359
1377
  await import_promises.default.unlink(lockPath).catch(() => {
1360
1378
  });