@lawaty/lacode 0.1.7 → 0.1.9

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.
Files changed (2) hide show
  1. package/dist/index.js +37 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2163,6 +2163,7 @@ var INSTALL_TIMEOUT_MS = 12e4;
2163
2163
  var LOCK_STALE_MS = 10 * 60 * 1e3;
2164
2164
  var CHILD_ENV = "LACODE_SELFUPDATE_CHILD";
2165
2165
  var OPT_OUT_ENV = "LACODE_NO_SELFUPDATE";
2166
+ var inTestRunner = (env = process.env) => typeof env.NODE_TEST_CONTEXT === "string" && env.NODE_TEST_CONTEXT.length > 0;
2166
2167
  var STATE_DIR = join6(homedir2(), ".local", "share", "opencode", "lacode");
2167
2168
  var STATE_PATH = join6(STATE_DIR, "selfupdate.json");
2168
2169
  var LOCK_PATH = join6(STATE_DIR, "selfupdate.lock");
@@ -2244,9 +2245,16 @@ function writeState(state2, path4 = STATE_PATH) {
2244
2245
  }
2245
2246
  }
2246
2247
  var isDue = (state2, now, interval = CHECK_INTERVAL_MS) => typeof state2.checkedAt !== "number" || now - state2.checkedAt >= interval;
2247
- function acquireLock(path4 = LOCK_PATH, now = Date.now()) {
2248
+ var isProcessAlive = (pid) => {
2248
2249
  try {
2249
- mkdirSync2(dirname3(path4), { recursive: true });
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 = () => {
2250
2258
  const fd = openSync(path4, "wx");
2251
2259
  writeSync(fd, String(process.pid));
2252
2260
  closeSync(fd);
@@ -2256,12 +2264,36 @@ function acquireLock(path4 = LOCK_PATH, now = Date.now()) {
2256
2264
  } catch {
2257
2265
  }
2258
2266
  };
2267
+ };
2268
+ try {
2269
+ mkdirSync2(dirname3(path4), { recursive: true });
2270
+ return claim();
2259
2271
  } catch {
2272
+ let orphaned = false;
2260
2273
  try {
2261
- if (now - statSync3(path4).mtimeMs > LOCK_STALE_MS) unlinkSync2(path4);
2274
+ const pid = Number.parseInt(readFileSync4(path4, "utf8").trim(), 10);
2275
+ orphaned = !Number.isFinite(pid) || pid <= 0 || !isProcessAlive(pid);
2262
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;
2263
2296
  }
2264
- return void 0;
2265
2297
  }
2266
2298
  }
2267
2299
  async function checkForUpdate(opts) {
@@ -2329,7 +2361,7 @@ async function refreshCache(opts) {
2329
2361
  }
2330
2362
  async function maybeSelfUpdate(opts) {
2331
2363
  const env = opts.env ?? process.env;
2332
- if (opts.enabled === false || env[CHILD_ENV] === "1" || env[OPT_OUT_ENV] === "1") {
2364
+ if (opts.enabled === false || env[CHILD_ENV] === "1" || env[OPT_OUT_ENV] === "1" || inTestRunner(env)) {
2333
2365
  return { action: "disabled" };
2334
2366
  }
2335
2367
  const now = (opts.now ?? Date.now)();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lawaty/lacode",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Ultimate opencode setup for Go users — cost-controlled pooled subagents, hang recovery, and notifications for opencode.",
5
5
  "license": "MIT",
6
6
  "type": "module",