( builtinPath: string, systemRgPath?: string | null, platform?: string, )
| 75 | * @param platform Override for `process.platform` (tests only). |
| 76 | */ |
| 77 | export function resolveBuiltinWithFallback( |
| 78 | builtinPath: string, |
| 79 | systemRgPath?: string | null, |
| 80 | platform?: string, |
| 81 | ): { |
| 82 | mode: 'system' | 'builtin' |
| 83 | command: string |
| 84 | args: string[] |
| 85 | note?: string |
| 86 | } { |
| 87 | const p = platform ?? process.platform |
| 88 | |
| 89 | // Builtin exists — use it, no note. |
| 90 | if (existsSync(builtinPath)) { |
| 91 | return { mode: 'builtin', command: builtinPath, args: [] } |
| 92 | } |
| 93 | |
| 94 | // Builtin missing — check system rg. |
| 95 | // When systemRgPath is explicitly passed (including null), use it directly. |
| 96 | // When undefined, call findExecutable (production path). |
| 97 | const resolvedSystem = |
| 98 | systemRgPath === undefined |
| 99 | ? findExecutable('rg', []).cmd |
| 100 | : (systemRgPath ?? 'rg') |
| 101 | if (resolvedSystem !== 'rg') { |
| 102 | return { |
| 103 | mode: 'system', |
| 104 | command: 'rg', |
| 105 | args: [], |
| 106 | note: `fallback: builtin rg unavailable on ${p}, using system rg`, |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | // Neither available. |
| 111 | return { |
| 112 | mode: 'builtin', |
| 113 | command: builtinPath, |
| 114 | args: [], |
| 115 | note: `no ripgrep available on ${p}; install ripgrep via apt/pkg/brew`, |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | export function ripgrepCommand(): { |
| 120 | rgPath: string |
no test coverage detected