Skip to content

Commit 95a3715

Browse files
vtemianclaude
andcommitted
fix(ripgrep): use Bun.spawn instead of shell for search
Replace shell command execution with Bun.spawn to avoid cross-platform shell quoting issues. The previous approach used embedded single quotes in glob patterns which behaved differently on macOS vs Ubuntu. Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent c83cd5a commit 95a3715

File tree

1 file changed

+13
-6
lines changed
  • packages/opencode/src/file/ripgrep

1 file changed

+13
-6
lines changed

packages/opencode/src/file/ripgrep/index.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import fs from "fs/promises"
22

3-
import { $ } from "bun"
43
import z from "zod"
54

65
import { lazy } from "@/util/lazy.ts"
@@ -142,7 +141,7 @@ export namespace Ripgrep {
142141
}
143142

144143
export async function search(input: { cwd: string; pattern: string; glob?: string[]; limit?: number }) {
145-
const args = [`${await rg()}`, "--json", "--hidden", "--glob='!.git/*'"]
144+
const args = ["--json", "--hidden", "--glob=!.git/*"]
146145

147146
for (const g of input.glob ?? []) {
148147
args.push(`--glob=${g}`)
@@ -155,14 +154,22 @@ export namespace Ripgrep {
155154
args.push("--")
156155
args.push(input.pattern)
157156

158-
const command = args.join(" ")
159-
const searchResult = await $`${{ raw: command }}`.cwd(input.cwd).quiet().nothrow()
160-
if (searchResult.exitCode !== 0) {
157+
const proc = Bun.spawn([await rg(), ...args], {
158+
cwd: input.cwd,
159+
stdout: "pipe",
160+
stderr: "ignore",
161+
maxBuffer: MAX_BUFFER_BYTES,
162+
})
163+
164+
const output = await new Response(proc.stdout).text()
165+
await proc.exited
166+
167+
if (proc.exitCode !== 0) {
161168
return []
162169
}
163170

164171
// Handle both Unix (\n) and Windows (\r\n) line endings
165-
const lines = searchResult.text().trim().split(/\r?\n/).filter(Boolean)
172+
const lines = output.trim().split(/\r?\n/).filter(Boolean)
166173

167174
return lines
168175
.map((line) => JSON.parse(line))

0 commit comments

Comments
 (0)