* Resolves the first usable command from PATH, validating local bins specially.
( command: string, pathValue: string, cwd: string, localBinSearch: LocalBinSearch, diagnostics: ResolutionDiagnostics )
| 228 | * Resolves the first usable command from PATH, validating local bins specially. |
| 229 | */ |
| 230 | async function findCommandInPath( |
| 231 | command: string, |
| 232 | pathValue: string, |
| 233 | cwd: string, |
| 234 | localBinSearch: LocalBinSearch, |
| 235 | diagnostics: ResolutionDiagnostics |
| 236 | ): Promise<ResolvedCommand | null> { |
| 237 | for (const directory of splitPath(pathValue)) { |
| 238 | const candidate = getPathCommandCandidate(directory, command, cwd); |
| 239 | |
| 240 | try { |
| 241 | const canAccess = await canAccessCommandCandidate( |
| 242 | candidate, |
| 243 | localBinSearch, |
| 244 | diagnostics |
| 245 | ); |
| 246 | |
| 247 | if (canAccess) { |
| 248 | const resolvedCommand = await resolveCommandCandidate( |
| 249 | command, |
| 250 | candidate, |
| 251 | localBinSearch, |
| 252 | diagnostics |
| 253 | ); |
| 254 | |
| 255 | if (resolvedCommand) { |
| 256 | return resolvedCommand; |
| 257 | } |
| 258 | } |
| 259 | } catch { |
| 260 | // The candidate can change between access, stat, and realpath. Treat it |
| 261 | // like an unusable PATH entry and keep searching. |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | return null; |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * Builds an absolute candidate path for one PATH entry and command name. |
no test coverage detected