adhdev 0.9.13 → 0.9.14

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 CHANGED
@@ -37763,10 +37763,14 @@ var init_router = __esm({
37763
37763
  currentInstalled = parsed?.dependencies?.[pkgName]?.version || null;
37764
37764
  } catch {
37765
37765
  }
37766
- if (currentInstalled === latest) {
37766
+ const runningVersion = typeof this.deps.statusVersion === "string" ? this.deps.statusVersion.trim().replace(/^v/, "") : null;
37767
+ if (currentInstalled === latest && runningVersion === latest) {
37767
37768
  LOG.info("Upgrade", `Already on latest version v${latest}; skipping install`);
37768
37769
  return { success: true, upgraded: false, alreadyLatest: true, version: latest };
37769
37770
  }
37771
+ if (currentInstalled === latest && runningVersion && runningVersion !== latest) {
37772
+ LOG.info("Upgrade", `Installed package is v${latest}, but running daemon is v${runningVersion}; scheduling restart`);
37773
+ }
37770
37774
  spawnDetachedDaemonUpgradeHelper({
37771
37775
  packageName: pkgName,
37772
37776
  targetVersion: latest,
@@ -55416,21 +55420,65 @@ function isAdhdevProcess(pid) {
55416
55420
  return true;
55417
55421
  }
55418
55422
  }
55419
- function getDaemonPid(ref = {}) {
55420
- const pidFile = getDaemonPidFile(ref);
55423
+ function getDaemonHealthPid(ref = {}) {
55424
+ const port = resolveDaemonPort(ref);
55421
55425
  try {
55422
- if (!fs18.existsSync(pidFile)) return null;
55423
- const pid = parseInt(fs18.readFileSync(pidFile, "utf-8").trim(), 10);
55426
+ const { execFileSync: execFileSync4 } = require("child_process");
55427
+ const probe = `
55428
+ const http = require('http');
55429
+ const req = http.get('http://127.0.0.1:${port}/health', { timeout: 1500 }, (res) => {
55430
+ let body = '';
55431
+ res.setEncoding('utf8');
55432
+ res.on('data', (chunk) => { body += chunk; });
55433
+ res.on('end', () => {
55434
+ if (res.statusCode !== 200) return;
55435
+ try {
55436
+ const json = JSON.parse(body || '{}');
55437
+ if (Number.isFinite(json.pid)) process.stdout.write(String(json.pid));
55438
+ } catch {}
55439
+ });
55440
+ });
55441
+ req.on('error', () => {});
55442
+ req.on('timeout', () => { req.destroy(); });
55443
+ `;
55444
+ const result = execFileSync4(process.execPath, ["-e", probe], {
55445
+ encoding: "utf-8",
55446
+ timeout: 3e3,
55447
+ stdio: ["ignore", "pipe", "ignore"]
55448
+ }).trim();
55449
+ const pid = parseInt(result, 10);
55424
55450
  return Number.isFinite(pid) ? pid : null;
55425
55451
  } catch {
55426
55452
  return null;
55427
55453
  }
55428
55454
  }
55455
+ function getDaemonPid(ref = {}) {
55456
+ const pidFile = getDaemonPidFile(ref);
55457
+ try {
55458
+ if (fs18.existsSync(pidFile)) {
55459
+ const pid = parseInt(fs18.readFileSync(pidFile, "utf-8").trim(), 10);
55460
+ if (Number.isFinite(pid)) return pid;
55461
+ }
55462
+ } catch {
55463
+ }
55464
+ return getDaemonHealthPid(ref);
55465
+ }
55429
55466
  function stopDaemon(ref = {}) {
55430
55467
  const pidFile = getDaemonPidFile(ref);
55468
+ let pid = null;
55469
+ try {
55470
+ if (fs18.existsSync(pidFile)) {
55471
+ const pidFromFile = parseInt(fs18.readFileSync(pidFile, "utf-8").trim(), 10);
55472
+ if (Number.isFinite(pidFromFile)) pid = pidFromFile;
55473
+ }
55474
+ } catch {
55475
+ removeDaemonPid(ref);
55476
+ }
55477
+ if (pid === null) {
55478
+ pid = getDaemonHealthPid(ref);
55479
+ }
55480
+ if (pid === null) return false;
55431
55481
  try {
55432
- if (!fs18.existsSync(pidFile)) return false;
55433
- const pid = parseInt(fs18.readFileSync(pidFile, "utf-8").trim());
55434
55482
  process.kill(pid, "SIGTERM");
55435
55483
  removeDaemonPid(ref);
55436
55484
  return true;
@@ -55460,7 +55508,7 @@ var init_adhdev_daemon = __esm({
55460
55508
  init_version();
55461
55509
  init_src();
55462
55510
  init_runtime_defaults();
55463
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.13" });
55511
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.14" });
55464
55512
  AdhdevDaemon = class _AdhdevDaemon {
55465
55513
  localHttpServer = null;
55466
55514
  localWss = null;