/** * Dependency resolution module - resolves relative imports to actual file paths * * PERFORMANCE OPTIMIZATION: This module is optimized for O(n) complexity when processing * large codebases (10,000+ files). Key optimizations: * 1. Pre-built lookup structures to avoid O(n²) array searches * 2. File path Set for O(1) existence checks * 3. Basename and extension maps for efficient candidate matching * 4. Cached directory structures for directory-based imports */ import type { ImportInfo } from '../types/index.js'; /** * Performance-optimized file lookup structures * These are built once and reused for all import resolution operations */ interface FileLookupStructures { /** Set of all file paths for O(1) existence checks */ fileSet: Set; /** Map from basename (without extension) to array of full file paths */ basenameMap: Map; /** Map from directory path to array of index files in that directory */ directoryIndexMap: Map; /** Map from file extension to array of files with that extension */ extensionMap: Map; } export declare class DependencyResolver { private static readonly EXTENSIONS; private static readonly INDEX_FILES; /** * Build optimized lookup structures from file array * Time Complexity: O(n) where n is number of files * Space Complexity: O(n) for lookup structures * * This is the key performance optimization - we build these structures once * and use O(1) lookups instead of O(n) array searches */ private static buildLookupStructures; /** * Resolve relative imports to actual file paths using optimized lookup structures * Time Complexity: O(1) per import (average case), O(k) worst case where k is number of candidates * * @param imports - Array of import info from file * @param currentFilePath - Path of the file containing the imports * @param lookupStructures - Pre-built lookup structures for O(1) file resolution * @returns Array of resolved file paths */ static resolveImportsOptimized(imports: ImportInfo[], currentFilePath: string, lookupStructures: FileLookupStructures): string[]; /** * Legacy method for backwards compatibility * PERFORMANCE WARNING: This method has O(n²) complexity and should be avoided for large codebases * Use resolveImportsOptimized instead for better performance * * @deprecated Use resolveImportsOptimized with pre-built lookup structures */ static resolveImports(imports: ImportInfo[], currentFilePath: string, allFiles: string[]): string[]; /** * Resolve a single relative import using optimized lookup structures * Time Complexity: O(1) average case, O(k) worst case where k is number of candidates * * @param specifier - Relative module specifier * @param currentDir - Directory of the importing file * @param lookupStructures - Pre-built lookup structures for O(1) file resolution * @returns Resolved file path or undefined if not found */ private static resolveRelativeImportOptimized; /** * Generate candidate file paths using optimized lookup structures * Time Complexity: O(1) for most cases, O(k) where k is number of files with same basename * * @param basePath - Base path to generate candidates from * @param lookupStructures - Pre-built lookup structures * @returns Array of candidate file paths */ private static generateCandidatesOptimized; /** * Check if an import specifier is relative * @param specifier - Module specifier to check * @returns True if the specifier is relative */ private static isRelativeImport; /** * Build dependency edges from resolved imports using optimized O(n) algorithm * * PERFORMANCE OPTIMIZATION: This method now has O(n) complexity instead of O(n²) * Key optimization: Pre-build lookup structures once and reuse for all files * * @param files - Map of file paths to their import info * @param allFiles - Array of all discovered files * @returns Array of dependency edges */ static buildDependencyGraph(files: Record, allFiles: string[]): Array<{ from: string; to: string; }>; /** * Find circular dependencies in the dependency graph * @param edges - Array of dependency edges * @returns Array of circular dependency chains */ static findCircularDependencies(edges: Array<{ from: string; to: string; }>): string[][]; /** * Get dependency count for each file * @param edges - Array of dependency edges * @returns Map of file paths to dependency counts */ static getDependencyCounts(edges: Array<{ from: string; to: string; }>): { dependencies: Map; dependents: Map; }; /** * Find files with no dependencies (entry points) * @param edges - Array of dependency edges * @param allFiles - Array of all files * @returns Array of entry point file paths */ static findEntryPoints(edges: Array<{ from: string; to: string; }>, allFiles: string[]): string[]; /** * Find leaf files (files that no other files import) * @param edges - Array of dependency edges * @param allFiles - Array of all files * @returns Array of leaf file paths */ static findLeafFiles(edges: Array<{ from: string; to: string; }>, allFiles: string[]): string[]; } export {}; //# sourceMappingURL=dependency-resolver.d.ts.map