diff options
| author | Dax <[email protected]> | 2026-02-18 19:26:45 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-02-18 19:26:45 -0500 |
| commit | 270b807cdf004b4ae398414e1475f9dc24e5cb43 (patch) | |
| tree | 7e1b95ab2a5ad6a5a36ed4862a3df2f3d4fe8f35 | |
| parent | bd52ce5640f0299f49f2bc2bfadcb95c2acec260 (diff) | |
| download | opencode-270b807cdf004b4ae398414e1475f9dc24e5cb43.tar.gz opencode-270b807cdf004b4ae398414e1475f9dc24e5cb43.zip | |
refactor: migrate src/tool/edit.ts from Bun.file() to Filesystem module (#14120)
| -rw-r--r-- | packages/opencode/src/tool/edit.ts | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/packages/opencode/src/tool/edit.ts b/packages/opencode/src/tool/edit.ts index d84f6ec34..7a097d3fe 100644 --- a/packages/opencode/src/tool/edit.ts +++ b/packages/opencode/src/tool/edit.ts @@ -49,7 +49,7 @@ export const EditTool = Tool.define("edit", { let contentNew = "" await FileTime.withLock(filePath, async () => { if (params.oldString === "") { - const existed = await Bun.file(filePath).exists() + const existed = await Filesystem.exists(filePath) contentNew = params.newString diff = trimDiff(createTwoFilesPatch(filePath, filePath, contentOld, contentNew)) await ctx.ask({ @@ -61,7 +61,7 @@ export const EditTool = Tool.define("edit", { diff, }, }) - await Bun.write(filePath, params.newString) + await Filesystem.write(filePath, params.newString) await Bus.publish(File.Event.Edited, { file: filePath, }) @@ -73,12 +73,11 @@ export const EditTool = Tool.define("edit", { return } - const file = Bun.file(filePath) - const stats = await file.stat().catch(() => {}) + const stats = Filesystem.stat(filePath) if (!stats) throw new Error(`File ${filePath} not found`) if (stats.isDirectory()) throw new Error(`Path is a directory, not a file: ${filePath}`) await FileTime.assert(ctx.sessionID, filePath) - contentOld = await file.text() + contentOld = await Filesystem.readText(filePath) contentNew = replace(contentOld, params.oldString, params.newString, params.replaceAll) diff = trimDiff( @@ -94,7 +93,7 @@ export const EditTool = Tool.define("edit", { }, }) - await file.write(contentNew) + await Filesystem.write(filePath, contentNew) await Bus.publish(File.Event.Edited, { file: filePath, }) @@ -102,7 +101,7 @@ export const EditTool = Tool.define("edit", { file: filePath, event: "change", }) - contentNew = await file.text() + contentNew = await Filesystem.readText(filePath) diff = trimDiff( createTwoFilesPatch(filePath, filePath, normalizeLineEndings(contentOld), normalizeLineEndings(contentNew)), ) |
