MCPcopy Index your code
hub / github.com/npmx-dev/npmx.dev / getExecutableInfo

Function getExecutableInfo

app/utils/run-command.ts:28–61  ·  view source on GitHub ↗
(
  packageName: string,
  bin: string | Record<string, string> | undefined,
)

Source from the content-addressed store, hash-verified

26 * Handles both string format ("bin": "./cli.js") and object format ("bin": { "cmd": "./cli.js" }).
27 */
28export function getExecutableInfo(
29 packageName: string,
30 bin: string | Record<string, string> | undefined,
31): ExecutableInfo {
32 if (!bin) {
33 return { primaryCommand: '', commands: [], hasExecutable: false }
34 }
35
36 // String format: package name becomes the command
37 if (typeof bin === 'string') {
38 return {
39 primaryCommand: packageName,
40 commands: [packageName],
41 hasExecutable: true,
42 }
43 }
44
45 // Object format: keys are command names
46 const commands = Object.keys(bin)
47 const firstCommand = commands[0]
48 if (!firstCommand) {
49 return { primaryCommand: '', commands: [], hasExecutable: false }
50 }
51
52 // Prefer command matching package name if it exists; otherwise, use first
53 const baseName = getPackageBaseName(packageName)
54 const primaryCommand = baseName && commands.includes(baseName) ? baseName : firstCommand
55
56 return {
57 primaryCommand,
58 commands,
59 hasExecutable: true,
60 }
61}
62
63export interface RunCommandOptions {
64 packageName: string

Callers 1

Calls 1

getPackageBaseNameFunction · 0.85

Tested by

no test coverage detected