Skip to content

Commit ca3c22d

Browse files
committed
fix bunfile bug
1 parent 49110f7 commit ca3c22d

File tree

6 files changed

+18
-16
lines changed

6 files changed

+18
-16
lines changed

packages/opencode/src/auth/anthropic.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import fs from "fs/promises"
66
export namespace AuthAnthropic {
77
const CLIENT_ID = "9d1c250a-e61b-44d9-88ed-5944d1962f5e"
88

9-
const file = Bun.file(path.join(Global.Path.data, "auth", "anthropic.json"))
9+
const filepath = path.join(Global.Path.data, "auth", "anthropic.json")
1010

1111
export async function authorize() {
1212
const pkce = await generatePKCE()
@@ -48,15 +48,15 @@ export namespace AuthAnthropic {
4848
}),
4949
})
5050
if (!result.ok) throw new ExchangeFailed()
51+
const file = Bun.file(filepath)
5152
await Bun.write(file, result)
5253
await fs.chmod(file.name!, 0o600)
5354
}
5455

55-
export const exists = file.exists
56-
5756
export async function access() {
58-
if (!(await file.exists())) return
59-
const result = await file.json()
57+
const file = Bun.file(filepath)
58+
const result = await file.json().catch(() => ({}))
59+
if (!result) return
6060
const refresh = result.refresh_token
6161
const response = await fetch(
6262
"https://console.anthropic.com/v1/oauth/token",

packages/opencode/src/auth/keys.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ import { Global } from "../global"
33
import fs from "fs/promises"
44

55
export namespace AuthKeys {
6-
const file = Bun.file(path.join(Global.Path.data, "auth", "keys.json"))
6+
const filepath = path.join(Global.Path.data, "auth", "keys.json")
77

88
export async function get() {
9+
const file = Bun.file(filepath)
910
return file
1011
.json()
1112
.catch(() => ({}))
1213
.then((x) => x as Record<string, string>)
1314
}
1415

1516
export async function set(key: string, value: string) {
17+
const file = Bun.file(filepath)
1618
const env = await get()
1719
await Bun.write(file, JSON.stringify({ ...env, [key]: value }))
1820
await fs.chmod(file.name!, 0o600)

packages/opencode/src/bun/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ export namespace BunProc {
88
options?: Bun.SpawnOptions.OptionsObject<any, any, any>,
99
) {
1010
const root =
11-
process.argv0 !== "bun"
11+
process.argv0 !== "bun" && false
1212
? path.resolve(process.cwd(), process.argv0)
13-
: process.argv0
13+
: "bun"
1414
log.info("running", {
1515
cmd: [root, ...cmd],
1616
options,

packages/opencode/src/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ yargs(hideBin(process.argv))
3636
await App.provide({ cwd: process.cwd(), version: VERSION }, async () => {
3737
const providers = await Provider.list()
3838
if (Object.keys(providers).length === 0) {
39-
UI.empty()
40-
UI.logo()
41-
UI.empty()
4239
await ProviderAddCommand.handler(args)
4340
return
4441
}

packages/opencode/src/lsp/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ export namespace LSPServer {
3838
).catch(() => {})
3939
if (!tsserver) return
4040
const root =
41-
process.argv0 !== "bun"
41+
process.argv0 !== "bun" && false
4242
? path.resolve(process.cwd(), process.argv0)
43-
: process.argv0
43+
: "bun"
4444
const proc = spawn(
4545
root,
4646
["x", "typescript-language-server", "--stdio"],

packages/opencode/src/provider/models.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@ import path from "path"
44

55
export namespace ModelsDev {
66
const log = Log.create({ service: "models.dev" })
7-
const file = Bun.file(path.join(Global.Path.cache, "models.json"))
7+
const filepath = path.join(Global.Path.cache, "models.json")
88

99
export async function get() {
10-
if (await file.exists()) {
10+
const file = Bun.file(filepath)
11+
const result = await file.json().catch(() => {})
12+
if (result) {
1113
refresh()
12-
return file.json()
14+
return result
1315
}
1416
await refresh()
1517
return get()
1618
}
1719

1820
async function refresh() {
21+
const file = Bun.file(filepath)
1922
log.info("refreshing")
2023
const result = await fetch("https://models.dev/api.json")
2124
if (!result.ok)

0 commit comments

Comments
 (0)