(command: string)
| 12 | * @returns Promise<boolean> - true if the command exists, false otherwise |
| 13 | */ |
| 14 | export async function isBinaryInstalled(command: string): Promise<boolean> { |
| 15 | // Edge case: empty or whitespace-only command |
| 16 | if (!command || !command.trim()) { |
| 17 | logForDebugging('[binaryCheck] Empty command provided, returning false') |
| 18 | return false |
| 19 | } |
| 20 | |
| 21 | // Trim the command to handle whitespace |
| 22 | const trimmedCommand = command.trim() |
| 23 | |
| 24 | // Check cache first |
| 25 | const cached = binaryCache.get(trimmedCommand) |
| 26 | if (cached !== undefined) { |
| 27 | logForDebugging( |
| 28 | `[binaryCheck] Cache hit for '${trimmedCommand}': ${cached}`, |
| 29 | ) |
| 30 | return cached |
| 31 | } |
| 32 | |
| 33 | let exists = false |
| 34 | if (await which(trimmedCommand).catch(() => null)) { |
| 35 | exists = true |
| 36 | } |
| 37 | |
| 38 | // Cache the result |
| 39 | binaryCache.set(trimmedCommand, exists) |
| 40 | |
| 41 | logForDebugging( |
| 42 | `[binaryCheck] Binary '${trimmedCommand}' ${exists ? 'found' : 'not found'}`, |
| 43 | ) |
| 44 | |
| 45 | return exists |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Clear the binary check cache (useful for testing) |
no test coverage detected