| 208 | /* 8. Unified runtime loader */ |
| 209 | /* ------------------------------------------------------------------ */ |
| 210 | class UnifiedLanguageLoader implements RuntimeLanguageLoader { |
| 211 | private parserReady: Promise<void> |
| 212 | |
| 213 | constructor() { |
| 214 | this.parserReady = initTreeSitterForNode() |
| 215 | } |
| 216 | |
| 217 | async initParser(): Promise<void> { |
| 218 | await this.parserReady |
| 219 | } |
| 220 | |
| 221 | async loadLanguage(wasmFile: string): Promise<Language> { |
| 222 | // Resolve WASM file path |
| 223 | let wasmPath = resolveWasmPath(wasmFile) |
| 224 | |
| 225 | // Try to load the language using Node.js-specific method if available |
| 226 | let lang: Language |
| 227 | try { |
| 228 | lang = await Language.load(wasmPath) |
| 229 | } catch (err) { |
| 230 | // Fallback: try resolving from the original package (development) |
| 231 | const fallbackPath = tryResolveFromPackage(wasmFile) |
| 232 | if (fallbackPath) { |
| 233 | lang = await Language.load(fallbackPath) |
| 234 | } else { |
| 235 | throw err |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | return lang |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | /* ------------------------------------------------------------------ */ |
| 244 | /* 9. Helper functions */ |
nothing calls this directly
no outgoing calls
no test coverage detected