@trama-dev/cli 0.2.2 → 0.3.1

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 +38 -1
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -2,6 +2,38 @@
2
2
  import { readFileSync } from "node:fs";
3
3
  import { Command } from "commander";
4
4
  import { createProject, runProgram, updateProject, listProjects, showLogs, resolveProject, } from "@trama-dev/runtime/runner";
5
+ // The trama command is always a runner of its own, even when a program starts
6
+ // it: what it runs it runs here, and shows here. (Code that is part of a
7
+ // program asks that program's runner instead — see runProgram.) So it does not
8
+ // go by a bridge it may have inherited, and neither does anything it starts.
9
+ delete process.env.TRAMA_PORT;
10
+ delete process.env.TRAMA_INIT;
11
+ // What a signal means is for this command to say: the runtime listens for none
12
+ // (its watchdog cleans up after a process that simply dies). While a program
13
+ // is being run, a signal stops the run the way a run should be stopped — its
14
+ // program asked first, and waited for — and then this process goes the way the
15
+ // signal would have had it go. A second signal does not wait. Without this the
16
+ // command could not be stopped politely at all where it is process 1, as in a
17
+ // container: there the kernel only delivers signals a process handles.
18
+ const SIGNALS = { SIGINT: 2, SIGTERM: 15, SIGHUP: 1 };
19
+ const stopRun = new AbortController();
20
+ let running = false;
21
+ let received = null;
22
+ for (const name of Object.keys(SIGNALS)) {
23
+ process.on(name, () => {
24
+ if (!running || received)
25
+ process.exit(128 + SIGNALS[name]);
26
+ received = name;
27
+ stopRun.abort();
28
+ });
29
+ }
30
+ /** End as the signal that stopped the run would have ended this process. */
31
+ function leaveBySignal(name) {
32
+ process.removeAllListeners(name);
33
+ process.kill(process.pid, name);
34
+ // Still here a moment later: nothing kills this process that way (process 1).
35
+ setTimeout(() => process.exit(128 + SIGNALS[name]), 100);
36
+ }
5
37
  function collectArg(value, previous) {
6
38
  return [...previous, value];
7
39
  }
@@ -59,7 +91,12 @@ cli
59
91
  }
60
92
  }
61
93
  const args = parseArgs(opts.arg);
62
- const result = await runProgram({ projectDir: resolveProject(name), timeout, args });
94
+ const projectDir = resolveProject(name);
95
+ running = true;
96
+ const result = await runProgram({ projectDir, timeout, args, signal: stopRun.signal })
97
+ .finally(() => { running = false; });
98
+ if (received)
99
+ return leaveBySignal(received);
63
100
  if (result.status === "failed") {
64
101
  throw new Error(`Program failed: ${result.reason}`);
65
102
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trama-dev/cli",
3
- "version": "0.2.2",
3
+ "version": "0.3.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "trama": "dist/index.js"
@@ -30,8 +30,8 @@
30
30
  "node": ">=22.19.0"
31
31
  },
32
32
  "dependencies": {
33
- "@trama-dev/runtime": "0.2.2",
34
- "@trama-dev/session": "0.2.2",
33
+ "@trama-dev/runtime": "0.3.1",
34
+ "@trama-dev/session": "0.3.1",
35
35
  "commander": "15.1.0"
36
36
  }
37
37
  }