* 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, )
| 428 | * the same lex pass and returned alongside the parsed file. |
| 429 | */ |
| 430 | async function safelyReadMemoryFileAsync( |
| 431 | filePath: string, |
| 432 | type: MemoryType, |
| 433 | includeBasePath?: string, |
| 434 | ): Promise<{ info: MemoryFileInfo | null; includePaths: string[] }> { |
| 435 | try { |
| 436 | const fs = getFsImplementation() |
| 437 | const rawContent = await fs.readFile(filePath, { encoding: 'utf-8' }) |
| 438 | const { |
| 439 | content: sanitizedContent, |
| 440 | stripped: strippedOperationalSections, |
| 441 | } = stripOperationalProjectInstructions(rawContent, filePath, type) |
| 442 | const parsed = parseMemoryFileContent( |
| 443 | sanitizedContent, |
| 444 | filePath, |
| 445 | type, |
| 446 | includeBasePath, |
| 447 | ) |
| 448 | |
| 449 | if (parsed.info && strippedOperationalSections) { |
| 450 | parsed.info.contentDiffersFromDisk = true |
| 451 | parsed.info.rawContent = rawContent |
| 452 | } |
| 453 | |
| 454 | return parsed |
| 455 | } catch (error) { |
| 456 | handleMemoryFileReadError(error, filePath) |
| 457 | return { info: null, includePaths: [] } |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | type MarkdownToken = { |
| 462 | type: string |
no test coverage detected