( platform: NodeJS.Platform, currentPath: string | undefined, candidates: string[], )
| 1195 | } |
| 1196 | |
| 1197 | function findCommandOnPath( |
| 1198 | platform: NodeJS.Platform, |
| 1199 | currentPath: string | undefined, |
| 1200 | candidates: string[], |
| 1201 | ): string | null { |
| 1202 | const pathEntries = String(currentPath ?? '').split(path.delimiter).filter((entry) => entry.trim()); |
| 1203 | for (const entry of pathEntries) { |
| 1204 | for (const candidate of candidates) { |
| 1205 | const resolved = path.join(entry, candidate); |
| 1206 | if (fs.existsSync(resolved)) { |
| 1207 | return resolved; |
| 1208 | } |
| 1209 | } |
| 1210 | if (platform !== 'win32') { |
| 1211 | continue; |
| 1212 | } |
| 1213 | const normalizedCandidates = candidates.flatMap((candidate) => ( |
| 1214 | candidate.endsWith('.exe') || candidate.endsWith('.cmd') || candidate.endsWith('.bat') |
| 1215 | ? [candidate] |
| 1216 | : [`${candidate}.exe`, `${candidate}.cmd`, `${candidate}.bat`] |
| 1217 | )); |
| 1218 | for (const candidate of normalizedCandidates) { |
| 1219 | const resolved = path.join(entry, candidate); |
| 1220 | if (fs.existsSync(resolved)) { |
| 1221 | return resolved; |
| 1222 | } |
| 1223 | } |
| 1224 | } |
| 1225 | return null; |
| 1226 | } |
| 1227 | |
| 1228 | async function removeIfExists(filePath: string | null): Promise<void> { |
| 1229 | if (!filePath) { |
no outgoing calls
no test coverage detected