@t2code/cli 0.1.6-nightly.20261114.886 → 0.1.6-nightly.20261115.921

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/bin/t2code.mjs +31 -1
  2. package/package.json +2 -2
package/bin/t2code.mjs CHANGED
@@ -14,6 +14,8 @@ const { version } = JSON.parse(
14
14
  );
15
15
 
16
16
  const SUPPORTED = ["darwin-arm64", "linux-arm64", "linux-x64", "win32-arm64", "win32-x64"];
17
+ // Well inside launchd's 20 s ExitTimeOut, which SIGKILLs only the launcher and orphans the runtime.
18
+ const TERMINATE_GRACE_MS = 5_000;
17
19
 
18
20
  function t2Home() {
19
21
  const raw = (process.env.T2CODE_HOME || "").trim();
@@ -207,8 +209,13 @@ async function main() {
207
209
  child.on("message", (message) => process.connected && process.send(message));
208
210
  process.on("disconnect", () => child.connected && child.disconnect());
209
211
  }
212
+ let force;
210
213
  for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) {
211
- process.on(signal, () => (ipc || signal !== "SIGINT") && child.kill(signal));
214
+ process.on(signal, () => {
215
+ if (!ipc && signal === "SIGINT") return;
216
+ child.kill(signal);
217
+ force ??= setTimeout(() => killTree(child), TERMINATE_GRACE_MS).unref();
218
+ });
212
219
  }
213
220
  child.on("error", (error) => fail(executableError(key, error.message)));
214
221
  child.on("exit", (code, signal) =>
@@ -216,6 +223,29 @@ async function main() {
216
223
  );
217
224
  }
218
225
 
226
+ /** SIGKILL the runtime and its providers, which a runtime stuck on shutdown never stops. */
227
+ function killTree(child) {
228
+ const pids = [child.pid];
229
+ if (process.platform !== "win32") {
230
+ const table =
231
+ spawnSync("ps", ["-A", "-o", "pid=,ppid="], { encoding: "utf8", timeout: 2_000 }).stdout ||
232
+ "";
233
+ const rows = table
234
+ .trim()
235
+ .split("\n")
236
+ .map((line) => line.trim().split(/\s+/).map(Number));
237
+ for (let i = 0; i < pids.length; i++) {
238
+ for (const [pid, ppid] of rows) if (ppid === pids[i]) pids.push(pid);
239
+ }
240
+ }
241
+ for (const pid of pids.slice(1)) {
242
+ try {
243
+ process.kill(pid, "SIGKILL");
244
+ } catch {}
245
+ }
246
+ child.kill("SIGKILL");
247
+ }
248
+
219
249
  function executableError(key, detail) {
220
250
  return new Error(
221
251
  `could not run T2 Code ${version} for ${key}: ${detail}` +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t2code/cli",
3
- "version": "0.1.6-nightly.20261114.886",
3
+ "version": "0.1.6-nightly.20261115.921",
4
4
  "description": "T2 Code CLI. Downloads the self-contained executable for this platform from the GitHub Release.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -19,6 +19,6 @@
19
19
  "node": ">=20.11"
20
20
  },
21
21
  "t2code": {
22
- "databaseMigration": 82
22
+ "databaseMigration": 91
23
23
  }
24
24
  }