ソースを参照

refactor: migrate src/project/project.ts from Bun.file() to Filesystem/stat modules (#14126)

Dax 1 ヶ月 前
コミット
3a07dd8d96
1 ファイル変更7 行追加13 行削除
  1. 7 13
      packages/opencode/src/project/project.ts

+ 7 - 13
packages/opencode/src/project/project.ts

@@ -86,8 +86,7 @@ export namespace Project {
         const gitBinary = Bun.which("git")
 
         // cached id calculation
-        let id = await Bun.file(path.join(dotgit, "opencode"))
-          .text()
+        let id = await Filesystem.readText(path.join(dotgit, "opencode"))
           .then((x) => x.trim())
           .catch(() => undefined)
 
@@ -125,9 +124,7 @@ export namespace Project {
 
           id = roots[0]
           if (id) {
-            void Bun.file(path.join(dotgit, "opencode"))
-              .write(id)
-              .catch(() => undefined)
+            void Filesystem.write(path.join(dotgit, "opencode"), id).catch(() => undefined)
           }
         }
 
@@ -277,10 +274,9 @@ export namespace Project {
     )
     const shortest = matches.sort((a, b) => a.length - b.length)[0]
     if (!shortest) return
-    const file = Bun.file(shortest)
-    const buffer = await file.arrayBuffer()
-    const base64 = Buffer.from(buffer).toString("base64")
-    const mime = file.type || "image/png"
+    const buffer = await Filesystem.readBytes(shortest)
+    const base64 = buffer.toString("base64")
+    const mime = Filesystem.mimeType(shortest) || "image/png"
     const url = `data:${mime};base64,${base64}`
     await update({
       projectID: input.id,
@@ -381,10 +377,8 @@ export namespace Project {
     const data = fromRow(row)
     const valid: string[] = []
     for (const dir of data.sandboxes) {
-      const stat = await Bun.file(dir)
-        .stat()
-        .catch(() => undefined)
-      if (stat?.isDirectory()) valid.push(dir)
+      const s = Filesystem.stat(dir)
+      if (s?.isDirectory()) valid.push(dir)
     }
     return valid
   }