diff --git a/bin/oh-my-opencode.js b/bin/oh-my-opencode.js index 0d66e55eb..75b5794ce 100755 --- a/bin/oh-my-opencode.js +++ b/bin/oh-my-opencode.js @@ -71,9 +71,19 @@ function getSignalExitCode(signal) { return 128 + (signalCodeByName[signal] ?? 1); } +function getPackageBaseName() { + try { + const packageJson = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")); + return packageJson.name || "oh-my-opencode"; + } catch { + return "oh-my-opencode"; + } +} + function main() { const { platform, arch } = process; const libcFamily = getLibcFamily(); + const packageBaseName = getPackageBaseName(); const avx2Supported = supportsAvx2(); let packageCandidates; @@ -83,6 +93,7 @@ function main() { arch, libcFamily, preferBaseline: avx2Supported === false, + packageBaseName, }); } catch (error) { console.error(`\noh-my-opencode: ${error.message}\n`); diff --git a/bin/platform.js b/bin/platform.js index a2a6c3c32..5790cf3dc 100644 --- a/bin/platform.js +++ b/bin/platform.js @@ -3,11 +3,11 @@ /** * Get the platform-specific package name - * @param {{ platform: string, arch: string, libcFamily?: string | null }} options + * @param {{ platform: string, arch: string, libcFamily?: string | null, packageBaseName?: string }} options * @returns {string} Package name like "oh-my-opencode-darwin-arm64" * @throws {Error} If libc cannot be detected on Linux */ -export function getPlatformPackage({ platform, arch, libcFamily }) { +export function getPlatformPackage({ platform, arch, libcFamily, packageBaseName = "oh-my-opencode" }) { let suffix = ""; if (platform === "linux") { if (libcFamily === null || libcFamily === undefined) { @@ -23,13 +23,13 @@ export function getPlatformPackage({ platform, arch, libcFamily }) { // Map platform names: win32 -> windows (for package name) const os = platform === "win32" ? "windows" : platform; - return `oh-my-opencode-${os}-${arch}${suffix}`; + return `${packageBaseName}-${os}-${arch}${suffix}`; } -/** @param {{ platform: string, arch: string, libcFamily?: string | null, preferBaseline?: boolean }} options */ -export function getPlatformPackageCandidates({ platform, arch, libcFamily, preferBaseline = false }) { - const primaryPackage = getPlatformPackage({ platform, arch, libcFamily }); - const baselinePackage = getBaselinePlatformPackage({ platform, arch, libcFamily }); +/** @param {{ platform: string, arch: string, libcFamily?: string | null, preferBaseline?: boolean, packageBaseName?: string }} options */ +export function getPlatformPackageCandidates({ platform, arch, libcFamily, preferBaseline = false, packageBaseName = "oh-my-opencode" }) { + const primaryPackage = getPlatformPackage({ platform, arch, libcFamily, packageBaseName }); + const baselinePackage = getBaselinePlatformPackage({ platform, arch, libcFamily, packageBaseName }); if (!baselinePackage) { return [primaryPackage]; @@ -38,18 +38,18 @@ export function getPlatformPackageCandidates({ platform, arch, libcFamily, prefe return preferBaseline ? [baselinePackage, primaryPackage] : [primaryPackage, baselinePackage]; } -/** @param {{ platform: string, arch: string, libcFamily?: string | null }} options */ -function getBaselinePlatformPackage({ platform, arch, libcFamily }) { +/** @param {{ platform: string, arch: string, libcFamily?: string | null, packageBaseName?: string }} options */ +function getBaselinePlatformPackage({ platform, arch, libcFamily, packageBaseName = "oh-my-opencode" }) { if (arch !== "x64") { return null; } if (platform === "darwin") { - return "oh-my-opencode-darwin-x64-baseline"; + return `${packageBaseName}-darwin-x64-baseline`; } if (platform === "win32") { - return "oh-my-opencode-windows-x64-baseline"; + return `${packageBaseName}-windows-x64-baseline`; } if (platform === "linux") { @@ -61,10 +61,10 @@ function getBaselinePlatformPackage({ platform, arch, libcFamily }) { } if (libcFamily === "musl") { - return "oh-my-opencode-linux-x64-musl-baseline"; + return `${packageBaseName}-linux-x64-musl-baseline`; } - return "oh-my-opencode-linux-x64-baseline"; + return `${packageBaseName}-linux-x64-baseline`; } return null; diff --git a/bin/platform.test.ts b/bin/platform.test.ts index 88b8b877b..0d21f3dd4 100644 --- a/bin/platform.test.ts +++ b/bin/platform.test.ts @@ -190,6 +190,21 @@ describe("getPlatformPackageCandidates", () => { ]); }); + + + test("supports renamed package family via packageBaseName override", () => { + // #given Linux x64 with glibc and renamed package base + const input = { platform: "linux", arch: "x64", libcFamily: "glibc", packageBaseName: "oh-my-openagent" }; + + // #when getting package candidates + const result = getPlatformPackageCandidates(input); + + // #then returns renamed package family candidates + expect(result).toEqual([ + "oh-my-openagent-linux-x64", + "oh-my-openagent-linux-x64-baseline", + ]); + }); test("returns only one candidate for ARM64", () => { // #given non-x64 platform const input = { platform: "linux", arch: "arm64", libcFamily: "glibc" }; diff --git a/postinstall.mjs b/postinstall.mjs index 35f77a6d4..0d78c888f 100644 --- a/postinstall.mjs +++ b/postinstall.mjs @@ -22,15 +22,26 @@ function getLibcFamily() { } } +function getPackageBaseName() { + try { + const packageJson = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")); + return packageJson.name || "oh-my-opencode"; + } catch { + return "oh-my-opencode"; + } +} + function main() { const { platform, arch } = process; const libcFamily = getLibcFamily(); + const packageBaseName = getPackageBaseName(); try { const packageCandidates = getPlatformPackageCandidates({ platform, arch, libcFamily, + packageBaseName, }); const resolvedPackage = packageCandidates.find((pkg) => {