fix(bin): route lazycodex through bundled cli

This commit is contained in:
YeonGyu-Kim
2026-05-30 21:45:42 +09:00
parent a789d6c2a5
commit a149805253
2 changed files with 119 additions and 3 deletions
+41 -3
View File
@@ -6,6 +6,7 @@ import { spawnSync } from "node:child_process";
import { readFileSync } from "node:fs";
import { createRequire } from "node:module";
import { basename } from "node:path";
import { fileURLToPath } from "node:url";
import {
getPlatformPackageCandidates,
getBinaryPath,
@@ -77,9 +78,13 @@ function getSignalExitCode(signal) {
}
function getPackageBaseName() {
return resolvePlatformPackageBaseName(getWrapperPackageName());
}
function getWrapperPackageName() {
try {
const packageJson = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
return resolvePlatformPackageBaseName(packageJson.name || "oh-my-opencode");
return packageJson.name || "oh-my-opencode";
} catch {
return "oh-my-opencode";
}
@@ -102,10 +107,44 @@ function getInvocationName() {
return basename(argv1, ".js").replace(/\.exe$/, "");
}
function shouldRunBundledLazyCodexCli(packageName, invocationName) {
return packageName === "lazycodex" && invocationName === "lazycodex";
}
function runBundledLazyCodexCli(invocationName) {
const cliPath = fileURLToPath(new URL("../dist/cli/index.js", import.meta.url));
const result = spawnSync("bun", [cliPath, ...process.argv.slice(2)], {
stdio: "inherit",
env: {
...process.env,
OMO_INVOCATION_NAME: invocationName,
},
});
if (result.error) {
console.error("\nlazycodex: Failed to execute bundled CLI with Bun.");
console.error("Install Bun or run through `bunx lazycodex`.");
console.error(`Error: ${result.error.message}\n`);
process.exit(2);
}
if (result.signal) {
process.exit(getSignalExitCode(result.signal));
}
process.exit(result.status ?? 1);
}
function main() {
const { platform, arch } = process;
const libcFamily = getLibcFamily();
const packageBaseName = getPackageBaseName();
const wrapperPackageName = getWrapperPackageName();
const invocationName = getInvocationName();
if (shouldRunBundledLazyCodexCli(wrapperPackageName, invocationName)) {
runBundledLazyCodexCli(invocationName);
}
const packageBaseName = resolvePlatformPackageBaseName(wrapperPackageName);
const avx2Supported = supportsAvx2();
let packageCandidates;
@@ -141,7 +180,6 @@ function main() {
process.exit(1);
}
const invocationName = getInvocationName();
const childEnv = {
...process.env,
OMO_INVOCATION_NAME: invocationName,