Skip to content

Commit d7dfbf6

Browse files
committed
fix(ripgrep): evaluate npm_config_arch at call time in candidate paths
1 parent 0a57e84 commit d7dfbf6

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

src/core/environment/__tests__/getEnvironmentDetails.spec.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,17 @@ describe("getEnvironmentDetails", () => {
451451
// When ripgrep cannot be found (e.g. @vscode/ripgrep >=1.18 platform layout on
452452
// Windows), listFiles throws "Could not find ripgrep binary". getEnvironmentDetails
453453
// must not propagate this — the task should proceed to the API call, not hang at 0%.
454-
it("should not throw when listFiles rejects with ripgrep not found", async () => {
454+
it("should degrade gracefully when listFiles rejects with an Error", async () => {
455455
;(listFiles as Mock).mockRejectedValue(new Error("Could not find ripgrep binary"))
456456

457-
await expect(getEnvironmentDetails(mockCline as Task, true)).resolves.not.toThrow()
457+
const result = await getEnvironmentDetails(mockCline as Task, true)
458+
expect(result).toContain("File listing unavailable: Could not find ripgrep binary")
459+
})
460+
461+
it("should degrade gracefully when listFiles rejects with a non-Error value", async () => {
462+
;(listFiles as Mock).mockRejectedValue("unexpected string rejection")
463+
464+
const result = await getEnvironmentDetails(mockCline as Task, true)
465+
expect(result).toContain("File listing unavailable: unexpected string rejection")
458466
})
459467
})

src/services/ripgrep/index.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,6 @@ const binName = isWindows ? "rg.exe" : "rg"
5656
// bin/<platform>-<arch>/ rather than directly in bin/.
5757
const ripgrepUniversalBinDir = `bin/${process.platform}-${process.arch}`
5858

59-
// @vscode/ripgrep >=1.18 ships the binary in a platform-specific optional
60-
// package (e.g. @vscode/ripgrep-win32-x64). Matches the wrapper's own arch
61-
// selection: process.env.npm_config_arch || process.arch.
62-
const platformPkgArch = process.env.npm_config_arch || process.arch
63-
const ripgrepPlatformPkg = `@vscode/ripgrep-${process.platform}-${platformPkgArch}`
64-
6559
interface SearchFileResult {
6660
file: string
6761
searchResults: SearchResult[]
@@ -96,6 +90,9 @@ export function truncateLine(line: string, maxLength: number = MAX_LINE_LENGTH):
9690
* resolution) and the diagnostic command (existence report for all paths).
9791
*/
9892
export function ripgrepCandidatePaths(vscodeAppRoot: string): readonly string[] {
93+
// Read at call time so process.env.npm_config_arch overrides take effect,
94+
// matching @vscode/ripgrep's own arch selection logic.
95+
const platformPkg = `@vscode/ripgrep-${process.platform}-${process.env.npm_config_arch || process.arch}`
9996
return [
10097
path.join(vscodeAppRoot, "node_modules/@vscode/ripgrep/bin/", binName),
10198
path.join(vscodeAppRoot, "node_modules/vscode-ripgrep/bin", binName),
@@ -108,8 +105,8 @@ export function ripgrepCandidatePaths(vscodeAppRoot: string): readonly string[]
108105
binName,
109106
),
110107
// @vscode/ripgrep >=1.18 (VS Code 1.130+): binary lives in a platform-specific optional package.
111-
path.join(vscodeAppRoot, `node_modules/${ripgrepPlatformPkg}/bin`, binName),
112-
path.join(vscodeAppRoot, `node_modules.asar.unpacked/${ripgrepPlatformPkg}/bin`, binName),
108+
path.join(vscodeAppRoot, `node_modules/${platformPkg}/bin`, binName),
109+
path.join(vscodeAppRoot, `node_modules.asar.unpacked/${platformPkg}/bin`, binName),
113110
]
114111
}
115112

0 commit comments

Comments
 (0)