import { logForDebugging } from './debug.js'import { which } from './which.js'// Session cache to avoid repeated checksconst binaryCache = new Map<string, boolean>()/*** Check if a binary/command is installed and available on the system.* Uses 'which' on Unix systems (macOS, Linux, WSL) and 'where' on Windows.** @param command - The command name to check (e.g., 'gopls', 'rust-analyzer')* @returns Promise<boolean> - true if the command exists, false otherwise*/export async function isBinaryInstalled(command: string): Promise<boolean> {// Edge case: empty or whitespace-only commandif (!command || !command.trim()) {logForDebugging('[binaryCheck] Empty command provided, returning false')return false}// Trim the command to handle whitespaceconst trimmedCommand = command.trim()// Check cache firstconst cached = binaryCache.get(trimmedCommand)if (cached !== undefined) {logForDebugging(`[binaryCheck] Cache hit for '${trimmedCommand}': ${cached}`,)return cached}let exists = falseif (await which(trimmedCommand).catch(() => null)) {exists = true}// Cache the resultbinaryCache.set(trimmedCommand, exists)logForDebugging(`[binaryCheck] Binary '${trimmedCommand}' ${exists ? 'found' : 'not found'}`,)return exists}/*** Clear the binary check cache (useful for testing)*/export function clearBinaryCache(): void {binaryCache.clear()}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。