refactor(core): consolidate filesystem services (#30447)

This commit is contained in:
Dax
2026-06-02 16:09:26 -04:00
committed by GitHub
parent b93963e462
commit 604a5f781f
153 changed files with 2553 additions and 4312 deletions
+3 -7
View File
@@ -1,5 +1,5 @@
import { Effect } from "effect"
import { AppFileSystem } from "@opencode-ai/core/filesystem"
import { FSUtil } from "@opencode-ai/core/fs-util"
const BOM_CODE = 0xfeff
const BOM = String.fromCharCode(BOM_CODE)
@@ -15,15 +15,11 @@ export function join(text: string, bom: boolean) {
return BOM + stripped
}
export const readFile = Effect.fn("Bom.readFile")(function* (fs: AppFileSystem.Interface, filePath: string) {
export const readFile = Effect.fn("Bom.readFile")(function* (fs: FSUtil.Interface, filePath: string) {
return split(new TextDecoder("utf-8", { ignoreBOM: true }).decode(yield* fs.readFile(filePath)))
})
export const syncFile = Effect.fn("Bom.syncFile")(function* (
fs: AppFileSystem.Interface,
filePath: string,
bom: boolean,
) {
export const syncFile = Effect.fn("Bom.syncFile")(function* (fs: FSUtil.Interface, filePath: string, bom: boolean) {
const current = yield* readFile(fs, filePath)
if (current.bom === bom) return current.text
yield* fs.writeWithDirs(filePath, join(current.text, bom))
-14
View File
@@ -1,14 +0,0 @@
import whichPkg from "which"
import path from "path"
import { Global } from "@opencode-ai/core/global"
export function which(cmd: string, env?: NodeJS.ProcessEnv) {
const base = env?.PATH ?? env?.Path ?? process.env.PATH ?? process.env.Path ?? ""
const full = base ? base + path.delimiter + Global.Path.bin : Global.Path.bin
const result = whichPkg.sync(cmd, {
nothrow: true,
path: full,
pathExt: env?.PATHEXT ?? env?.PathExt ?? process.env.PATHEXT ?? process.env.PathExt,
})
return typeof result === "string" ? result : null
}