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

Function findCommandInPath

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

* Resolves the first usable command from PATH, validating local bins specially.

(
  command: string,
  pathValue: string,
  cwd: string,
  localBinSearch: LocalBinSearch,
  diagnostics: ResolutionDiagnostics
)

Source from the content-addressed store, hash-verified

228 * Resolves the first usable command from PATH, validating local bins specially.
229 */
230async 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.

Callers 1

resolveCliInvocationFunction · 0.85

Calls 4

splitPathFunction · 0.90
getPathCommandCandidateFunction · 0.85
resolveCommandCandidateFunction · 0.85

Tested by

no test coverage detected