@bom0792/herdgate 0.9.27 → 0.9.28

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/bin/herdgate.mjs CHANGED
@@ -13,6 +13,7 @@ import { fileURLToPath } from "node:url";
13
13
  import { manageCloud, resolveCloud } from "./cloud-config.mjs";
14
14
  import { readConfig } from "../plugin/server/common.mjs";
15
15
  import { withLatest } from "../windows/npm-update.mjs";
16
+ import { windowsNode } from "../windows/node-runtime.mjs";
16
17
 
17
18
  const HERE = dirname(fileURLToPath(import.meta.url)); // <pkg>/bin
18
19
  const ROOT = dirname(HERE); // <pkg>
@@ -348,7 +349,15 @@ try {
348
349
  if (cmd === "setup-host") setupHost();
349
350
  else if (cmd === "cloud") manageCloud(args);
350
351
  else if (cmd === "pair") pairHost(args);
351
- else if (["setup", "migrate", "start", "stop", "status", "update"].includes(cmd)) managePublisher(cmd, args);
352
+ else if (process.platform === "win32" && (
353
+ ["setup", "migrate", "start", "update", "install-tui"].includes(cmd) ||
354
+ (cmd === "tui" && ["setup", "migrate", "start", "update"].includes(args[0]))
355
+ ) && (Number(process.versions.node.split(".")[0]) < 22 || typeof globalThis.WebSocket !== "function")) {
356
+ const node = windowsNode();
357
+ const r = spawnSync(node, [fileURLToPath(import.meta.url), cmd, ...args], { stdio: "inherit", shell: false, windowsHide: true });
358
+ if (r.error) throw r.error;
359
+ process.exitCode = r.status ?? 1;
360
+ } else if (["setup", "migrate", "start", "stop", "status", "update"].includes(cmd)) managePublisher(cmd, args);
352
361
  else if (cmd === "home-tui") runNode(join(HERE, "home-tui.mjs"), args);
353
362
  else if (cmd === "install-tui") runNode(join(ROOT, "windows", "install-cli.mjs"), args);
354
363
  else if (cmd === "tui") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bom0792/herdgate",
3
- "version": "0.9.27",
3
+ "version": "0.9.28",
4
4
  "description": "Cloud relay hub for herdr-core: every machine dials out, phones and browsers follow (PWA + SSH leg, E2E payloads).",
5
5
  "type": "module",
6
6
  "engines": {
@@ -0,0 +1,26 @@
1
+ // An npm-launched CLI can be running under a different Node from npm itself.
2
+ import { spawnSync } from 'node:child_process';
3
+ import { isAbsolute, join } from 'node:path';
4
+
5
+ const major = (version) => Number(/^v?(\d+)\./.exec(version)?.[1] || 0);
6
+ const working = (version, webSocket) => major(version) >= 22 && webSocket;
7
+
8
+ /** Return an absolute alternate runtime, or null when the current runtime is usable. */
9
+ export function windowsNode({ version = process.version, webSocket = typeof globalThis.WebSocket === 'function', env = process.env } = {}) {
10
+ if (working(version, webSocket)) return null;
11
+ // Do not work around flags disabling WebSocket on an already compatible Node installation.
12
+ if (major(version) >= 22) throw new Error(`WebSocket is disabled or unavailable in Node ${version}; check NODE_OPTIONS and the Node installation`);
13
+ for (const base of new Set([env.ProgramW6432, env.ProgramFiles])) {
14
+ if (!base || !isAbsolute(base)) continue;
15
+ const candidate = join(base, 'nodejs', 'node.exe');
16
+ const result = spawnSync(candidate, ['-p', 'JSON.stringify([process.version,typeof(WebSocket)])'], {
17
+ cwd: join(base, 'nodejs'), env, encoding: 'utf8', windowsHide: true, shell: false, timeout: 3000,
18
+ });
19
+ if (result.status !== 0) continue;
20
+ try {
21
+ const [found, ws] = JSON.parse(result.stdout);
22
+ if (working(found, ws === 'function')) return candidate;
23
+ } catch { /* not a usable Node runtime */ }
24
+ }
25
+ throw new Error(`Herdgate was launched with Node ${String(version).replace(/^v/, '')}; install Node 22+ with WebSocket enabled or run the CLI directly with that Node`);
26
+ }