Home / Function/ buildIgnoreFilter() — mcp Function Reference

buildIgnoreFilter() — mcp Function Reference

Architecture documentation for the buildIgnoreFilter() function in zip-repository.ts from the mcp codebase.

Entity Profile

Dependency Diagram

graph TD
  44adfa8b_2ebc_f147_11ab_97c37a623907["buildIgnoreFilter()"]
  52a097f2_598d_df67_e422_55b20a202d95["zipRepository()"]
  52a097f2_598d_df67_e422_55b20a202d95 -->|calls| 44adfa8b_2ebc_f147_11ab_97c37a623907
  b8971bfc_ba3c_23a9_1f17_5d613ac67105["debug()"]
  44adfa8b_2ebc_f147_11ab_97c37a623907 -->|calls| b8971bfc_ba3c_23a9_1f17_5d613ac67105
  dde30444_a7df_fa00_0129_12e7f409e2e4["findGitignoreFiles()"]
  44adfa8b_2ebc_f147_11ab_97c37a623907 -->|calls| dde30444_a7df_fa00_0129_12e7f409e2e4
  dfe11f52_4dd3_db89_9717_941d05bae091["warn()"]
  44adfa8b_2ebc_f147_11ab_97c37a623907 -->|calls| dfe11f52_4dd3_db89_9717_941d05bae091
  7676d97e_3407_e9fb_36e4_f3398b574ec2["error()"]
  44adfa8b_2ebc_f147_11ab_97c37a623907 -->|calls| 7676d97e_3407_e9fb_36e4_f3398b574ec2
  style 44adfa8b_2ebc_f147_11ab_97c37a623907 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/utils/zip-repository.ts lines 423–515

async function buildIgnoreFilter(
  rootDir: string,
  additionalExclusions: string[] = [],
  includeGitignore: boolean = true
): Promise<Ignore> {
  const ig = ignore();

  // Add standard exclusions
  ig.add(STANDARD_EXCLUSIONS);

  // Add custom exclusions
  if (additionalExclusions.length > 0) {
    ig.add(additionalExclusions);
  }

  // Exclude .gitignore files if requested
  if (includeGitignore === false) {
    ig.add(['.gitignore', '**/.gitignore']);
    logger.debug('Excluding .gitignore files from archive');
  }

  // Recursively find and parse all .gitignore files
  const gitignoreFiles = await findGitignoreFiles(rootDir);

  for (const gitignorePath of gitignoreFiles) {
    try {
      const gitignoreContent = await fs.readFile(gitignorePath, 'utf-8');
      const patterns = gitignoreContent
        .split('\n')
        .map(line => line.trim())
        .filter(line => line && !line.startsWith('#'));

      if (patterns.length > 0) {
        // Get the directory containing this .gitignore
        const gitignoreDir = gitignorePath.substring(0, gitignorePath.length - '.gitignore'.length);
        const relativeDir = relative(rootDir, gitignoreDir);

        // Scope patterns to their directory
        const scopedPatterns = patterns.map(pattern => {
          // If pattern starts with '/', it's relative to the .gitignore location
          if (pattern.startsWith('/')) {
            const patternWithoutSlash = pattern.substring(1);
            return relativeDir ? `${relativeDir}/${patternWithoutSlash}` : patternWithoutSlash;
          }
          // If pattern starts with '!', handle negation
          else if (pattern.startsWith('!')) {
            const negatedPattern = pattern.substring(1);
            if (negatedPattern.startsWith('/')) {
              const patternWithoutSlash = negatedPattern.substring(1);
              return relativeDir ? `!${relativeDir}/${patternWithoutSlash}` : `!${patternWithoutSlash}`;
            }
            // For non-rooted negation patterns, prefix with directory
            return relativeDir ? `!${relativeDir}/${negatedPattern}` : `!${negatedPattern}`;
          }
          // For non-rooted patterns, prefix with the directory path
          else {
            return relativeDir ? `${relativeDir}/${pattern}` : pattern;
          }
        });

        ig.add(scopedPatterns);

        const location = relativeDir ? `in ${relativeDir}/` : 'in root';
        logger.debug(`Loaded .gitignore ${location} with ${patterns.length} patterns`);
      }
    } catch (error: any) {
      if (error.code !== 'ENOENT') {
        logger.warn('Failed to read .gitignore at', gitignorePath, ':', error.message);
      }
    }
  }

  // Parse .dockerignore in root
  const dockerignorePath = join(rootDir, '.dockerignore');
  try {
    const dockerignoreContent = await fs.readFile(dockerignorePath, 'utf-8');
    const patterns = dockerignoreContent
      .split('\n')
      .map(line => line.trim())
      .filter(line => line && !line.startsWith('#'));

    if (patterns.length > 0) {
      ig.add(patterns);
      console.error('[DEBUG] Loaded .dockerignore with', patterns.length, 'patterns');
    }
  } catch (error: any) {
    if (error.code !== 'ENOENT') {
      console.error('[WARN] Failed to read .dockerignore:', error.message);
    }
  }

  return ig;
}

Subdomains

Called By

Frequently Asked Questions

What does buildIgnoreFilter() do?
buildIgnoreFilter() is a function in the mcp codebase.
What does buildIgnoreFilter() call?
buildIgnoreFilter() calls 4 function(s): debug, error, findGitignoreFiles, warn.
What calls buildIgnoreFilter()?
buildIgnoreFilter() is called by 1 function(s): zipRepository.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free