MCPcopy Index your code
hub / github.com/codeaashu/claude-code / normalizePatternToPath

Function normalizePatternToPath

src/utils/permissions/filesystem.ts:765–798  ·  view source on GitHub ↗
({
  patternRoot,
  pattern,
  rootPath,
}: {
  patternRoot: string
  pattern: string
  rootPath: string
})

Source from the content-addressed store, hash-verified

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

Callers 1

normalizePatternsToPathFunction · 0.85

Calls 1

prependDirSepFunction · 0.85

Tested by

no test coverage detected