@lawaty/lacode 0.1.8 → 0.1.10
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.js +38 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2245,9 +2245,16 @@ function writeState(state2, path4 = STATE_PATH) {
|
|
|
2245
2245
|
}
|
|
2246
2246
|
}
|
|
2247
2247
|
var isDue = (state2, now, interval = CHECK_INTERVAL_MS) => typeof state2.checkedAt !== "number" || now - state2.checkedAt >= interval;
|
|
2248
|
-
|
|
2248
|
+
var isProcessAlive = (pid) => {
|
|
2249
2249
|
try {
|
|
2250
|
-
|
|
2250
|
+
process.kill(pid, 0);
|
|
2251
|
+
return true;
|
|
2252
|
+
} catch (error) {
|
|
2253
|
+
return error.code === "EPERM";
|
|
2254
|
+
}
|
|
2255
|
+
};
|
|
2256
|
+
function acquireLock(path4 = LOCK_PATH, now = Date.now()) {
|
|
2257
|
+
const claim = () => {
|
|
2251
2258
|
const fd = openSync(path4, "wx");
|
|
2252
2259
|
writeSync(fd, String(process.pid));
|
|
2253
2260
|
closeSync(fd);
|
|
@@ -2257,12 +2264,36 @@ function acquireLock(path4 = LOCK_PATH, now = Date.now()) {
|
|
|
2257
2264
|
} catch {
|
|
2258
2265
|
}
|
|
2259
2266
|
};
|
|
2267
|
+
};
|
|
2268
|
+
try {
|
|
2269
|
+
mkdirSync2(dirname3(path4), { recursive: true });
|
|
2270
|
+
return claim();
|
|
2260
2271
|
} catch {
|
|
2272
|
+
let orphaned = false;
|
|
2261
2273
|
try {
|
|
2262
|
-
|
|
2274
|
+
const pid = Number.parseInt(readFileSync4(path4, "utf8").trim(), 10);
|
|
2275
|
+
orphaned = !Number.isFinite(pid) || pid <= 0 || !isProcessAlive(pid);
|
|
2263
2276
|
} catch {
|
|
2277
|
+
orphaned = true;
|
|
2278
|
+
}
|
|
2279
|
+
if (!orphaned) {
|
|
2280
|
+
try {
|
|
2281
|
+
orphaned = now - statSync3(path4).mtimeMs > LOCK_STALE_MS;
|
|
2282
|
+
} catch {
|
|
2283
|
+
orphaned = true;
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
if (!orphaned) return void 0;
|
|
2287
|
+
try {
|
|
2288
|
+
unlinkSync2(path4);
|
|
2289
|
+
} catch {
|
|
2290
|
+
return void 0;
|
|
2291
|
+
}
|
|
2292
|
+
try {
|
|
2293
|
+
return claim();
|
|
2294
|
+
} catch {
|
|
2295
|
+
return void 0;
|
|
2264
2296
|
}
|
|
2265
|
-
return void 0;
|
|
2266
2297
|
}
|
|
2267
2298
|
}
|
|
2268
2299
|
async function checkForUpdate(opts) {
|
|
@@ -2379,8 +2410,9 @@ async function selfUpdateHooks(input, options) {
|
|
|
2379
2410
|
if (opts.enabled === false || opts.selfUpdate === false) return {};
|
|
2380
2411
|
const log = (level, message, extra) => input.client.app.log({ body: { service: "lacode", level, message, extra } }).catch(() => {
|
|
2381
2412
|
});
|
|
2382
|
-
void maybeSelfUpdate({ packageRoot: PACKAGE_ROOT, enabled: opts.enabled, log }).
|
|
2383
|
-
|
|
2413
|
+
void maybeSelfUpdate({ packageRoot: PACKAGE_ROOT, enabled: opts.enabled, log }).then((result) => {
|
|
2414
|
+
if (result.action !== "disabled") log("debug", `self-update check: ${JSON.stringify(result)}`);
|
|
2415
|
+
}).catch((error) => log("error", `self-update check threw: ${String(error)}`));
|
|
2384
2416
|
return {};
|
|
2385
2417
|
}
|
|
2386
2418
|
|
package/package.json
CHANGED