@ankhorage/dependency-graph 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -55,7 +55,9 @@ function moduleForFile(file, owner) {
|
|
|
55
55
|
? (file.filePath ?? '')
|
|
56
56
|
: (file.filePath ?? '').slice(owner.relativeRoot.length + 1);
|
|
57
57
|
const directory = relative.split('/').slice(0, -1).join('/');
|
|
58
|
-
|
|
58
|
+
if (directory !== '')
|
|
59
|
+
return directory.split('/').filter(Boolean).join('.');
|
|
60
|
+
return relative.replace(/\.[^.]+$/u, '');
|
|
59
61
|
}
|
|
60
62
|
/*** Preserve the existing package/module node identity and dotted ancestor structure. */
|
|
61
63
|
function addModuleHierarchy(nodes, owner, modulePath) {
|
package/dist/features/dependency-analysis/domain/projectDependencyGraphFromSourceGraph.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projectDependencyGraphFromSourceGraph.js","sourceRoot":"","sources":["../../../../src/features/dependency-analysis/domain/projectDependencyGraphFromSourceGraph.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAgB/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE,0FAA0F;AAC1F,MAAM,UAAU,qCAAqC,CACnD,WAAwB,EACxB,QAA2C,EAC3C,QAA0D;IAE1D,MAAM,aAAa,GAAG,IAAI,GAAG,CAC3B,QAAQ,CAAC,GAAG,CACV,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAU,CAC3F,CACF,CAAC;IACF,MAAM,KAAK,GAAG,IAAI,GAAG,CACnB,QAAQ,CAAC,GAAG,CAAC,CAA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Q;QAChB,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,UAAU;YACV,MAAM,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,QAAQ,CAAC,MAAM;YACtD,QAAQ,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC,EAAE,GAAG,QAAQ,CAAC;SAC5D;KACF,CAAC,CAAC;AACL,CAAC;AAED,yEAAyE;AACzE,SAAS,YAAY,CAAC,KAA6B,EAAE,UAAkB;IACrE,OAAO,UAAU,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,IAAI,UAAU,EAAE,CAAC;AAC5E,CAAC","sourcesContent":["import type { GraphEdge, GraphNode } from '@ankhorage/graph';\nimport { createGraph } from '@ankhorage/graph';\n\nimport type {\n DependencyGraph,\n DependencyGraphEdgeData,\n DependencyGraphInspectionProjectInput,\n DependencyGraphNodeData,\n DependencyGraphPackage,\n DependencyImportEvidence,\n DependencyReferenceClassification,\n} from '../../../types/dependencyGraph.js';\nimport type {\n SourceGraph,\n SourceNodeData,\n SourceRelationEvidence,\n} from '../../../types/sourceGraph.js';\nimport { createFocusPackageNode } from './createFocusPackageNode.js';\n\n/*** Derive the established module/package dependency view from canonical source facts. */\nexport function projectDependencyGraphFromSourceGraph(\n sourceGraph: SourceGraph,\n packages: readonly DependencyGraphPackage[],\n projects: readonly DependencyGraphInspectionProjectInput[],\n): DependencyGraph {\n const detectedRoots = new Map(\n projects.map(\n ({ id, inspection }) => [id, inspection.packages.map(({ rootPath }) => rootPath)] as const,\n ),\n );\n const nodes = new Map<string, GraphNode<DependencyGraphNodeData>>(\n packages.map((item) => [item.nodeId, createFocusPackageNode(item)]),\n );\n const edges = new Map<string, GraphEdge<DependencyGraphEdgeData>>();\n const sourceNodes = new Map(sourceGraph.graph.nodes.map((node) => [node.id, node.data]));\n const files = sourceGraph.graph.nodes.filter(\n ({ data }) => data.kind === 'file' && data.analyzerId !== undefined,\n );\n for (const { data } of files) {\n const owner = packageForFile(packages, detectedRoots, data);\n if (owner !== undefined) addModuleHierarchy(nodes, owner, moduleForFile(data, owner));\n }\n for (const edge of sourceGraph.graph.edges) {\n if (edge.data.kind !== 'imports') continue;\n const source = sourceNodes.get(edge.source);\n const target = sourceNodes.get(edge.target);\n if (source === undefined || target === undefined) continue;\n const owner = packageForFile(packages, detectedRoots, source);\n if (owner === undefined || source.analyzerId === undefined) continue;\n const sourceId = moduleNodeId(owner, moduleForFile(source, owner));\n const targetId = projectTarget(target, owner, packages, detectedRoots, nodes);\n if (targetId === undefined || targetId === sourceId) continue;\n addProjectedEdge(\n edges,\n sourceId,\n targetId,\n source.analyzerId,\n owner,\n edge.data.evidence,\n target,\n );\n }\n return createGraph({ nodes: [...nodes.values()], edges: [...edges.values()] });\n}\n\n/*** Select the deepest focus package root containing one project-relative source file. */\nfunction packageForFile(\n packages: readonly DependencyGraphPackage[],\n detectedRoots: ReadonlyMap<string, readonly string[]>,\n file: SourceNodeData,\n): DependencyGraphPackage | undefined {\n if (file.filePath === undefined) return undefined;\n const { filePath } = file;\n const detected =\n (detectedRoots.get(file.projectId) ?? ['.'])\n .filter((root) => root === '.' || filePath === root || filePath.startsWith(`${root}/`))\n .sort((left, right) => right.length - left.length)[0] ?? '.';\n if (!packages.some((item) => item.projectId === file.projectId && item.relativeRoot === detected))\n return undefined;\n return packages\n .filter(\n (item) =>\n item.projectId === file.projectId &&\n (item.relativeRoot === '.' ||\n filePath === item.relativeRoot ||\n filePath.startsWith(`${item.relativeRoot}/`)),\n )\n .sort((left, right) => right.relativeRoot.length - left.relativeRoot.length)[0];\n}\n\n/*** Read the established dotted module path from one analyzed source file. */\nfunction moduleForFile(file: SourceNodeData, owner: DependencyGraphPackage): string {\n if (file.analyzerId !== 'typescript') return file.packageName ?? '';\n const relative =\n owner.relativeRoot === '.'\n ? (file.filePath ?? '')\n : (file.filePath ?? '').slice(owner.relativeRoot.length + 1);\n const directory = relative.split('/').slice(0, -1).join('/');\n return directory.split('/').filter(Boolean).join('.');\n}\n\n/*** Preserve the existing package/module node identity and dotted ancestor structure. */\nfunction addModuleHierarchy(\n nodes: Map<string, GraphNode<DependencyGraphNodeData>>,\n owner: DependencyGraphPackage,\n modulePath: string,\n): void {\n const parts = modulePath.split('.').filter(Boolean);\n parts.forEach((_, index) => {\n const current = parts.slice(0, index + 1).join('.');\n const id = moduleNodeId(owner, current);\n if (nodes.has(id)) return;\n nodes.set(id, {\n id,\n data: {\n kind: 'module',\n classification: 'intrinsic',\n focus: true,\n label: parts.at(index) ?? current,\n projectId: owner.projectId,\n ...(owner.name === undefined ? {} : { packageName: owner.name }),\n path: current,\n parentPath: index === 0 ? '' : parts.slice(0, index).join('.'),\n },\n });\n });\n}\n\n/*** Resolve canonical import targets to stable package/module projection identities. */\nfunction projectTarget(\n target: SourceNodeData,\n sourceOwner: DependencyGraphPackage,\n packages: readonly DependencyGraphPackage[],\n detectedRoots: ReadonlyMap<string, readonly string[]>,\n nodes: Map<string, GraphNode<DependencyGraphNodeData>>,\n): string | undefined {\n if (target.classification === 'vendor' || target.classification === 'unknown') {\n const name = target.packageName ?? target.name;\n const id = `${target.classification}:${name}`;\n if (!nodes.has(id))\n nodes.set(id, {\n id,\n data: {\n kind: 'package',\n classification: target.classification,\n focus: false,\n label: name,\n packageName: name,\n },\n });\n return id;\n }\n if (target.kind === 'package' && target.path !== undefined) {\n return packages.find(\n (item) => item.projectId === target.projectId && item.relativeRoot === target.path,\n )?.nodeId;\n }\n const owner =\n target.filePath === undefined ? sourceOwner : packageForFile(packages, detectedRoots, target);\n if (owner === undefined) return undefined;\n const modulePath =\n target.analyzerId === 'typescript' || target.kind === 'file'\n ? moduleForFile(target, owner)\n : (target.packageName ?? '');\n addModuleHierarchy(nodes, owner, modulePath);\n return moduleNodeId(owner, modulePath);\n}\n\n/*** Add one canonical import to a weighted package edge with original evidence. */\nfunction addProjectedEdge(\n edges: Map<string, GraphEdge<DependencyGraphEdgeData>>,\n sourceId: string,\n targetId: string,\n analyzerId: string,\n owner: DependencyGraphPackage,\n evidence: readonly SourceRelationEvidence[],\n target: SourceNodeData,\n): void {\n const id = `${sourceId}->${targetId}`;\n const previous = edges.get(id);\n const classification: DependencyReferenceClassification =\n target.kind === 'package' && target.path !== undefined\n ? 'focus'\n : (target.classification ?? 'unknown');\n const observed = evidence.map((item): DependencyImportEvidence => ({\n sourceFile:\n owner.relativeRoot === '.'\n ? item.sourcePath\n : item.sourcePath.slice(owner.relativeRoot.length + 1),\n specifier: item.specifier ?? '',\n classification,\n declarations: item.declarations ?? [],\n }));\n edges.set(id, {\n id,\n source: sourceId,\n target: targetId,\n data: {\n kind: 'import',\n analyzerId,\n weight: (previous?.data.weight ?? 0) + observed.length,\n evidence: [...(previous?.data.evidence ?? []), ...observed],\n },\n });\n}\n\n/*** Preserve the legacy projection's readable package/module node ID. */\nfunction moduleNodeId(owner: DependencyGraphPackage, modulePath: string): string {\n return modulePath === '' ? owner.nodeId : `${owner.nodeId}#${modulePath}`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"projectDependencyGraphFromSourceGraph.js","sourceRoot":"","sources":["../../../../src/features/dependency-analysis/domain/projectDependencyGraphFromSourceGraph.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAgB/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE,0FAA0F;AAC1F,MAAM,UAAU,qCAAqC,CACnD,WAAwB,EACxB,QAA2C,EAC3C,QAA0D;IAE1D,MAAM,aAAa,GAAG,IAAI,GAAG,CAC3B,QAAQ,CAAC,GAAG,CACV,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE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SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,EAAE;QAC/B,cAAc;QACd,YAAY,EAAE,IAAI,CAAC,YAAY,IAAI,EAAE;KACtC,CAAC,CAAC,CAAC;IACJ,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE;QACZ,EAAE;QACF,MAAM,EAAE,QAAQ;QAChB,MAAM,EAAE,QAAQ;QAChB,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,UAAU;YACV,MAAM,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,QAAQ,CAAC,MAAM;YACtD,QAAQ,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC,EAAE,GAAG,QAAQ,CAAC;SAC5D;KACF,CAAC,CAAC;AACL,CAAC;AAED,yEAAyE;AACzE,SAAS,YAAY,CAAC,KAA6B,EAAE,UAAkB;IACrE,OAAO,UAAU,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,IAAI,UAAU,EAAE,CAAC;AAC5E,CAAC","sourcesContent":["import type { GraphEdge, GraphNode } from '@ankhorage/graph';\nimport { createGraph } from '@ankhorage/graph';\n\nimport type {\n DependencyGraph,\n DependencyGraphEdgeData,\n DependencyGraphInspectionProjectInput,\n DependencyGraphNodeData,\n DependencyGraphPackage,\n DependencyImportEvidence,\n DependencyReferenceClassification,\n} from '../../../types/dependencyGraph.js';\nimport type {\n SourceGraph,\n SourceNodeData,\n SourceRelationEvidence,\n} from '../../../types/sourceGraph.js';\nimport { createFocusPackageNode } from './createFocusPackageNode.js';\n\n/*** Derive the established module/package dependency view from canonical source facts. */\nexport function projectDependencyGraphFromSourceGraph(\n sourceGraph: SourceGraph,\n packages: readonly DependencyGraphPackage[],\n projects: readonly DependencyGraphInspectionProjectInput[],\n): DependencyGraph {\n const detectedRoots = new Map(\n projects.map(\n ({ id, inspection }) => [id, inspection.packages.map(({ rootPath }) => rootPath)] as const,\n ),\n );\n const nodes = new Map<string, GraphNode<DependencyGraphNodeData>>(\n packages.map((item) => [item.nodeId, createFocusPackageNode(item)]),\n );\n const edges = new Map<string, GraphEdge<DependencyGraphEdgeData>>();\n const sourceNodes = new Map(sourceGraph.graph.nodes.map((node) => [node.id, node.data]));\n const files = sourceGraph.graph.nodes.filter(\n ({ data }) => data.kind === 'file' && data.analyzerId !== undefined,\n );\n for (const { data } of files) {\n const owner = packageForFile(packages, detectedRoots, data);\n if (owner !== undefined) addModuleHierarchy(nodes, owner, moduleForFile(data, owner));\n }\n for (const edge of sourceGraph.graph.edges) {\n if (edge.data.kind !== 'imports') continue;\n const source = sourceNodes.get(edge.source);\n const target = sourceNodes.get(edge.target);\n if (source === undefined || target === undefined) continue;\n const owner = packageForFile(packages, detectedRoots, source);\n if (owner === undefined || source.analyzerId === undefined) continue;\n const sourceId = moduleNodeId(owner, moduleForFile(source, owner));\n const targetId = projectTarget(target, owner, packages, detectedRoots, nodes);\n if (targetId === undefined || targetId === sourceId) continue;\n addProjectedEdge(\n edges,\n sourceId,\n targetId,\n source.analyzerId,\n owner,\n edge.data.evidence,\n target,\n );\n }\n return createGraph({ nodes: [...nodes.values()], edges: [...edges.values()] });\n}\n\n/*** Select the deepest focus package root containing one project-relative source file. */\nfunction packageForFile(\n packages: readonly DependencyGraphPackage[],\n detectedRoots: ReadonlyMap<string, readonly string[]>,\n file: SourceNodeData,\n): DependencyGraphPackage | undefined {\n if (file.filePath === undefined) return undefined;\n const { filePath } = file;\n const detected =\n (detectedRoots.get(file.projectId) ?? ['.'])\n .filter((root) => root === '.' || filePath === root || filePath.startsWith(`${root}/`))\n .sort((left, right) => right.length - left.length)[0] ?? '.';\n if (!packages.some((item) => item.projectId === file.projectId && item.relativeRoot === detected))\n return undefined;\n return packages\n .filter(\n (item) =>\n item.projectId === file.projectId &&\n (item.relativeRoot === '.' ||\n filePath === item.relativeRoot ||\n filePath.startsWith(`${item.relativeRoot}/`)),\n )\n .sort((left, right) => right.relativeRoot.length - left.relativeRoot.length)[0];\n}\n\n/*** Read the established dotted module path from one analyzed source file. */\nfunction moduleForFile(file: SourceNodeData, owner: DependencyGraphPackage): string {\n if (file.analyzerId !== 'typescript') return file.packageName ?? '';\n const relative =\n owner.relativeRoot === '.'\n ? (file.filePath ?? '')\n : (file.filePath ?? '').slice(owner.relativeRoot.length + 1);\n const directory = relative.split('/').slice(0, -1).join('/');\n if (directory !== '') return directory.split('/').filter(Boolean).join('.');\n return relative.replace(/\\.[^.]+$/u, '');\n}\n\n/*** Preserve the existing package/module node identity and dotted ancestor structure. */\nfunction addModuleHierarchy(\n nodes: Map<string, GraphNode<DependencyGraphNodeData>>,\n owner: DependencyGraphPackage,\n modulePath: string,\n): void {\n const parts = modulePath.split('.').filter(Boolean);\n parts.forEach((_, index) => {\n const current = parts.slice(0, index + 1).join('.');\n const id = moduleNodeId(owner, current);\n if (nodes.has(id)) return;\n nodes.set(id, {\n id,\n data: {\n kind: 'module',\n classification: 'intrinsic',\n focus: true,\n label: parts.at(index) ?? current,\n projectId: owner.projectId,\n ...(owner.name === undefined ? {} : { packageName: owner.name }),\n path: current,\n parentPath: index === 0 ? '' : parts.slice(0, index).join('.'),\n },\n });\n });\n}\n\n/*** Resolve canonical import targets to stable package/module projection identities. */\nfunction projectTarget(\n target: SourceNodeData,\n sourceOwner: DependencyGraphPackage,\n packages: readonly DependencyGraphPackage[],\n detectedRoots: ReadonlyMap<string, readonly string[]>,\n nodes: Map<string, GraphNode<DependencyGraphNodeData>>,\n): string | undefined {\n if (target.classification === 'vendor' || target.classification === 'unknown') {\n const name = target.packageName ?? target.name;\n const id = `${target.classification}:${name}`;\n if (!nodes.has(id))\n nodes.set(id, {\n id,\n data: {\n kind: 'package',\n classification: target.classification,\n focus: false,\n label: name,\n packageName: name,\n },\n });\n return id;\n }\n if (target.kind === 'package' && target.path !== undefined) {\n return packages.find(\n (item) => item.projectId === target.projectId && item.relativeRoot === target.path,\n )?.nodeId;\n }\n const owner =\n target.filePath === undefined ? sourceOwner : packageForFile(packages, detectedRoots, target);\n if (owner === undefined) return undefined;\n const modulePath =\n target.analyzerId === 'typescript' || target.kind === 'file'\n ? moduleForFile(target, owner)\n : (target.packageName ?? '');\n addModuleHierarchy(nodes, owner, modulePath);\n return moduleNodeId(owner, modulePath);\n}\n\n/*** Add one canonical import to a weighted package edge with original evidence. */\nfunction addProjectedEdge(\n edges: Map<string, GraphEdge<DependencyGraphEdgeData>>,\n sourceId: string,\n targetId: string,\n analyzerId: string,\n owner: DependencyGraphPackage,\n evidence: readonly SourceRelationEvidence[],\n target: SourceNodeData,\n): void {\n const id = `${sourceId}->${targetId}`;\n const previous = edges.get(id);\n const classification: DependencyReferenceClassification =\n target.kind === 'package' && target.path !== undefined\n ? 'focus'\n : (target.classification ?? 'unknown');\n const observed = evidence.map((item): DependencyImportEvidence => ({\n sourceFile:\n owner.relativeRoot === '.'\n ? item.sourcePath\n : item.sourcePath.slice(owner.relativeRoot.length + 1),\n specifier: item.specifier ?? '',\n classification,\n declarations: item.declarations ?? [],\n }));\n edges.set(id, {\n id,\n source: sourceId,\n target: targetId,\n data: {\n kind: 'import',\n analyzerId,\n weight: (previous?.data.weight ?? 0) + observed.length,\n evidence: [...(previous?.data.evidence ?? []), ...observed],\n },\n });\n}\n\n/*** Preserve the legacy projection's readable package/module node ID. */\nfunction moduleNodeId(owner: DependencyGraphPackage, modulePath: string): string {\n return modulePath === '' ? owner.nodeId : `${owner.nodeId}#${modulePath}`;\n}\n"]}
|