MCPcopy
hub / github.com/codeaashu/claude-code / resolveExcludePatterns

Function resolveExcludePatterns

src/utils/claudemd.ts:581–612  ·  view source on GitHub ↗

* Expands exclude patterns by resolving symlinks in absolute path prefixes. * For each absolute pattern (starting with /), tries to resolve the longest * existing directory prefix via realpathSync and adds the resolved version. * Glob patterns (containing *) have their static prefix resolved.

(patterns: string[])

Source from the content-addressed store, hash-verified

579 * Glob patterns (containing *) have their static prefix resolved.
580 */
581function resolveExcludePatterns(patterns: string[]): string[] {
582 const fs = getFsImplementation()
583 const expanded: string[] = patterns.map(p => p.replaceAll('\\', '/'))
584
585 for (const normalized of expanded) {
586 // Only resolve absolute patterns — glob-only patterns like "**/*.md" don't have
587 // a filesystem prefix to resolve
588 if (!normalized.startsWith('/')) {
589 continue
590 }
591
592 // Find the static prefix before any glob characters
593 const globStart = normalized.search(/[*?{[]/)
594 const staticPrefix =
595 globStart === -1 ? normalized : normalized.slice(0, globStart)
596 const dirToResolve = dirname(staticPrefix)
597
598 try {
599 // sync IO: called from sync context (isClaudeMdExcluded -> processMemoryFile -> getMemoryFiles)
600 const resolvedDir = fs.realpathSync(dirToResolve).replaceAll('\\', '/')
601 if (resolvedDir !== dirToResolve) {
602 const resolvedPattern =
603 resolvedDir + normalized.slice(dirToResolve.length)
604 expanded.push(resolvedPattern)
605 }
606 } catch {
607 // Directory doesn't exist; skip resolution for this pattern
608 }
609 }
610
611 return expanded
612}
613
614/**
615 * Recursively processes a memory file and all its @include references

Callers 1

isClaudeMdExcludedFunction · 0.85

Calls 3

getFsImplementationFunction · 0.85
searchMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected