Просмотр исходного кода

cache platform binary in postinstall for faster startup (#14467)

Aiden Cline 1 месяц назад
Родитель
Сommit
1d9f05e4f5
2 измененных файлов с 14 добавлено и 2 удалено
  1. 6 0
      packages/opencode/bin/opencode
  2. 8 2
      packages/opencode/script/postinstall.mjs

+ 6 - 0
packages/opencode/bin/opencode

@@ -25,6 +25,12 @@ if (envPath) {
 const scriptPath = fs.realpathSync(__filename)
 const scriptDir = path.dirname(scriptPath)
 
+//
+const cached = path.join(scriptDir, ".opencode")
+if (fs.existsSync(cached)) {
+  run(cached)
+}
+
 const platformMap = {
   darwin: "darwin",
   linux: "linux",

+ 8 - 2
packages/opencode/script/postinstall.mjs

@@ -109,8 +109,14 @@ async function main() {
     // On non-Windows platforms, just verify the binary package exists
     // Don't replace the wrapper script - it handles binary execution
     const { binaryPath } = findBinary()
-    console.log(`Platform binary verified at: ${binaryPath}`)
-    console.log("Wrapper script will handle binary execution")
+    const target = path.join(__dirname, "bin", ".opencode")
+    if (fs.existsSync(target)) fs.unlinkSync(target)
+    try {
+      fs.linkSync(binaryPath, target)
+    } catch {
+      fs.copyFileSync(binaryPath, target)
+    }
+    fs.chmodSync(target, 0o755)
   } catch (error) {
     console.error("Failed to setup opencode binary:", error.message)
     process.exit(1)