Skip to content

Commit 3a07dd8

Browse files
authored
refactor: migrate src/project/project.ts from Bun.file() to Filesystem/stat modules (#14126)
1 parent 802ccd3 commit 3a07dd8

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

packages/opencode/src/project/project.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ export namespace Project {
8686
const gitBinary = Bun.which("git")
8787

8888
// cached id calculation
89-
let id = await Bun.file(path.join(dotgit, "opencode"))
90-
.text()
89+
let id = await Filesystem.readText(path.join(dotgit, "opencode"))
9190
.then((x) => x.trim())
9291
.catch(() => undefined)
9392

@@ -125,9 +124,7 @@ export namespace Project {
125124

126125
id = roots[0]
127126
if (id) {
128-
void Bun.file(path.join(dotgit, "opencode"))
129-
.write(id)
130-
.catch(() => undefined)
127+
void Filesystem.write(path.join(dotgit, "opencode"), id).catch(() => undefined)
131128
}
132129
}
133130

@@ -277,10 +274,9 @@ export namespace Project {
277274
)
278275
const shortest = matches.sort((a, b) => a.length - b.length)[0]
279276
if (!shortest) return
280-
const file = Bun.file(shortest)
281-
const buffer = await file.arrayBuffer()
282-
const base64 = Buffer.from(buffer).toString("base64")
283-
const mime = file.type || "image/png"
277+
const buffer = await Filesystem.readBytes(shortest)
278+
const base64 = buffer.toString("base64")
279+
const mime = Filesystem.mimeType(shortest) || "image/png"
284280
const url = `data:${mime};base64,${base64}`
285281
await update({
286282
projectID: input.id,
@@ -381,10 +377,8 @@ export namespace Project {
381377
const data = fromRow(row)
382378
const valid: string[] = []
383379
for (const dir of data.sandboxes) {
384-
const stat = await Bun.file(dir)
385-
.stat()
386-
.catch(() => undefined)
387-
if (stat?.isDirectory()) valid.push(dir)
380+
const s = Filesystem.stat(dir)
381+
if (s?.isDirectory()) valid.push(dir)
388382
}
389383
return valid
390384
}

0 commit comments

Comments
 (0)