@nubjs/nub 0.0.26 → 0.0.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.
Files changed (2) hide show
  1. package/bin/launch.js +30 -7
  2. package/package.json +9 -9
package/bin/launch.js CHANGED
@@ -28,7 +28,8 @@
28
28
  // The native binary selects its verb from argv[0]'s basename (nub vs nubx); the
29
29
  // healed trampoline exec's bin/<verb> in the platform package (which ships both
30
30
  // names), so no argv0 override is needed past the heal.
31
- const { spawnSync } = require("child_process");
31
+ const { spawn } = require("child_process");
32
+ const os = require("os");
32
33
  const fs = require("fs");
33
34
  const path = require("path");
34
35
  const { platformPackage } = require("../platform.js");
@@ -140,13 +141,35 @@ module.exports = function launch(argv0Name) {
140
141
  healPathEntry(verb, binPath);
141
142
  // This call still runs through Node; spawn the native binary. argv0 basename of
142
143
  // binPath is the verb (bin/nub or bin/nubx), so the Rust CLI dispatches correctly
143
- // without an argv0 override.
144
+ // without an argv0 override. We use async `spawn` (not `spawnSync`) ONLY so this
145
+ // Node launcher can forward terminating signals to the native child: `spawnSync`
146
+ // blocks the event loop, so a SIGTERM (docker stop on a `nub run` entrypoint whose
147
+ // first-ever call hasn't been healed to the sh trampoline yet) would terminate
148
+ // this launcher and orphan the workload. With async spawn we relay SIGTERM/INT/HUP
149
+ // to the child — which then relays to its own subtree — and mirror its exit
150
+ // status. (Subsequent calls skip Node entirely via the healed trampoline's `exec`,
151
+ // where signals reach the binary directly.)
144
152
  const opts = { stdio: "inherit", windowsHide: true };
145
153
  if (argv0Name) opts.argv0 = argv0Name; // belt-and-suspenders for the bin/nub fallback path
146
- const result = spawnSync(binPath, process.argv.slice(2), opts);
147
- if (result.error) {
148
- console.error(`@nubjs/nub: failed to launch ${binPath}: ${result.error.message}`);
154
+ const child = spawn(binPath, process.argv.slice(2), opts);
155
+ let forwarding = true;
156
+ const forward = (sig) => {
157
+ if (forwarding && child.pid) {
158
+ try { process.kill(child.pid, sig); } catch {}
159
+ }
160
+ };
161
+ for (const sig of ["SIGTERM", "SIGINT", "SIGHUP"]) process.on(sig, () => forward(sig));
162
+ child.on("error", (err) => {
163
+ console.error(`@nubjs/nub: failed to launch ${binPath}: ${err.message}`);
149
164
  process.exit(1);
150
- }
151
- process.exit(result.status == null ? 1 : result.status);
165
+ });
166
+ child.on("exit", (code, signal) => {
167
+ forwarding = false;
168
+ if (signal) {
169
+ // Mirror death-by-signal as 128+signo, matching the native binary and a shell.
170
+ const signo = (os.constants && os.constants.signals && os.constants.signals[signal]) || 0;
171
+ process.exit(signo ? 128 + signo : 1);
172
+ }
173
+ process.exit(code == null ? 1 : code);
174
+ });
152
175
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nubjs/nub",
3
- "version": "0.0.26",
3
+ "version": "0.0.28",
4
4
  "description": "TypeScript-first developer supertool — a fast script runner and TS runtime powered by Node.js",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/nubjs/nub",
@@ -18,13 +18,13 @@
18
18
  "postinstall.js"
19
19
  ],
20
20
  "optionalDependencies": {
21
- "@nubjs/nub-darwin-arm64": "0.0.26",
22
- "@nubjs/nub-darwin-x64": "0.0.26",
23
- "@nubjs/nub-linux-x64": "0.0.26",
24
- "@nubjs/nub-linux-x64-musl": "0.0.26",
25
- "@nubjs/nub-linux-arm64": "0.0.26",
26
- "@nubjs/nub-linux-arm64-musl": "0.0.26",
27
- "@nubjs/nub-win32-x64": "0.0.26",
28
- "@nubjs/nub-win32-arm64": "0.0.26"
21
+ "@nubjs/nub-darwin-arm64": "0.0.28",
22
+ "@nubjs/nub-darwin-x64": "0.0.28",
23
+ "@nubjs/nub-linux-x64": "0.0.28",
24
+ "@nubjs/nub-linux-x64-musl": "0.0.28",
25
+ "@nubjs/nub-linux-arm64": "0.0.28",
26
+ "@nubjs/nub-linux-arm64-musl": "0.0.28",
27
+ "@nubjs/nub-win32-x64": "0.0.28",
28
+ "@nubjs/nub-win32-arm64": "0.0.28"
29
29
  }
30
30
  }