fix(#2849): resolve platform binaries using current package name

The installer wrapper and postinstall script still hardcoded the old
oh-my-opencode-* platform package family. When users installed the renamed
npm package oh-my-openagent (for example via npx oh-my-openagent install on
WSL2/Linux), the main package installed correctly but the wrapper looked for
nonexistent optional binaries like oh-my-opencode-linux-x64.

Fix:
- derive packageBaseName from package.json at runtime in wrapper/postinstall
- thread packageBaseName through platform package candidate resolution
- keep legacy oh-my-opencode default as fallback
- add regression test for renamed package family
This commit is contained in:
YeonGyu-Kim
2026-03-27 18:29:36 +09:00
parent 6662205646
commit f1f099fde9
4 changed files with 50 additions and 13 deletions

View File

@@ -71,9 +71,19 @@ function getSignalExitCode(signal) {
return 128 + (signalCodeByName[signal] ?? 1); 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() { function main() {
const { platform, arch } = process; const { platform, arch } = process;
const libcFamily = getLibcFamily(); const libcFamily = getLibcFamily();
const packageBaseName = getPackageBaseName();
const avx2Supported = supportsAvx2(); const avx2Supported = supportsAvx2();
let packageCandidates; let packageCandidates;
@@ -83,6 +93,7 @@ function main() {
arch, arch,
libcFamily, libcFamily,
preferBaseline: avx2Supported === false, preferBaseline: avx2Supported === false,
packageBaseName,
}); });
} catch (error) { } catch (error) {
console.error(`\noh-my-opencode: ${error.message}\n`); console.error(`\noh-my-opencode: ${error.message}\n`);

View File

@@ -3,11 +3,11 @@
/** /**
* Get the platform-specific package name * 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" * @returns {string} Package name like "oh-my-opencode-darwin-arm64"
* @throws {Error} If libc cannot be detected on Linux * @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 = ""; let suffix = "";
if (platform === "linux") { if (platform === "linux") {
if (libcFamily === null || libcFamily === undefined) { if (libcFamily === null || libcFamily === undefined) {
@@ -23,13 +23,13 @@ export function getPlatformPackage({ platform, arch, libcFamily }) {
// Map platform names: win32 -> windows (for package name) // Map platform names: win32 -> windows (for package name)
const os = platform === "win32" ? "windows" : platform; 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 */ /** @param {{ platform: string, arch: string, libcFamily?: string | null, preferBaseline?: boolean, packageBaseName?: string }} options */
export function getPlatformPackageCandidates({ platform, arch, libcFamily, preferBaseline = false }) { export function getPlatformPackageCandidates({ platform, arch, libcFamily, preferBaseline = false, packageBaseName = "oh-my-opencode" }) {
const primaryPackage = getPlatformPackage({ platform, arch, libcFamily }); const primaryPackage = getPlatformPackage({ platform, arch, libcFamily, packageBaseName });
const baselinePackage = getBaselinePlatformPackage({ platform, arch, libcFamily }); const baselinePackage = getBaselinePlatformPackage({ platform, arch, libcFamily, packageBaseName });
if (!baselinePackage) { if (!baselinePackage) {
return [primaryPackage]; return [primaryPackage];
@@ -38,18 +38,18 @@ export function getPlatformPackageCandidates({ platform, arch, libcFamily, prefe
return preferBaseline ? [baselinePackage, primaryPackage] : [primaryPackage, baselinePackage]; return preferBaseline ? [baselinePackage, primaryPackage] : [primaryPackage, baselinePackage];
} }
/** @param {{ platform: string, arch: string, libcFamily?: string | null }} options */ /** @param {{ platform: string, arch: string, libcFamily?: string | null, packageBaseName?: string }} options */
function getBaselinePlatformPackage({ platform, arch, libcFamily }) { function getBaselinePlatformPackage({ platform, arch, libcFamily, packageBaseName = "oh-my-opencode" }) {
if (arch !== "x64") { if (arch !== "x64") {
return null; return null;
} }
if (platform === "darwin") { if (platform === "darwin") {
return "oh-my-opencode-darwin-x64-baseline"; return `${packageBaseName}-darwin-x64-baseline`;
} }
if (platform === "win32") { if (platform === "win32") {
return "oh-my-opencode-windows-x64-baseline"; return `${packageBaseName}-windows-x64-baseline`;
} }
if (platform === "linux") { if (platform === "linux") {
@@ -61,10 +61,10 @@ function getBaselinePlatformPackage({ platform, arch, libcFamily }) {
} }
if (libcFamily === "musl") { 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; return null;

View File

@@ -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", () => { test("returns only one candidate for ARM64", () => {
// #given non-x64 platform // #given non-x64 platform
const input = { platform: "linux", arch: "arm64", libcFamily: "glibc" }; const input = { platform: "linux", arch: "arm64", libcFamily: "glibc" };

View File

@@ -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() { function main() {
const { platform, arch } = process; const { platform, arch } = process;
const libcFamily = getLibcFamily(); const libcFamily = getLibcFamily();
const packageBaseName = getPackageBaseName();
try { try {
const packageCandidates = getPlatformPackageCandidates({ const packageCandidates = getPlatformPackageCandidates({
platform, platform,
arch, arch,
libcFamily, libcFamily,
packageBaseName,
}); });
const resolvedPackage = packageCandidates.find((pkg) => { const resolvedPackage = packageCandidates.find((pkg) => {