refactor(macos): bundle single relay binary
This commit is contained in:
@@ -12,11 +12,8 @@ describe("ensureClawdisCliOnPath", () => {
|
||||
try {
|
||||
const relayDir = path.join(tmp, "Relay");
|
||||
await fs.mkdir(relayDir, { recursive: true });
|
||||
const gatewayPath = path.join(relayDir, "clawdis-gateway");
|
||||
const cliPath = path.join(relayDir, "clawdis");
|
||||
await fs.writeFile(gatewayPath, "#!/bin/sh\nexit 0\n", "utf-8");
|
||||
await fs.writeFile(cliPath, "#!/bin/sh\necho ok\n", "utf-8");
|
||||
await fs.chmod(gatewayPath, 0o755);
|
||||
await fs.chmod(cliPath, 0o755);
|
||||
|
||||
const originalPath = process.env.PATH;
|
||||
@@ -25,7 +22,7 @@ describe("ensureClawdisCliOnPath", () => {
|
||||
delete process.env.CLAWDIS_PATH_BOOTSTRAPPED;
|
||||
try {
|
||||
ensureClawdisCliOnPath({
|
||||
execPath: gatewayPath,
|
||||
execPath: cliPath,
|
||||
cwd: tmp,
|
||||
homeDir: tmp,
|
||||
platform: "darwin",
|
||||
|
||||
@@ -55,7 +55,7 @@ function candidateBinDirs(opts: EnsureClawdisPathOpts): string[] {
|
||||
|
||||
const candidates: string[] = [];
|
||||
|
||||
// Bun bundled (macOS app): `clawdis` is shipped next to `clawdis-gateway`.
|
||||
// Bun bundled (macOS app): `clawdis` lives in the Relay dir (process.execPath).
|
||||
try {
|
||||
const execDir = path.dirname(execPath);
|
||||
const siblingClawdis = path.join(execDir, "clawdis");
|
||||
|
||||
69
src/macos/relay.ts
Normal file
69
src/macos/relay.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env node
|
||||
import process from "node:process";
|
||||
|
||||
declare const __CLAWDIS_VERSION__: string | undefined;
|
||||
|
||||
const BUNDLED_VERSION =
|
||||
typeof __CLAWDIS_VERSION__ === "string" ? __CLAWDIS_VERSION__ : "0.0.0";
|
||||
|
||||
function hasFlag(args: string[], flag: string): boolean {
|
||||
return args.includes(flag);
|
||||
}
|
||||
|
||||
async function patchBunLongForProtobuf(): Promise<void> {
|
||||
// Bun ships a global `Long` that protobufjs detects, but it is not long.js and
|
||||
// misses critical APIs (fromBits, ...). Baileys WAProto expects long.js.
|
||||
if (typeof process.versions.bun !== "string") return;
|
||||
const mod = await import("long");
|
||||
const Long = (mod as unknown as { default?: unknown }).default ?? mod;
|
||||
(globalThis as unknown as { Long?: unknown }).Long = Long;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const args = process.argv.slice(2);
|
||||
|
||||
// Swift side expects `--version` to return a plain semver string.
|
||||
if (
|
||||
hasFlag(args, "--version") ||
|
||||
hasFlag(args, "-V") ||
|
||||
hasFlag(args, "-v")
|
||||
) {
|
||||
console.log(BUNDLED_VERSION);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
await patchBunLongForProtobuf();
|
||||
|
||||
const { default: dotenv } = await import("dotenv");
|
||||
dotenv.config({ quiet: true });
|
||||
|
||||
const { ensureClawdisCliOnPath } = await import("../infra/path-env.js");
|
||||
ensureClawdisCliOnPath();
|
||||
|
||||
const { enableConsoleCapture } = await import("../logging.js");
|
||||
enableConsoleCapture();
|
||||
|
||||
const { assertSupportedRuntime } = await import("../infra/runtime-guard.js");
|
||||
assertSupportedRuntime();
|
||||
|
||||
const { buildProgram } = await import("../cli/program.js");
|
||||
const program = buildProgram();
|
||||
|
||||
process.on("unhandledRejection", (reason, _promise) => {
|
||||
console.error(
|
||||
"[clawdis] Unhandled promise rejection:",
|
||||
reason instanceof Error ? (reason.stack ?? reason.message) : reason,
|
||||
);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
process.on("uncaughtException", (error) => {
|
||||
console.error("[clawdis] Uncaught exception:", error.stack ?? error.message);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
await program.parseAsync(process.argv);
|
||||
}
|
||||
|
||||
void main();
|
||||
|
||||
Reference in New Issue
Block a user