(wasmPath?: string)
| 61 | } |
| 62 | |
| 63 | static async load(wasmPath?: string): Promise<Ghostty> { |
| 64 | // If explicit path provided, use it |
| 65 | if (wasmPath) { |
| 66 | return Ghostty.loadFromPath(wasmPath); |
| 67 | } |
| 68 | |
| 69 | // Resolve path relative to this module |
| 70 | const moduleUrl = new URL('../ghostty-vt.wasm', import.meta.url); |
| 71 | |
| 72 | // Build paths to try, prioritizing file system paths for Node/Bun |
| 73 | const defaultPaths: string[] = []; |
| 74 | |
| 75 | // For Node/Bun: try absolute file path first (strip file:// protocol) |
| 76 | if (moduleUrl.protocol === 'file:') { |
| 77 | let filePath = moduleUrl.pathname; |
| 78 | // Remove leading slash on Windows paths (e.g., /C:/ -> C:/) |
| 79 | if (filePath.match(/^\/[A-Za-z]:\//)) { |
| 80 | filePath = filePath.slice(1); |
| 81 | } |
| 82 | defaultPaths.push(filePath); |
| 83 | } |
| 84 | |
| 85 | // Also try other common paths |
| 86 | defaultPaths.push(moduleUrl.href, './ghostty-vt.wasm', '/ghostty-vt.wasm'); |
| 87 | |
| 88 | let lastError: Error | null = null; |
| 89 | for (const path of defaultPaths) { |
| 90 | try { |
| 91 | return await Ghostty.loadFromPath(path); |
| 92 | } catch (e) { |
| 93 | lastError = e instanceof Error ? e : new Error(String(e)); |
| 94 | } |
| 95 | } |
| 96 | throw lastError || new Error('Failed to load Ghostty WASM'); |
| 97 | } |
| 98 | |
| 99 | private static async loadFromPath(path: string): Promise<Ghostty> { |
| 100 | let wasmBytes: ArrayBuffer | undefined; |
no test coverage detected