( patternsByRoot: Map<string | null, string[]>, root: string, )
| 808 | } |
| 809 | |
| 810 | export function normalizePatternsToPath( |
| 811 | patternsByRoot: Map<string | null, string[]>, |
| 812 | root: string, |
| 813 | ): string[] { |
| 814 | // null root means the pattern can match anywhere |
| 815 | const result = new Set(patternsByRoot.get(null) ?? []) |
| 816 | |
| 817 | for (const [patternRoot, patterns] of patternsByRoot.entries()) { |
| 818 | if (patternRoot === null) { |
| 819 | // already added |
| 820 | continue |
| 821 | } |
| 822 | |
| 823 | // Check each pattern to see if the full path starts with our reference root |
| 824 | for (const pattern of patterns) { |
| 825 | const normalizedPattern = normalizePatternToPath({ |
| 826 | patternRoot, |
| 827 | pattern, |
| 828 | rootPath: root, |
| 829 | }) |
| 830 | if (normalizedPattern) { |
| 831 | result.add(normalizedPattern) |
| 832 | } |
| 833 | } |
| 834 | } |
| 835 | return Array.from(result) |
| 836 | } |
| 837 | |
| 838 | /** |
| 839 | * Collects all deny rules for file read permissions and returns their ignore patterns |
no test coverage detected