Explorar el Código

fix bunfile bug

Dax Raad hace 8 meses
padre
commit
ca3c22dc12

+ 5 - 5
packages/opencode/src/auth/anthropic.ts

@@ -6,7 +6,7 @@ import fs from "fs/promises"
 export namespace AuthAnthropic {
   const CLIENT_ID = "9d1c250a-e61b-44d9-88ed-5944d1962f5e"
 
-  const file = Bun.file(path.join(Global.Path.data, "auth", "anthropic.json"))
+  const filepath = path.join(Global.Path.data, "auth", "anthropic.json")
 
   export async function authorize() {
     const pkce = await generatePKCE()
@@ -48,15 +48,15 @@ export namespace AuthAnthropic {
       }),
     })
     if (!result.ok) throw new ExchangeFailed()
+    const file = Bun.file(filepath)
     await Bun.write(file, result)
     await fs.chmod(file.name!, 0o600)
   }
 
-  export const exists = file.exists
-
   export async function access() {
-    if (!(await file.exists())) return
-    const result = await file.json()
+    const file = Bun.file(filepath)
+    const result = await file.json().catch(() => ({}))
+    if (!result) return
     const refresh = result.refresh_token
     const response = await fetch(
       "https://console.anthropic.com/v1/oauth/token",

+ 3 - 1
packages/opencode/src/auth/keys.ts

@@ -3,9 +3,10 @@ import { Global } from "../global"
 import fs from "fs/promises"
 
 export namespace AuthKeys {
-  const file = Bun.file(path.join(Global.Path.data, "auth", "keys.json"))
+  const filepath = path.join(Global.Path.data, "auth", "keys.json")
 
   export async function get() {
+    const file = Bun.file(filepath)
     return file
       .json()
       .catch(() => ({}))
@@ -13,6 +14,7 @@ export namespace AuthKeys {
   }
 
   export async function set(key: string, value: string) {
+    const file = Bun.file(filepath)
     const env = await get()
     await Bun.write(file, JSON.stringify({ ...env, [key]: value }))
     await fs.chmod(file.name!, 0o600)

+ 2 - 2
packages/opencode/src/bun/index.ts

@@ -8,9 +8,9 @@ export namespace BunProc {
     options?: Bun.SpawnOptions.OptionsObject<any, any, any>,
   ) {
     const root =
-      process.argv0 !== "bun"
+      process.argv0 !== "bun" && false
         ? path.resolve(process.cwd(), process.argv0)
-        : process.argv0
+        : "bun"
     log.info("running", {
       cmd: [root, ...cmd],
       options,

+ 0 - 3
packages/opencode/src/index.ts

@@ -36,9 +36,6 @@ yargs(hideBin(process.argv))
       await App.provide({ cwd: process.cwd(), version: VERSION }, async () => {
         const providers = await Provider.list()
         if (Object.keys(providers).length === 0) {
-          UI.empty()
-          UI.logo()
-          UI.empty()
           await ProviderAddCommand.handler(args)
           return
         }

+ 2 - 2
packages/opencode/src/lsp/server.ts

@@ -38,9 +38,9 @@ export namespace LSPServer {
         ).catch(() => {})
         if (!tsserver) return
         const root =
-          process.argv0 !== "bun"
+          process.argv0 !== "bun" && false
             ? path.resolve(process.cwd(), process.argv0)
-            : process.argv0
+            : "bun"
         const proc = spawn(
           root,
           ["x", "typescript-language-server", "--stdio"],

+ 6 - 3
packages/opencode/src/provider/models.ts

@@ -4,18 +4,21 @@ import path from "path"
 
 export namespace ModelsDev {
   const log = Log.create({ service: "models.dev" })
-  const file = Bun.file(path.join(Global.Path.cache, "models.json"))
+  const filepath = path.join(Global.Path.cache, "models.json")
 
   export async function get() {
-    if (await file.exists()) {
+    const file = Bun.file(filepath)
+    const result = await file.json().catch(() => {})
+    if (result) {
       refresh()
-      return file.json()
+      return result
     }
     await refresh()
     return get()
   }
 
   async function refresh() {
+    const file = Bun.file(filepath)
     log.info("refreshing")
     const result = await fetch("https://models.dev/api.json")
     if (!result.ok)