Skip to content

Commit f81de6e

Browse files
committed
fix: add baseline variant fallback to postinstall binary lookup
Apply Greptile suggestion to handle baseline packages like shuvcode-linux-x64-baseline by searching for packages that start with the base package name when exact match fails.
1 parent 536552f commit f81de6e

1 file changed

Lines changed: 27 additions & 9 deletions

File tree

packages/opencode/postinstall.mjs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,40 @@ function detectPlatformAndArch() {
4949

5050
function findBinary() {
5151
const { platform, arch } = detectPlatformAndArch()
52-
const packageName = `shuvcode-${platform}-${arch}`
52+
const basePackageName = `shuvcode-${platform}-${arch}`
5353
const binaryName = platform === "windows" ? "shuvcode.exe" : "shuvcode"
5454

5555
try {
56-
// Use require.resolve to find the package
57-
const packageJsonPath = require.resolve(`${packageName}/package.json`)
58-
const packageDir = path.dirname(packageJsonPath)
59-
const binaryPath = path.join(packageDir, "bin", binaryName)
56+
// Try exact package name first
57+
try {
58+
const packageJsonPath = require.resolve(`${basePackageName}/package.json`)
59+
const packageDir = path.dirname(packageJsonPath)
60+
const binaryPath = path.join(packageDir, "bin", binaryName)
61+
62+
if (fs.existsSync(binaryPath)) {
63+
return { binaryPath, binaryName }
64+
}
65+
} catch (error) {
66+
// Exact match failed, try baseline variant
67+
}
6068

61-
if (!fs.existsSync(binaryPath)) {
62-
throw new Error(`Binary not found at ${binaryPath}`)
69+
// Fallback: search for baseline variants (e.g., shuvcode-linux-x64-baseline)
70+
const nodeModulesPath = path.join(__dirname, "..")
71+
if (fs.existsSync(nodeModulesPath)) {
72+
const entries = fs.readdirSync(nodeModulesPath)
73+
for (const entry of entries) {
74+
if (entry.startsWith(basePackageName)) {
75+
const binaryPath = path.join(nodeModulesPath, entry, "bin", binaryName)
76+
if (fs.existsSync(binaryPath)) {
77+
return { binaryPath, binaryName }
78+
}
79+
}
80+
}
6381
}
6482

65-
return { binaryPath, binaryName }
83+
throw new Error(`No binary package found for ${basePackageName}`)
6684
} catch (error) {
67-
throw new Error(`Could not find package ${packageName}: ${error.message}`)
85+
throw new Error(`Could not find package ${basePackageName}: ${error.message}`)
6886
}
6987
}
7088

0 commit comments

Comments
 (0)