/** * Import graph for TypeScript/JavaScript files. * * Builds a reverse dependency index (dependents map) by scanning the project * tree for import/export/require statements. Caches the result and rebuilds * when a file is marked as modified. * * Usage: * const graph = new ImportGraph(); * await graph.build(projectRoot); * const affected = graph.findDependents('/abs/path/to/file.ts'); */ /** Absolute path → set of absolute paths that import it */ export type DependentsMap = Map>; /** Absolute path → set of absolute paths it imports */ export type ImportsMap = Map>; /** * Extract all module specifiers (import/export/require) from a file's text. * Returns only relative specifiers (starting with '.'). */ declare function extractRelativeSpecifiers(content: string): string[]; export declare const extractRelativeSpecifiersForTest: typeof extractRelativeSpecifiers; export declare function resolveSpecifierForTest(fromFile: string, spec: string, knownFiles: Iterable): string | null; export declare class ImportGraph { /** Forward map: file → files it imports */ private imports; /** Reverse map: file → files that import it */ private dependents; /** Root that was last scanned */ private scannedRoot; /** Whether graph is stale and needs a rebuild */ private dirty; /** Warnings from the most recent graph build. */ private warnings; constructor(); /** * Mark the graph as stale. Call this whenever a file has been modified * so the next findDependents() call triggers a rebuild. */ markDirty(): void; /** * Build (or rebuild) the import graph by scanning all source files under * `projectRoot`. Idempotent when not dirty and root hasn't changed. */ build(projectRoot: string): Promise; /** * Build the graph from an in-memory file map for deterministic tests. * Keys must be absolute file paths. */ buildFromFilesForTest(files: Record): void; /** * Return all files that directly import `filePath`. * Returns an empty array if the graph hasn't been built or the file isn't known. */ findDependents(filePath: string): string[]; /** * Return all files that transitively depend on `filePath`. * BFS from the direct dependents. */ findTransitiveDependents(filePath: string): string[]; /** * Return the set of files `filePath` directly imports. */ findImports(filePath: string): string[]; /** * Return graph statistics. */ stats(): { files: number; edges: number; scannedRoot: string | null; dirty: boolean; }; /** * Return warnings from the most recent graph build. */ getWarnings(): string[]; /** * Export as a plain object keyed by relative paths (relative to `projectRoot`). * Useful for serialization and the analyze tool's `dependencies` mode. */ toRelativeGraph(projectRoot: string): Record; } export {}; //# sourceMappingURL=import-graph.d.ts.map