open-usage 0.3.2 → 0.4.0
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/open-usage.js +40 -9
- package/package.json +7 -6
package/bin/open-usage.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
// The binary embeds Bun, so nothing needs to be installed alongside it.
|
|
4
4
|
// Deliberately dependency-free and syntax-conservative so it runs on any Node.
|
|
5
5
|
import { createRequire } from "node:module";
|
|
6
|
-
import {
|
|
6
|
+
import { spawn } from "node:child_process";
|
|
7
|
+
import { realpathSync } from "node:fs";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
7
9
|
|
|
8
10
|
const PLATFORM_PACKAGES = {
|
|
9
11
|
"darwin-arm64": "@open-usage/darwin-arm64",
|
|
@@ -44,13 +46,42 @@ function resolvePlatformBinary() {
|
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
|
|
49
|
+
export function launch(binary = resolvePlatformBinary(), args = process.argv.slice(2)) {
|
|
50
|
+
const child = spawn(binary, args, { stdio: "inherit" });
|
|
51
|
+
const signals = ["SIGTERM", "SIGINT", "SIGHUP"];
|
|
52
|
+
const handlers = new Map();
|
|
48
53
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
function cleanup() {
|
|
55
|
+
for (const [signal, handler] of handlers) process.off(signal, handler);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
for (const signal of signals) {
|
|
59
|
+
const handler = () => {
|
|
60
|
+
try {
|
|
61
|
+
child.kill(signal);
|
|
62
|
+
} catch {
|
|
63
|
+
// The child may already be exiting; its exit event remains authoritative.
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
handlers.set(signal, handler);
|
|
67
|
+
process.on(signal, handler);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
child.once("error", (error) => {
|
|
71
|
+
cleanup();
|
|
72
|
+
fail("failed to start the platform binary", error.message);
|
|
73
|
+
});
|
|
74
|
+
child.once("exit", (code, signal) => {
|
|
75
|
+
cleanup();
|
|
76
|
+
if (signal) {
|
|
77
|
+
process.kill(process.pid, signal);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
process.exit(code ?? 1);
|
|
81
|
+
});
|
|
55
82
|
}
|
|
56
|
-
|
|
83
|
+
|
|
84
|
+
if (
|
|
85
|
+
process.argv[1] &&
|
|
86
|
+
realpathSync(fileURLToPath(import.meta.url)) === realpathSync(process.argv[1])
|
|
87
|
+
) launch();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "open-usage",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "A terminal dashboard for unified AI plan usage across Claude Code, Codex, and OpenCode Go",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "GPL-3.0-only",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"shot": "bun scripts/shot.tsx",
|
|
42
42
|
"build": "bun build --compile --minify src/index.tsx --outfile dist/open-usage",
|
|
43
43
|
"build:npm": "bun scripts/build-npm-packages.ts",
|
|
44
|
+
"prepublishOnly": "bun scripts/check-prepublish.ts",
|
|
44
45
|
"version:set": "bun scripts/set-version.ts",
|
|
45
46
|
"test": "bun test",
|
|
46
47
|
"typecheck": "tsc --noEmit"
|
|
@@ -54,10 +55,10 @@
|
|
|
54
55
|
"typescript": "^5"
|
|
55
56
|
},
|
|
56
57
|
"optionalDependencies": {
|
|
57
|
-
"@open-usage/darwin-arm64": "0.
|
|
58
|
-
"@open-usage/linux-arm64": "0.
|
|
59
|
-
"@open-usage/linux-x64": "0.
|
|
60
|
-
"@open-usage/win32-arm64": "0.
|
|
61
|
-
"@open-usage/win32-x64": "0.
|
|
58
|
+
"@open-usage/darwin-arm64": "0.4.0",
|
|
59
|
+
"@open-usage/linux-arm64": "0.4.0",
|
|
60
|
+
"@open-usage/linux-x64": "0.4.0",
|
|
61
|
+
"@open-usage/win32-arm64": "0.4.0",
|
|
62
|
+
"@open-usage/win32-x64": "0.4.0"
|
|
62
63
|
}
|
|
63
64
|
}
|