Skip to content

Commit f15c62f

Browse files
committed
Revert brandon's change to npm-app/src/native/ripgrep.ts, which fixes code_search
1 parent 9fb72d3 commit f15c62f

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

npm-app/src/native/ripgrep.ts

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,51 @@
11
import { mkdirSync } from 'fs'
22
import path from 'path'
33

4+
import { rgPath as vscodeRgPath } from '@vscode/ripgrep'
45
import { spawnSync } from 'bun'
5-
import { getBundledRgPath } from '@codebuff/sdk'
66

77
import { CONFIG_DIR } from '../credentials'
88
import { logger } from '../utils/logger'
99

1010
const getRipgrepPath = async (): Promise<string> => {
11-
let bundledRgPath: string
12-
try {
13-
bundledRgPath = getBundledRgPath()
14-
} catch (error) {
15-
logger.error({ error }, 'Failed to resolve bundled ripgrep path')
16-
throw error
17-
}
18-
19-
// In dev mode, use the bundled path directly
11+
// In dev mode, use the vscode ripgrep binary
2012
if (!process.env.IS_BINARY) {
21-
return bundledRgPath
13+
return vscodeRgPath
2214
}
2315

24-
// Compiled mode - stage the bundled binary in the config directory
16+
// Compiled mode - self-extract the embedded binary
2517
const rgFileName = process.platform === 'win32' ? 'rg.exe' : 'rg'
2618
const outPath = path.join(CONFIG_DIR, rgFileName)
2719

20+
// Check if already extracted
21+
if (await Bun.file(outPath).exists()) {
22+
return outPath
23+
}
24+
25+
// Extract the embedded binary
2826
try {
29-
if (await Bun.file(outPath).exists()) {
30-
return outPath
31-
}
27+
// Use require() on a static string path to make sure rg is included in the compiled binary
28+
const embeddedRgPath =
29+
process.platform === 'win32'
30+
? require('../../../node_modules/@vscode/ripgrep/bin/rg.exe')
31+
: require('../../../node_modules/@vscode/ripgrep/bin/rg')
3232

33+
// Create cache directory
3334
mkdirSync(path.dirname(outPath), { recursive: true })
34-
await Bun.write(outPath, await Bun.file(bundledRgPath).arrayBuffer())
3535

36+
// Copy embedded binary to cache location
37+
await Bun.write(outPath, await Bun.file(embeddedRgPath).arrayBuffer())
38+
39+
// Make executable on Unix systems
3640
if (process.platform !== 'win32') {
3741
spawnSync(['chmod', '+x', outPath])
3842
}
3943

4044
return outPath
4145
} catch (error) {
42-
logger.error(
43-
{ error },
44-
'Failed to stage bundled ripgrep binary, using fallback path',
45-
)
46-
return bundledRgPath
46+
logger.error({ error }, 'Failed to extract ripgrep binary')
47+
// Fallback to vscode ripgrep if extraction fails
48+
return vscodeRgPath
4749
}
4850
}
4951

0 commit comments

Comments
 (0)