( packageName: string, bin: string | Record<string, string> | undefined, )
| 26 | * Handles both string format ("bin": "./cli.js") and object format ("bin": { "cmd": "./cli.js" }). |
| 27 | */ |
| 28 | export 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 | |
| 63 | export interface RunCommandOptions { |
| 64 | packageName: string |
no test coverage detected