({
patternRoot,
pattern,
rootPath,
}: {
patternRoot: string
pattern: string
rootPath: string
})
| 773 | } |
| 774 | |
| 775 | function normalizePatternToPath({ |
| 776 | patternRoot, |
| 777 | pattern, |
| 778 | rootPath, |
| 779 | }: { |
| 780 | patternRoot: string |
| 781 | pattern: string |
| 782 | rootPath: string |
| 783 | }): string | null { |
| 784 | // If the pattern root + pattern combination starts with our reference root |
| 785 | const fullPattern = posix.join(patternRoot, pattern) |
| 786 | if (patternRoot === rootPath) { |
| 787 | // If the pattern root exactly matches our reference root no need to change |
| 788 | return prependDirSep(pattern) |
| 789 | } else if (fullPattern.startsWith(`${rootPath}${DIR_SEP}`)) { |
| 790 | // Extract the relative part |
| 791 | const relativePart = fullPattern.slice(rootPath.length) |
| 792 | return prependDirSep(relativePart) |
| 793 | } else { |
| 794 | // Handle patterns that are inside the reference root but not starting with it |
| 795 | const relativePath = posix.relative(rootPath, patternRoot) |
| 796 | if ( |
| 797 | !relativePath || |
| 798 | relativePath.startsWith(`..${DIR_SEP}`) || |
| 799 | relativePath === '..' |
| 800 | ) { |
| 801 | // Pattern is outside the reference root, so it can be skipped |
| 802 | return null |
| 803 | } else { |
| 804 | const relativePattern = posix.join(relativePath, pattern) |
| 805 | return prependDirSep(relativePattern) |
| 806 | } |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | export function normalizePatternsToPath( |
| 811 | patternsByRoot: Map<string | null, string[]>, |
no test coverage detected