* Used by processMemoryFile → getMemoryFiles so the event loop stays * responsive during the directory walk (many readFile attempts, most * ENOENT). When includeBasePath is given, @include paths are resolved in * the same lex pass and returned alongside the parsed file.
( filePath: string, type: MemoryType, includeBasePath?: string, )
| 422 | * the same lex pass and returned alongside the parsed file. |
| 423 | */ |
| 424 | async function safelyReadMemoryFileAsync( |
| 425 | filePath: string, |
| 426 | type: MemoryType, |
| 427 | includeBasePath?: string, |
| 428 | ): Promise<{ info: MemoryFileInfo | null; includePaths: string[] }> { |
| 429 | try { |
| 430 | const fs = getFsImplementation() |
| 431 | const rawContent = await fs.readFile(filePath, { encoding: 'utf-8' }) |
| 432 | return parseMemoryFileContent(rawContent, filePath, type, includeBasePath) |
| 433 | } catch (error) { |
| 434 | handleMemoryFileReadError(error, filePath) |
| 435 | return { info: null, includePaths: [] } |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | type MarkdownToken = { |
| 440 | type: string |
no test coverage detected