Files
claude-code/src/utils/binaryCheck.ts
claude-code-best 4aa15160e4 chore: 移除 binaryCheck/claudeAiLimits/codeIndexing 中未引用的导出
- binaryCheck.ts: 删除 clearBinaryCache(零调用,binaryCache 仍由 isBinaryInstalled 使用)
- claudeAiLimits.ts: 删除 RATE_LIMIT_DISPLAY_NAMES 常量 + getRateLimitDisplayName(互为唯一消费者)
- codeIndexing.ts: 删除 detectCodeIndexingFromMcpTool(同胞 detectCodeIndexingFromCommand/McpServerName 仍活跃)

Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
2026-06-20 12:39:27 +08:00

47 lines
1.3 KiB
TypeScript

import { logForDebugging } from './debug.js'
import { which } from './which.js'
// Session cache to avoid repeated checks
const 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 command
if (!command || !command.trim()) {
logForDebugging('[binaryCheck] Empty command provided, returning false')
return false
}
// Trim the command to handle whitespace
const trimmedCommand = command.trim()
// Check cache first
const cached = binaryCache.get(trimmedCommand)
if (cached !== undefined) {
logForDebugging(
`[binaryCheck] Cache hit for '${trimmedCommand}': ${cached}`,
)
return cached
}
let exists = false
if (await which(trimmedCommand).catch(() => null)) {
exists = true
}
// Cache the result
binaryCache.set(trimmedCommand, exists)
logForDebugging(
`[binaryCheck] Binary '${trimmedCommand}' ${exists ? 'found' : 'not found'}`,
)
return exists
}