* Global candidates can be returned directly. Local bins must resolve through * the installed `vercel` package so a spoofed shim cannot be invoked.
( command: string, candidate: string, localBinSearch: LocalBinSearch, diagnostics: ResolutionDiagnostics )
| 344 | * the installed `vercel` package so a spoofed shim cannot be invoked. |
| 345 | */ |
| 346 | async function resolveCommandCandidate( |
| 347 | command: string, |
| 348 | candidate: string, |
| 349 | localBinSearch: LocalBinSearch, |
| 350 | diagnostics: ResolutionDiagnostics |
| 351 | ): Promise<ResolvedCommand | null> { |
| 352 | if (!(await stat(candidate)).isFile()) { |
| 353 | return null; |
| 354 | } |
| 355 | |
| 356 | const realPath = await realpath(candidate); |
| 357 | const localBinCandidate = await classifyPathLocalBinCandidate( |
| 358 | candidate, |
| 359 | localBinSearch.directories |
| 360 | ); |
| 361 | |
| 362 | if (!localBinCandidate) { |
| 363 | return { realPath, source: 'path' }; |
| 364 | } |
| 365 | |
| 366 | if ('reason' in localBinCandidate) { |
| 367 | recordSkippedLocalBin(diagnostics, candidate, localBinCandidate.reason); |
| 368 | return null; |
| 369 | } |
| 370 | |
| 371 | const localPackageBinResult = await getLocalVercelPackageBin( |
| 372 | command, |
| 373 | localBinCandidate.directory |
| 374 | ); |
| 375 | |
| 376 | if ('reason' in localPackageBinResult) { |
| 377 | recordSkippedLocalBin(diagnostics, candidate, localPackageBinResult.reason); |
| 378 | return null; |
| 379 | } |
| 380 | |
| 381 | return { realPath: localPackageBinResult.binPath, source: 'local-bin' }; |
| 382 | } |
| 383 | |
| 384 | /** |
| 385 | * Adds a rejected local bin candidate to lookup diagnostics. |
no test coverage detected