sicua
Version:
A tool for analyzing project structure and dependencies
31 lines (30 loc) • 1.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildDependencyGraph = buildDependencyGraph;
const analysisUtils_1 = require("../../../utils/common/analysisUtils");
/**
* Builds a dependency graph from component relationships using optimized lookups
* @param components The list of components to analyze
* @param lookupService Pre-initialized lookup service for O(1) component resolution
* @returns A dependency graph mapping unique component IDs to their dependencies
*/
function buildDependencyGraph(components, lookupService) {
const graph = {};
for (const component of components) {
const componentId = (0, analysisUtils_1.generateComponentId)(component);
// Resolve all imports to target component IDs using O(1) lookups
const targetComponentIds = [];
for (const importPath of component.imports) {
const resolvedIds = lookupService.resolveImportToComponentIds(importPath);
// Add all resolved component IDs, excluding self-references
for (const targetId of resolvedIds) {
if (targetId !== componentId) {
targetComponentIds.push(targetId);
}
}
}
// Remove duplicates and store in graph
graph[componentId] = Array.from(new Set(targetComponentIds));
}
return graph;
}