MCPcopy Create free account
hub / github.com/Noumena-Network/code / normalizePatternToPath

Function normalizePatternToPath

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

Source from the content-addressed store, hash-verified

773}
774
775function 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
810export function normalizePatternsToPath(
811 patternsByRoot: Map<string | null, string[]>,

Callers 1

normalizePatternsToPathFunction · 0.85

Calls 1

prependDirSepFunction · 0.85

Tested by

no test coverage detected