/** * @fileoverview File discovery and filtering with pattern support * * Provides file discovery capabilities with include/exclude pattern filtering, * gitignore integration, performance optimization through caching, and * comprehensive pattern analysis and validation. * * @example * ```typescript * // Basic file discovery * const files = await FileDiscovery.discoverFiles('/path/to/project'); * * // With include/exclude patterns * const filteredFiles = await FileDiscovery.discoverFiles('/path/to/project', { * include: ['src/**'], * exclude: ['**\/*.test.ts'] * }); * * // With verbose logging * const verboseFiles = await FileDiscovery.discoverFilesWithVerbose( * '/path/to/project', * { include: ['src/**'] }, * true * ); * ``` */ import type { FilterOptions } from '../types/index.js'; import type { PatternWarning } from '../utils/pattern-analysis.js'; export declare class FileDiscovery { private static readonly SUPPORTED_EXTENSIONS; private static readonly EXCLUDED_DIRS; /** * Validate filter options patterns * @private */ private static validateFilterOptions; /** * Discover all TypeScript/JavaScript files in the project with analysis * * @param rootPath - Root directory to scan (absolute or relative path) * @param options - Optional filtering options with include/exclude patterns * @param options.include - Array of glob patterns to include files (OR logic) * @param options.exclude - Array of glob patterns to exclude files (OR logic) * @returns Promise resolving to object containing file paths and pattern analysis * * @example * ```typescript * const { files, analysis } = await FileDiscovery.discoverFilesWithAnalysis('/project', { * include: ['src/**'], * exclude: ['**\/*.test.ts'] * }); * * console.log(`Found ${files.length} files`); * console.log(`Warnings: ${analysis.warnings.length}`); * ``` * * @throws {InvalidPatternSyntaxError} When glob patterns are malformed * @throws {SecurityViolationError} When patterns contain dangerous sequences * @throws {PatternConflictError} When patterns result in no files */ static discoverFilesWithAnalysis(rootPath: string, options?: FilterOptions): Promise<{ files: string[]; analysis: { warnings: PatternWarning[]; suggestions: string[]; stats: { totalCandidateFiles: number; includedFiles: number; finalFiles: number; excludedFiles: number; }; }; }>; /** * Discover all TypeScript/JavaScript files in the project with verbose logging * * @param rootPath - Root directory to scan (absolute or relative path) * @param options - Optional filtering options with include/exclude patterns * @param options.include - Array of glob patterns to include files * @param options.exclude - Array of glob patterns to exclude files * @param verbose - Enable detailed pattern matching logging to console * @returns Promise resolving to array of file paths relative to root * * @example * ```typescript * // Enable verbose logging to see pattern evaluation details * const files = await FileDiscovery.discoverFilesWithVerbose('/project', { * include: ['src/**'], * exclude: ['**\/*.test.ts'] * }, true); * * // Logs will show individual file evaluation details * ``` * * @throws {InvalidPatternSyntaxError} When glob patterns are malformed * @throws {SecurityViolationError} When patterns contain dangerous sequences */ static discoverFilesWithVerbose(rootPath: string, options?: FilterOptions, verbose?: boolean): Promise; /** * Discover all TypeScript/JavaScript files in the project * * Main method for file discovery with pattern filtering support. Applies include * patterns first, then exclude patterns, and finally gitignore rules. * * @param rootPath - Root directory to scan (absolute or relative path) * @param options - Optional filtering options with include/exclude patterns * @param options.include - Array of glob patterns to include files (defaults to all supported files) * @param options.exclude - Array of glob patterns to exclude files (empty by default) * @returns Promise resolving to array of file paths relative to root, sorted alphabetically * * @example * ```typescript * // Basic usage - all supported files * const allFiles = await FileDiscovery.discoverFiles('/project'); * * // With include patterns * const srcFiles = await FileDiscovery.discoverFiles('/project', { * include: ['src/**\/*.ts', 'lib/**\/*.ts'] * }); * * // With include and exclude patterns * const prodFiles = await FileDiscovery.discoverFiles('/project', { * include: ['src/**'], * exclude: ['**\/*.test.ts', '**\/*.spec.ts'] * }); * ``` * * @throws {InvalidPatternSyntaxError} When glob patterns are malformed * @throws {SecurityViolationError} When patterns contain dangerous sequences * @throws {PatternConflictError} When patterns result in no files being selected * @throws {FileSystemError} When file system operations fail */ static discoverFiles(rootPath: string, options?: FilterOptions): Promise; /** * Create standardized glob options for file discovery * @param absoluteRoot - Absolute root directory path * @returns Configured glob options object */ private static createGlobOptions; /** * Load and parse .gitignore files * @param rootPath - Root directory path * @returns Ignore instance with loaded rules */ private static loadIgnoreRules; /** * Normalize glob patterns to ensure directory patterns work correctly * Converts bare directory names like "examples" to "examples/**" * Also converts directory paths like "src/core" to "src/core/**" * * @param patterns - Array of glob patterns to normalize * @returns Normalized patterns that will match files */ static normalizePatterns(patterns: string[]): string[]; /** * Apply ignore rules to file list * @param files - Array of file paths * @param ignoreRules - Ignore instance with rules * @returns Filtered array of file paths */ private static applyIgnoreRules; /** * Check if a file has a supported extension * * @param filePath - File path to check (absolute or relative) * @returns True if file has a supported extension (.ts, .tsx, .js, .jsx) * * @example * ```typescript * FileDiscovery.isSupportedFile('src/app.ts'); // true * FileDiscovery.isSupportedFile('src/app.py'); // false * FileDiscovery.isSupportedFile('README.md'); // false * ``` */ static isSupportedFile(filePath: string): boolean; /** * Get supported file extensions * * @returns Array of supported extensions: ['.ts', '.tsx', '.js', '.jsx'] * * @example * ```typescript * const extensions = FileDiscovery.getSupportedExtensions(); * console.log(extensions); // ['.ts', '.tsx', '.js', '.jsx'] * ``` */ static getSupportedExtensions(): string[]; /** * Get pattern cache statistics for performance monitoring * * @returns Object containing cache statistics with hit rates and sizes for different cache types * @returns returns.glob - Glob pattern cache statistics * @returns returns.ignore - Ignore pattern cache statistics * @returns returns.combined - Combined cache statistics * * @example * ```typescript * const stats = FileDiscovery.getPatternCacheStats(); * console.log(`Glob cache hit rate: ${stats.glob.hitRate}%`); * console.log(`Cache size: ${stats.combined.size} entries`); * ``` */ static getPatternCacheStats(): { glob: { size: number; hitRate: number; }; ignore: { size: number; hitRate: number; }; combined: { size: number; hitRate: number; }; }; /** * Clear pattern cache (useful for testing or memory management) * * Clears all cached compiled glob and ignore patterns. This can be useful * for memory management in long-running processes or for testing. * * @example * ```typescript * // Clear cache before running tests * beforeEach(() => { * FileDiscovery.clearPatternCache(); * }); * * // Clear cache in long-running process * if (memoryUsage > threshold) { * FileDiscovery.clearPatternCache(); * } * ``` */ static clearPatternCache(): void; /** * Evaluate a single file against all patterns with detailed logging * @param filePath - File path to evaluate * @param options - Filtering options * @param ignoreRules - Gitignore rules * @param absoluteRoot - Absolute root path * @returns Detailed match information */ private static evaluateFileVerbose; } //# sourceMappingURL=file-discovery.d.ts.map