Skip to content

Commit c79f1a7

Browse files
authored
cache platform binary in postinstall for faster startup (#14396)
1 parent 9c5bbba commit c79f1a7

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

packages/opencode/bin/opencode

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ if (envPath) {
2525
const scriptPath = fs.realpathSync(__filename)
2626
const scriptDir = path.dirname(scriptPath)
2727

28+
const cached = path.join(scriptDir, ".opencode")
29+
if (fs.existsSync(cached)) {
30+
run(cached)
31+
}
32+
2833
const platformMap = {
2934
darwin: "darwin",
3035
linux: "linux",

packages/opencode/script/postinstall.mjs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,15 @@ async function main() {
106106
return
107107
}
108108

109-
// On non-Windows platforms, just verify the binary package exists
110-
// Don't replace the wrapper script - it handles binary execution
111109
const { binaryPath } = findBinary()
112-
console.log(`Platform binary verified at: ${binaryPath}`)
113-
console.log("Wrapper script will handle binary execution")
110+
const target = path.join(__dirname, "..", "bin", ".opencode")
111+
if (fs.existsSync(target)) fs.unlinkSync(target)
112+
try {
113+
fs.linkSync(binaryPath, target)
114+
} catch {
115+
fs.copyFileSync(binaryPath, target)
116+
}
117+
fs.chmodSync(target, 0o755)
114118
} catch (error) {
115119
console.error("Failed to setup opencode binary:", error.message)
116120
process.exit(1)

0 commit comments

Comments
 (0)