Skip to content

Commit 3cde93b

Browse files
authored
refactor: migrate src/auth/index.ts from Bun.file()/Bun.write() to Filesystem module (anomalyco#14140)
1 parent 898bcde commit 3cde93b

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

packages/opencode/src/auth/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from "path"
22
import { Global } from "../global"
33
import z from "zod"
4+
import { Filesystem } from "../util/filesystem"
45

56
export const OAUTH_DUMMY_KEY = "opencode-oauth-dummy-key"
67

@@ -42,8 +43,7 @@ export namespace Auth {
4243
}
4344

4445
export async function all(): Promise<Record<string, Info>> {
45-
const file = Bun.file(filepath)
46-
const data = await file.json().catch(() => ({}) as Record<string, unknown>)
46+
const data = await Filesystem.readJson<Record<string, unknown>>(filepath).catch(() => ({}))
4747
return Object.entries(data).reduce(
4848
(acc, [key, value]) => {
4949
const parsed = Info.safeParse(value)
@@ -56,15 +56,13 @@ export namespace Auth {
5656
}
5757

5858
export async function set(key: string, info: Info) {
59-
const file = Bun.file(filepath)
6059
const data = await all()
61-
await Bun.write(file, JSON.stringify({ ...data, [key]: info }, null, 2), { mode: 0o600 })
60+
await Filesystem.writeJson(filepath, { ...data, [key]: info }, 0o600)
6261
}
6362

6463
export async function remove(key: string) {
65-
const file = Bun.file(filepath)
6664
const data = await all()
6765
delete data[key]
68-
await Bun.write(file, JSON.stringify(data, null, 2), { mode: 0o600 })
66+
await Filesystem.writeJson(filepath, data, 0o600)
6967
}
7068
}

0 commit comments

Comments
 (0)