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

Function resolveCliInvocation

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

* Resolves the CLI invocation from local bins first, then the provided PATH.

(
  cwd: string,
  pathValue: string
)

Source from the content-addressed store, hash-verified

177 * Resolves the CLI invocation from local bins first, then the provided PATH.
178 */
179async function resolveCliInvocation(
180 cwd: string,
181 pathValue: string
182): Promise<VercelCliResolution> {
183 const localBinSearch = await getLocalBinSearch(cwd);
184 const diagnostics: ResolutionDiagnostics = {
185 localBinSearch: localBinSearch.diagnostics,
186 skippedLocalBins: [],
187 };
188 const resolvedPath = prependPathEntries(
189 pathValue,
190 localBinSearch.directories
191 );
192
193 for (const command of getVercelCommandNames()) {
194 const resolvedCommand = await findCommandInPath(
195 command,
196 resolvedPath,
197 cwd,
198 localBinSearch,
199 diagnostics
200 );
201 if (!resolvedCommand) {
202 continue;
203 }
204
205 if (isNodeScript(resolvedCommand.realPath)) {
206 return {
207 found: true,
208 command: process.execPath,
209 commandArgs: [resolvedCommand.realPath],
210 source: resolvedCommand.source,
211 diagnostics,
212 };
213 }
214
215 return {
216 found: true,
217 command: resolvedCommand.realPath,
218 commandArgs: [],
219 source: resolvedCommand.source,
220 diagnostics,
221 };
222 }
223
224 return { found: false, diagnostics };
225}
226
227/**
228 * Resolves the first usable command from PATH, validating local bins specially.

Callers 1

Calls 5

prependPathEntriesFunction · 0.90
isNodeScriptFunction · 0.90
getLocalBinSearchFunction · 0.85
getVercelCommandNamesFunction · 0.85
findCommandInPathFunction · 0.85

Tested by

no test coverage detected