fix: publish lazycodex as release alias
This commit is contained in:
+5
-34
@@ -6,7 +6,6 @@ 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,
|
||||
@@ -97,10 +96,13 @@ function getWrapperPackageName() {
|
||||
* (e.g. `lazycodex` defaults to the Codex install flow).
|
||||
* @returns {string}
|
||||
*/
|
||||
function getInvocationName() {
|
||||
function getInvocationName(wrapperPackageName) {
|
||||
if (process.env.OMO_INVOCATION_NAME) {
|
||||
return process.env.OMO_INVOCATION_NAME;
|
||||
}
|
||||
if (getPackageBareName(wrapperPackageName) === "lazycodex") {
|
||||
return "lazycodex";
|
||||
}
|
||||
const argv1 = process.argv[1] ?? "";
|
||||
if (!argv1) {
|
||||
return "oh-my-opencode";
|
||||
@@ -108,42 +110,11 @@ function getInvocationName() {
|
||||
return basename(argv1, ".js").replace(/\.exe$/, "");
|
||||
}
|
||||
|
||||
function shouldRunBundledLazyCodexCli(packageName, invocationName) {
|
||||
return getPackageBareName(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 wrapperPackageName = getWrapperPackageName();
|
||||
const invocationName = getInvocationName();
|
||||
if (shouldRunBundledLazyCodexCli(wrapperPackageName, invocationName)) {
|
||||
runBundledLazyCodexCli(invocationName);
|
||||
}
|
||||
const invocationName = getInvocationName(wrapperPackageName);
|
||||
|
||||
const packageBaseName = resolvePlatformPackageBaseName(wrapperPackageName);
|
||||
const avx2Supported = supportsAvx2();
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
/// <reference types="bun-types" />
|
||||
|
||||
import { afterEach, describe, expect, test } from "bun:test";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { chmod, cp, mkdir, mkdtemp, readFile, realpath, rm, writeFile } from "node:fs/promises";
|
||||
import { chmod, cp, mkdir, mkdtemp, readFile, rm, symlink, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { getPlatformPackageCandidates } from "./platform.js";
|
||||
|
||||
const testRoots: string[] = [];
|
||||
|
||||
@@ -12,7 +15,7 @@ afterEach(async () => {
|
||||
});
|
||||
|
||||
describe("lazycodex bin wrapper", () => {
|
||||
test("runs the bundled Bun CLI instead of stale OMO platform binaries", async () => {
|
||||
test("runs the platform binary so npx lazycodex does not require Bun", async () => {
|
||||
// #given
|
||||
const fixture = await createLazyCodexFixture();
|
||||
const nodePath = Bun.which("node") ?? "node";
|
||||
@@ -23,7 +26,7 @@ describe("lazycodex bin wrapper", () => {
|
||||
env: {
|
||||
...process.env,
|
||||
CAPTURE_DIR: fixture.captureDir,
|
||||
PATH: `${fixture.fakeBinDir}:${process.env.PATH ?? ""}`,
|
||||
PATH: fixture.fakeBinDir,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -31,13 +34,12 @@ describe("lazycodex bin wrapper", () => {
|
||||
expect(result.status).toBe(23);
|
||||
expect((await readFile(join(fixture.captureDir, "env"), "utf8")).trim()).toBe("lazycodex");
|
||||
expect((await readFile(join(fixture.captureDir, "args"), "utf8")).trim().split("\n")).toEqual([
|
||||
await realpath(fixture.bundledCli),
|
||||
"install",
|
||||
"--no-tui",
|
||||
]);
|
||||
});
|
||||
|
||||
test("runs the bundled Bun CLI when published under an npm scope", async () => {
|
||||
test("runs the platform binary when published under an npm scope", async () => {
|
||||
// #given
|
||||
const fixture = await createLazyCodexFixture({ packageName: "@code-yeongyu/lazycodex" });
|
||||
const nodePath = Bun.which("node") ?? "node";
|
||||
@@ -48,7 +50,31 @@ describe("lazycodex bin wrapper", () => {
|
||||
env: {
|
||||
...process.env,
|
||||
CAPTURE_DIR: fixture.captureDir,
|
||||
PATH: `${fixture.fakeBinDir}:${process.env.PATH ?? ""}`,
|
||||
PATH: fixture.fakeBinDir,
|
||||
},
|
||||
});
|
||||
|
||||
// #then
|
||||
expect(result.status).toBe(23);
|
||||
expect((await readFile(join(fixture.captureDir, "env"), "utf8")).trim()).toBe("lazycodex");
|
||||
expect((await readFile(join(fixture.captureDir, "args"), "utf8")).trim().split("\n")).toEqual([
|
||||
"install",
|
||||
"--no-tui",
|
||||
]);
|
||||
});
|
||||
|
||||
test("routes npm shim execution from the lazycodex package to the Codex installer", async () => {
|
||||
// #given
|
||||
const fixture = await createLazyCodexFixture({ wrapperFileName: "oh-my-opencode.js" });
|
||||
const nodePath = Bun.which("node") ?? "node";
|
||||
|
||||
// #when
|
||||
const result = spawnSync(nodePath, [fixture.wrapperBin, "install", "--no-tui"], {
|
||||
encoding: "utf8",
|
||||
env: {
|
||||
...process.env,
|
||||
CAPTURE_DIR: fixture.captureDir,
|
||||
PATH: fixture.fakeBinDir,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -56,14 +82,13 @@ describe("lazycodex bin wrapper", () => {
|
||||
expect(result.status).toBe(23);
|
||||
expect((await readFile(join(fixture.captureDir, "env"), "utf8")).trim()).toBe("lazycodex");
|
||||
expect((await readFile(join(fixture.captureDir, "args"), "utf8")).trim().split("\n")).toEqual([
|
||||
await realpath(fixture.bundledCli),
|
||||
"install",
|
||||
"--no-tui",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
async function createLazyCodexFixture(options: { packageName?: string } = {}) {
|
||||
async function createLazyCodexFixture(options: { packageName?: string; wrapperFileName?: string } = {}) {
|
||||
const root = await mkdtemp(join(tmpdir(), "lazycodex-bin-wrapper-"));
|
||||
testRoots.push(root);
|
||||
|
||||
@@ -76,10 +101,16 @@ async function createLazyCodexFixture(options: { packageName?: string } = {}) {
|
||||
await mkdir(fakeBinDir, { recursive: true });
|
||||
await mkdir(captureDir, { recursive: true });
|
||||
|
||||
await cp(fileURLToPath(new URL("./oh-my-opencode.js", import.meta.url)), join(binDir, "lazycodex"));
|
||||
const wrapperFileName = options.wrapperFileName ?? "lazycodex";
|
||||
const wrapperBin = join(binDir, wrapperFileName);
|
||||
await cp(fileURLToPath(new URL("./oh-my-opencode.js", import.meta.url)), wrapperBin);
|
||||
if (wrapperFileName !== "lazycodex") {
|
||||
await symlink(wrapperFileName, join(binDir, "lazycodex"));
|
||||
}
|
||||
await cp(fileURLToPath(new URL("./platform.js", import.meta.url)), join(binDir, "platform.js"));
|
||||
await writeFile(join(root, "package.json"), JSON.stringify({ name: options.packageName ?? "lazycodex", type: "module" }));
|
||||
await writeFile(distCli, "#!/usr/bin/env bun\n");
|
||||
await writePlatformPackages(root);
|
||||
|
||||
const fakeBun = join(fakeBinDir, "bun");
|
||||
await writeFile(
|
||||
@@ -99,5 +130,36 @@ async function createLazyCodexFixture(options: { packageName?: string } = {}) {
|
||||
captureDir,
|
||||
fakeBinDir,
|
||||
lazycodexBin: join(binDir, "lazycodex"),
|
||||
wrapperBin,
|
||||
};
|
||||
}
|
||||
|
||||
async function writePlatformPackages(root: string): Promise<void> {
|
||||
const packages = getPlatformPackageCandidates({
|
||||
platform: process.platform,
|
||||
arch: process.arch,
|
||||
libcFamily: process.platform === "linux" ? "glibc" : undefined,
|
||||
packageBaseName: "oh-my-opencode",
|
||||
});
|
||||
for (const packageName of packages) {
|
||||
const binaryPath = join(root, "node_modules", packageName, "bin", process.platform === "win32" ? "oh-my-opencode.exe" : "oh-my-opencode");
|
||||
await mkdir(dirname(binaryPath), { recursive: true });
|
||||
await writeFile(
|
||||
binaryPath,
|
||||
[
|
||||
"#!/bin/sh",
|
||||
"printf '%s\\n' \"$OMO_INVOCATION_NAME\" > \"$CAPTURE_DIR/env\"",
|
||||
"printf '%s\\n' \"$@\" > \"$CAPTURE_DIR/args\"",
|
||||
"exit 23",
|
||||
"",
|
||||
].join("\n"),
|
||||
);
|
||||
await chmod(binaryPath, 0o755);
|
||||
}
|
||||
|
||||
if (process.platform === "linux") {
|
||||
const detectLibcPath = join(root, "node_modules", "detect-libc", "index.js");
|
||||
await mkdir(dirname(detectLibcPath), { recursive: true });
|
||||
await writeFile(detectLibcPath, 'exports.familySync = () => "glibc";\n');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user