Skip to content

Commit 5f02967

Browse files
committed
chore(npm-app): drop ripgrep dependency
1 parent 96b5c02 commit 5f02967

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

bun.lock

Lines changed: 9 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

npm-app/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"@codebuff/common": "workspace:*",
3939
"@types/diff": "8.0.0",
4040
"@types/micromatch": "^4.0.9",
41-
"@vscode/ripgrep": "1.15.9",
4241
"ai": "5.0.0",
4342
"axios": "1.7.4",
4443
"cli-highlight": "^2.1.11",

npm-app/src/native/ripgrep.ts

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

4-
import { rgPath as vscodeRgPath } from '@vscode/ripgrep'
54
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-
// In dev mode, use the vscode ripgrep binary
11+
let bundledRgPath: string
12+
try {
13+
bundledRgPath = getBundledRgPath(import.meta.url)
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
1220
if (!process.env.IS_BINARY) {
13-
return vscodeRgPath
21+
return bundledRgPath
1422
}
1523

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

20-
// Check if already extracted
21-
if (await Bun.file(outPath).exists()) {
22-
return outPath
23-
}
24-
25-
// Extract the embedded binary
2628
try {
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')
29+
if (await Bun.file(outPath).exists()) {
30+
return outPath
31+
}
3232

33-
// Create cache directory
3433
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
4036
if (process.platform !== 'win32') {
4137
spawnSync(['chmod', '+x', outPath])
4238
}
4339

4440
return outPath
4541
} catch (error) {
46-
logger.error({ error }, 'Failed to extract ripgrep binary')
47-
// Fallback to vscode ripgrep if extraction fails
48-
return vscodeRgPath
42+
logger.error(
43+
{ error },
44+
'Failed to stage bundled ripgrep binary, using fallback path',
45+
)
46+
return bundledRgPath
4947
}
5048
}
5149

0 commit comments

Comments
 (0)