@sys9/run9-cli 0.2.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.
package/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # @sys9/run9-cli
2
+
3
+ Install:
4
+
5
+ ```sh
6
+ npm install -g @sys9/run9-cli
7
+ ```
8
+
9
+ ```sh
10
+ bun install -g @sys9/run9-cli
11
+ ```
12
+
13
+ Run:
14
+
15
+ ```sh
16
+ run9 auth login \
17
+ --endpoint https://api.run9.example.com \
18
+ --ak ak-... \
19
+ --sk sk-...
20
+ ```
package/bin/run9.js ADDED
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawn } from "node:child_process";
4
+ import { existsSync } from "node:fs";
5
+ import path from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+
11
+ function resolveTargetTriple(platform, arch) {
12
+ switch (platform) {
13
+ case "linux":
14
+ case "android":
15
+ switch (arch) {
16
+ case "x64":
17
+ return "x86_64-unknown-linux-musl";
18
+ case "arm64":
19
+ return "aarch64-unknown-linux-musl";
20
+ default:
21
+ return null;
22
+ }
23
+ case "darwin":
24
+ switch (arch) {
25
+ case "x64":
26
+ return "x86_64-apple-darwin";
27
+ case "arm64":
28
+ return "aarch64-apple-darwin";
29
+ default:
30
+ return null;
31
+ }
32
+ default:
33
+ return null;
34
+ }
35
+ }
36
+
37
+ const targetTriple = resolveTargetTriple(process.platform, process.arch);
38
+ if (!targetTriple) {
39
+ throw new Error(`Unsupported platform: ${process.platform} (${process.arch})`);
40
+ }
41
+
42
+ const binaryPath = path.join(__dirname, "..", "vendor", targetTriple, "run9", "run9");
43
+ if (!existsSync(binaryPath)) {
44
+ throw new Error(`Bundled run9 binary not found at ${binaryPath}`);
45
+ }
46
+
47
+ // Use asynchronous spawn so the parent process can forward terminal signals
48
+ // while the native binary is running.
49
+ const child = spawn(binaryPath, process.argv.slice(2), {
50
+ stdio: "inherit",
51
+ env: process.env,
52
+ });
53
+
54
+ child.on("error", (err) => {
55
+ // eslint-disable-next-line no-console
56
+ console.error(err);
57
+ process.exit(1);
58
+ });
59
+
60
+ const forwardSignal = (signal) => {
61
+ if (child.killed) {
62
+ return;
63
+ }
64
+ try {
65
+ child.kill(signal);
66
+ } catch {
67
+ // Ignore races where the process already exited.
68
+ }
69
+ };
70
+
71
+ ["SIGINT", "SIGTERM", "SIGHUP"].forEach((signal) => {
72
+ process.on(signal, () => forwardSignal(signal));
73
+ });
74
+
75
+ const childResult = await new Promise((resolve) => {
76
+ child.on("exit", (code, signal) => {
77
+ if (signal) {
78
+ resolve({ type: "signal", signal });
79
+ return;
80
+ }
81
+ resolve({ type: "code", exitCode: code ?? 1 });
82
+ });
83
+ });
84
+
85
+ if (childResult.type === "signal") {
86
+ process.kill(process.pid, childResult.signal);
87
+ } else {
88
+ process.exit(childResult.exitCode);
89
+ }
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@sys9/run9-cli",
3
+ "version": "0.2.3",
4
+ "description": "run9 CLI with bundled native binaries for Linux and macOS",
5
+ "license": "MIT",
6
+ "bin": {
7
+ "run9": "bin/run9.js"
8
+ },
9
+ "type": "module",
10
+ "engines": {
11
+ "node": ">=16"
12
+ },
13
+ "files": [
14
+ "bin",
15
+ "vendor",
16
+ "README.md"
17
+ ],
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/breezewish/run9.git",
24
+ "directory": "run9cli/npm"
25
+ }
26
+ }