MCPcopy Create free account
hub / github.com/vercel/vercel / resolveCommandCandidate

Function resolveCommandCandidate

packages/cli-exec/src/lookup.ts:346–382  ·  view source on GitHub ↗

* 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
)

Source from the content-addressed store, hash-verified

344 * the installed `vercel` package so a spoofed shim cannot be invoked.
345 */
346async 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.

Callers 1

findCommandInPathFunction · 0.85

Calls 5

statFunction · 0.85
recordSkippedLocalBinFunction · 0.85
getLocalVercelPackageBinFunction · 0.85
isFileMethod · 0.45

Tested by

no test coverage detected