onepipeline-api-cli 0.3.1 → 0.3.2
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/onepipeline-api.js +43 -12
- package/package.json +6 -6
package/bin/onepipeline-api.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
"use strict";
|
|
18
18
|
|
|
19
|
-
const {
|
|
19
|
+
const { spawn } = require("node:child_process");
|
|
20
20
|
|
|
21
21
|
// process.platform-process.arch -> the platform package that carries the binary.
|
|
22
22
|
// The keys mirror the Rust target matrix in .github/workflows/release.yml and
|
|
@@ -77,18 +77,49 @@ function binaryPath() {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
// The signals that mean "stop", and the reason this launcher is asynchronous.
|
|
81
|
+
//
|
|
82
|
+
// A supervisor — systemd, Docker, a CI job, the smoke test in
|
|
83
|
+
// scripts/smoke-published.sh — stops this command by signalling the process it
|
|
84
|
+
// started, which is *this* one and not the binary behind it. Under a synchronous
|
|
85
|
+
// spawn node has no chance to react: the default disposition kills the launcher
|
|
86
|
+
// where it stands, so the caller sees 128+15 instead of the server's own `0`,
|
|
87
|
+
// and the binary is left running with nothing waiting on it. So the child is
|
|
88
|
+
// spawned asynchronously and each of these is passed on to it, which is what
|
|
89
|
+
// lets the server run the graceful shutdown it already has and lets its exit
|
|
90
|
+
// status be the one the caller observes.
|
|
91
|
+
//
|
|
92
|
+
// Exactly the two the server installs handlers for (`StopSignal` in
|
|
93
|
+
// src/server.rs). Listening for a signal replaces node's default disposition, so
|
|
94
|
+
// forwarding one the binary does not handle would trade a clean kill for a
|
|
95
|
+
// launcher that outlives its terminal.
|
|
96
|
+
const STOP_SIGNALS = ["SIGTERM", "SIGINT"];
|
|
97
|
+
|
|
98
|
+
const child = spawn(binaryPath(), process.argv.slice(2), { stdio: "inherit" });
|
|
99
|
+
|
|
100
|
+
child.on("error", (error) => {
|
|
101
|
+
fail(`failed to launch the onepipeline-api binary: ${error.message}`);
|
|
82
102
|
});
|
|
83
103
|
|
|
84
|
-
|
|
85
|
-
|
|
104
|
+
for (const signal of STOP_SIGNALS) {
|
|
105
|
+
// Passed to the child alone. A terminal's Ctrl-C already reached the whole
|
|
106
|
+
// foreground group, and the server treats the repeat as the same request to
|
|
107
|
+
// stop that it is already answering.
|
|
108
|
+
process.on(signal, () => child.kill(signal));
|
|
86
109
|
}
|
|
87
110
|
|
|
88
|
-
|
|
89
|
-
//
|
|
90
|
-
//
|
|
91
|
-
|
|
92
|
-
process
|
|
93
|
-
|
|
94
|
-
|
|
111
|
+
child.on("exit", (status, signal) => {
|
|
112
|
+
// Re-raise a terminating signal so callers observe the true cause; otherwise
|
|
113
|
+
// propagate the child's exit code verbatim — a caller scripting against the
|
|
114
|
+
// documented exit codes depends on seeing them. The listeners go first:
|
|
115
|
+
// re-raising into one of them would be this process signalling itself in a
|
|
116
|
+
// loop instead of dying of what killed the binary.
|
|
117
|
+
for (const stop of STOP_SIGNALS) {
|
|
118
|
+
process.removeAllListeners(stop);
|
|
119
|
+
}
|
|
120
|
+
if (signal) {
|
|
121
|
+
process.kill(process.pid, signal);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
process.exit(status === null ? 1 : status);
|
|
125
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "onepipeline-api-cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Read API and browser view for onepipeline runs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"node": ">=18"
|
|
28
28
|
},
|
|
29
29
|
"optionalDependencies": {
|
|
30
|
-
"onepipeline-api-cli-linux-x64": "0.3.
|
|
31
|
-
"onepipeline-api-cli-linux-arm64": "0.3.
|
|
32
|
-
"onepipeline-api-cli-darwin-x64": "0.3.
|
|
33
|
-
"onepipeline-api-cli-darwin-arm64": "0.3.
|
|
34
|
-
"onepipeline-api-cli-win32-x64": "0.3.
|
|
30
|
+
"onepipeline-api-cli-linux-x64": "0.3.2",
|
|
31
|
+
"onepipeline-api-cli-linux-arm64": "0.3.2",
|
|
32
|
+
"onepipeline-api-cli-darwin-x64": "0.3.2",
|
|
33
|
+
"onepipeline-api-cli-darwin-arm64": "0.3.2",
|
|
34
|
+
"onepipeline-api-cli-win32-x64": "0.3.2"
|
|
35
35
|
}
|
|
36
36
|
}
|