({
rulesDir,
type,
processedPaths,
includeExternal,
conditionalRule,
visitedDirs = new Set(),
}: {
rulesDir: string
type: MemoryType
processedPaths: Set<string>
includeExternal: boolean
conditionalRule: boolean
visitedDirs?: Set<string>
})
| 695 | * @returns Array of MemoryFileInfo objects |
| 696 | */ |
| 697 | export async function processMdRules({ |
| 698 | rulesDir, |
| 699 | type, |
| 700 | processedPaths, |
| 701 | includeExternal, |
| 702 | conditionalRule, |
| 703 | visitedDirs = new Set(), |
| 704 | }: { |
| 705 | rulesDir: string |
| 706 | type: MemoryType |
| 707 | processedPaths: Set<string> |
| 708 | includeExternal: boolean |
| 709 | conditionalRule: boolean |
| 710 | visitedDirs?: Set<string> |
| 711 | }): Promise<MemoryFileInfo[]> { |
| 712 | if (visitedDirs.has(rulesDir)) { |
| 713 | return [] |
| 714 | } |
| 715 | |
| 716 | try { |
| 717 | const fs = getFsImplementation() |
| 718 | |
| 719 | const { resolvedPath: resolvedRulesDir, isSymlink } = safeResolvePath( |
| 720 | fs, |
| 721 | rulesDir, |
| 722 | ) |
| 723 | |
| 724 | visitedDirs.add(rulesDir) |
| 725 | if (isSymlink) { |
| 726 | visitedDirs.add(resolvedRulesDir) |
| 727 | } |
| 728 | |
| 729 | const result: MemoryFileInfo[] = [] |
| 730 | let entries: import('fs').Dirent[] |
| 731 | try { |
| 732 | entries = await fs.readdir(resolvedRulesDir) |
| 733 | } catch (e: unknown) { |
| 734 | const code = getErrnoCode(e) |
| 735 | if (code === 'ENOENT' || code === 'EACCES' || code === 'ENOTDIR') { |
| 736 | return [] |
| 737 | } |
| 738 | throw e |
| 739 | } |
| 740 | |
| 741 | for (const entry of entries) { |
| 742 | const entryPath = join(rulesDir, entry.name) |
| 743 | const { resolvedPath: resolvedEntryPath, isSymlink } = safeResolvePath( |
| 744 | fs, |
| 745 | entryPath, |
| 746 | ) |
| 747 | |
| 748 | // Use Dirent methods for non-symlinks to avoid extra stat calls. |
| 749 | // For symlinks, we need stat to determine what the target is. |
| 750 | const stats = isSymlink ? await fs.stat(resolvedEntryPath) : null |
| 751 | const isDirectory = stats ? stats.isDirectory() : entry.isDirectory() |
| 752 | const isFile = stats ? stats.isFile() : entry.isFile() |
| 753 | |
| 754 | if (isDirectory) { |
no test coverage detected