( filePath: string, runtimeLoader: RuntimeLanguageLoader, )
| 254 | /* 10. Language configuration loader */ |
| 255 | /* ------------------------------------------------------------------ */ |
| 256 | export async function createLanguageConfig( |
| 257 | filePath: string, |
| 258 | runtimeLoader: RuntimeLanguageLoader, |
| 259 | ): Promise<LanguageConfig | undefined> { |
| 260 | const cfg = findLanguageConfigByExtension(filePath) |
| 261 | if (!cfg) { |
| 262 | return undefined |
| 263 | } |
| 264 | |
| 265 | if (!cfg.parser) { |
| 266 | try { |
| 267 | await runtimeLoader.initParser() |
| 268 | |
| 269 | // Load the language using the runtime-specific loader |
| 270 | const lang = await runtimeLoader.loadLanguage(cfg.wasmFile) |
| 271 | |
| 272 | // Create parser and query |
| 273 | const parser = new Parser() |
| 274 | parser.setLanguage(lang) |
| 275 | |
| 276 | // When loaded with bun, the queryText is a path to the file, not the content of the file. |
| 277 | const queryContent = path.isAbsolute(cfg.queryPathOrContent) |
| 278 | ? fs.readFileSync(cfg.queryPathOrContent, 'utf8') |
| 279 | : cfg.queryPathOrContent |
| 280 | |
| 281 | cfg.language = lang |
| 282 | cfg.parser = parser |
| 283 | cfg.query = new Query(lang, queryContent) |
| 284 | } catch (err) { |
| 285 | // Let the runtime-specific implementation handle error logging |
| 286 | throw err |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | return cfg |
| 291 | } |
| 292 | |
| 293 | /* ------------------------------------------------------------------ */ |
| 294 | /* 11. Public API */ |
no test coverage detected