@orggem/mini-pod 0.1.0 → 0.1.3

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 (3) hide show
  1. package/README.md +4 -1
  2. package/launcher.js +80 -8
  3. package/package.json +6 -6
package/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # mini-pod on npm
2
2
 
3
- After an npm release is available, install the CLI and daemon with Node.js 18 or later:
3
+ Install the CLI and daemon with Node.js 18 or later. As checked on 2026-11-29,
4
+ npm `latest` is **0.1.0**, while GitHub provides **v0.1.2**. See
5
+ [release status](https://github.com/OrgGem/mini-pod/blob/main/docs/status.md)
6
+ before choosing a distribution; the v0.1.2 npm publish job failed.
4
7
 
5
8
  ```sh
6
9
  npm install -g @orggem/mini-pod
package/launcher.js CHANGED
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
+ const os = require('node:os');
3
4
  const path = require('node:path');
4
- const { spawnSync } = require('node:child_process');
5
+ const { spawn } = require('node:child_process');
5
6
 
6
7
  const packages = new Set([
7
8
  'win32-x64',
@@ -22,6 +23,34 @@ function platformPackage(platform, arch, glibcVersion) {
22
23
  return `@orggem/mini-pod-${target}`;
23
24
  }
24
25
 
26
+ function watchedSignals(platform) {
27
+ return platform === 'win32'
28
+ ? ['SIGINT', 'SIGBREAK', 'SIGTERM', 'SIGHUP']
29
+ : ['SIGINT', 'SIGTERM', 'SIGHUP'];
30
+ }
31
+
32
+ function shouldForwardSignal(platform, signal, win32InterruptCount) {
33
+ if (platform !== 'win32') {
34
+ return true;
35
+ }
36
+ // On Windows inherited console `Ctrl+C` / `Ctrl+Break` deliver `CTRL_C_EVENT` /
37
+ // `CTRL_BREAK_EVENT` directly to the Rust child so it can clean up VMs and exit cleanly;
38
+ // `child.kill` calls `TerminateProcess` (hard kill). Let the first interrupt pass gracefully and
39
+ // escalate on repeat interrupts or `SIGTERM`.
40
+ if (signal === 'SIGINT' || signal === 'SIGBREAK') {
41
+ return win32InterruptCount > 1;
42
+ }
43
+ if (signal === 'SIGHUP') {
44
+ return false;
45
+ }
46
+ return true;
47
+ }
48
+
49
+ function exitCodeForSignal(signal) {
50
+ const signo = os.constants.signals[signal];
51
+ return typeof signo === 'number' ? 128 + signo : 1;
52
+ }
53
+
25
54
  function run(command) {
26
55
  try {
27
56
  const glibcVersion = process.platform === 'linux'
@@ -36,17 +65,60 @@ function run(command) {
36
65
  throw new Error(`The ${packageName} binary package is missing. Reinstall with optional dependencies enabled.`);
37
66
  }
38
67
  const executable = path.join(path.dirname(packageJson), 'bin', command + (process.platform === 'win32' ? '.exe' : ''));
39
- const result = spawnSync(executable, process.argv.slice(2), { stdio: 'inherit' });
40
- if (result.error) throw result.error;
41
- if (result.signal) {
42
- process.kill(process.pid, result.signal);
43
- } else {
44
- process.exitCode = result.status ?? 1;
68
+ const child = spawn(executable, process.argv.slice(2), { stdio: 'inherit' });
69
+ let win32InterruptCount = 0;
70
+ const signalHandlers = [];
71
+ for (const sig of watchedSignals(process.platform)) {
72
+ const handler = () => {
73
+ if (process.platform === 'win32' && (sig === 'SIGINT' || sig === 'SIGBREAK')) {
74
+ win32InterruptCount += 1;
75
+ }
76
+ if (
77
+ child.exitCode === null
78
+ && child.signalCode === null
79
+ && shouldForwardSignal(process.platform, sig, win32InterruptCount)
80
+ ) {
81
+ try {
82
+ child.kill(sig);
83
+ } catch {
84
+ // Ignore errors if the child already exited between check and signal delivery.
85
+ }
86
+ }
87
+ };
88
+ signalHandlers.push([sig, handler]);
89
+ process.on(sig, handler);
45
90
  }
91
+ const cleanupSignals = () => {
92
+ for (const [sig, handler] of signalHandlers) {
93
+ process.off(sig, handler);
94
+ }
95
+ };
96
+
97
+ child.on('error', err => {
98
+ cleanupSignals();
99
+ console.error(`${command}: ${err.message}`);
100
+ process.exitCode = 1;
101
+ });
102
+
103
+ child.on('exit', (code, signal) => {
104
+ cleanupSignals();
105
+ if (signal) {
106
+ process.exitCode = exitCodeForSignal(signal);
107
+ if (process.platform !== 'win32') {
108
+ try {
109
+ process.kill(process.pid, signal);
110
+ } catch {
111
+ // Fall back to `process.exitCode` set above if signal re-delivery fails.
112
+ }
113
+ }
114
+ } else {
115
+ process.exitCode = code ?? 1;
116
+ }
117
+ });
46
118
  } catch (err) {
47
119
  console.error(`${command}: ${err.message}`);
48
120
  process.exitCode = 1;
49
121
  }
50
122
  }
51
123
 
52
- module.exports = { platformPackage, run };
124
+ module.exports = { platformPackage, run, watchedSignals, shouldForwardSignal, exitCodeForSignal };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orggem/mini-pod",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "description": "Command-line client and daemon for the mini-pod sandbox runtime",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -21,11 +21,11 @@
21
21
  "README.md"
22
22
  ],
23
23
  "optionalDependencies": {
24
- "@orggem/mini-pod-win32-x64": "0.1.0",
25
- "@orggem/mini-pod-linux-x64": "0.1.0",
26
- "@orggem/mini-pod-linux-arm64": "0.1.0",
27
- "@orggem/mini-pod-darwin-x64": "0.1.0",
28
- "@orggem/mini-pod-darwin-arm64": "0.1.0"
24
+ "@orggem/mini-pod-win32-x64": "0.1.3",
25
+ "@orggem/mini-pod-linux-x64": "0.1.3",
26
+ "@orggem/mini-pod-linux-arm64": "0.1.3",
27
+ "@orggem/mini-pod-darwin-x64": "0.1.3",
28
+ "@orggem/mini-pod-darwin-arm64": "0.1.3"
29
29
  },
30
30
  "publishConfig": {
31
31
  "access": "public"