|
| 1 | +/** |
| 2 | + * AXe Helper Functions |
| 3 | + * |
| 4 | + * This utility module provides functions to work with the bundled AXe tool. |
| 5 | + * Always uses the bundled version to ensure consistency. |
| 6 | + */ |
| 7 | + |
| 8 | +import { existsSync } from 'fs'; |
| 9 | +import { dirname, join } from 'path'; |
| 10 | +import { fileURLToPath } from 'url'; |
| 11 | +import { createTextResponse } from './validation.js'; |
| 12 | +import { ToolResponse } from '../types/common.js'; |
| 13 | + |
| 14 | +// Get bundled AXe path - always use the bundled version for consistency |
| 15 | +const __filename = fileURLToPath(import.meta.url); |
| 16 | +const __dirname = dirname(__filename); |
| 17 | +// In the npm package, build/index.js is at the same level as bundled/ |
| 18 | +// So we go up one level from build/ to get to the package root |
| 19 | +const bundledAxePath = join(__dirname, '..', 'bundled', 'axe'); |
| 20 | + |
| 21 | +/** |
| 22 | + * Get the path to the bundled axe binary |
| 23 | + */ |
| 24 | +export function getAxePath(): string | null { |
| 25 | + // Always use bundled version for consistency |
| 26 | + if (existsSync(bundledAxePath)) { |
| 27 | + return bundledAxePath; |
| 28 | + } |
| 29 | + return null; |
| 30 | +} |
| 31 | + |
| 32 | +/** |
| 33 | + * Get environment variables needed for bundled AXe to run |
| 34 | + */ |
| 35 | +export function getBundledAxeEnvironment(): Record<string, string> { |
| 36 | + // No special environment variables needed - bundled AXe binary |
| 37 | + // has proper @rpath configuration to find frameworks |
| 38 | + return {}; |
| 39 | +} |
| 40 | + |
| 41 | +/** |
| 42 | + * Check if bundled axe tool is available |
| 43 | + */ |
| 44 | +export function areAxeToolsAvailable(): boolean { |
| 45 | + return getAxePath() !== null; |
| 46 | +} |
| 47 | + |
| 48 | +export function createAxeNotAvailableResponse(): ToolResponse { |
| 49 | + return createTextResponse( |
| 50 | + 'Bundled axe tool not found. UI automation features are not available.\n\n' + |
| 51 | + 'This is likely an installation issue with the npm package.\n' + |
| 52 | + 'Please reinstall xcodebuildmcp or report this issue.', |
| 53 | + true, |
| 54 | + ); |
| 55 | +} |
0 commit comments