@ankhorage/dependency-graph 0.4.0 → 0.5.0

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.
Files changed (29) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/dependencyGraph.d.ts +1 -0
  3. package/dist/dependencyGraph.d.ts.map +1 -1
  4. package/dist/dependencyGraph.js +1 -0
  5. package/dist/dependencyGraph.js.map +1 -1
  6. package/dist/features/dependency-analysis/adapters/outbound/cpp/analyzeCppProjectAsync.d.ts +4 -0
  7. package/dist/features/dependency-analysis/adapters/outbound/cpp/analyzeCppProjectAsync.d.ts.map +1 -0
  8. package/dist/features/dependency-analysis/adapters/outbound/cpp/analyzeCppProjectAsync.js +103 -0
  9. package/dist/features/dependency-analysis/adapters/outbound/cpp/analyzeCppProjectAsync.js.map +1 -0
  10. package/dist/features/dependency-analysis/adapters/outbound/cpp/collectCppFilesAsync.d.ts +3 -0
  11. package/dist/features/dependency-analysis/adapters/outbound/cpp/collectCppFilesAsync.d.ts.map +1 -0
  12. package/dist/features/dependency-analysis/adapters/outbound/cpp/collectCppFilesAsync.js +43 -0
  13. package/dist/features/dependency-analysis/adapters/outbound/cpp/collectCppFilesAsync.js.map +1 -0
  14. package/dist/features/dependency-analysis/adapters/outbound/cpp/cppDependencyGraphAnalyzer.d.ts +4 -0
  15. package/dist/features/dependency-analysis/adapters/outbound/cpp/cppDependencyGraphAnalyzer.d.ts.map +1 -0
  16. package/dist/features/dependency-analysis/adapters/outbound/cpp/cppDependencyGraphAnalyzer.js +8 -0
  17. package/dist/features/dependency-analysis/adapters/outbound/cpp/cppDependencyGraphAnalyzer.js.map +1 -0
  18. package/dist/features/dependency-analysis/adapters/outbound/cpp/extractCppDependencies.d.ts +11 -0
  19. package/dist/features/dependency-analysis/adapters/outbound/cpp/extractCppDependencies.d.ts.map +1 -0
  20. package/dist/features/dependency-analysis/adapters/outbound/cpp/extractCppDependencies.js +10 -0
  21. package/dist/features/dependency-analysis/adapters/outbound/cpp/extractCppDependencies.js.map +1 -0
  22. package/dist/features/dependency-analysis/adapters/outbound/cpp/extractCppPackageFromInclude.d.ts +3 -0
  23. package/dist/features/dependency-analysis/adapters/outbound/cpp/extractCppPackageFromInclude.d.ts.map +1 -0
  24. package/dist/features/dependency-analysis/adapters/outbound/cpp/extractCppPackageFromInclude.js +9 -0
  25. package/dist/features/dependency-analysis/adapters/outbound/cpp/extractCppPackageFromInclude.js.map +1 -0
  26. package/dist/features/dependency-analysis/application/createDependencyGraphAsync.d.ts.map +1 -1
  27. package/dist/features/dependency-analysis/application/createDependencyGraphAsync.js +2 -0
  28. package/dist/features/dependency-analysis/application/createDependencyGraphAsync.js.map +1 -1
  29. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ankhorage/dependency-graph
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 7174cf6: Add canonical C++ include/dependency analysis.
8
+
3
9
  ## 0.4.0
4
10
 
5
11
  ### Minor Changes
@@ -1,3 +1,4 @@
1
+ export { cppDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/cpp/cppDependencyGraphAnalyzer.js';
1
2
  export { javaDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/java/javaDependencyGraphAnalyzer.js';
2
3
  export { kotlinDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/kotlin/kotlinDependencyGraphAnalyzer.js';
3
4
  export { pythonDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/python/pythonDependencyGraphAnalyzer.js';
@@ -1 +1 @@
1
- {"version":3,"file":"dependencyGraph.d.ts","sourceRoot":"","sources":["../src/dependencyGraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,sFAAsF,CAAC;AACnI,OAAO,EAAE,6BAA6B,EAAE,MAAM,0FAA0F,CAAC;AACzI,OAAO,EAAE,6BAA6B,EAAE,MAAM,0FAA0F,CAAC;AACzI,OAAO,EAAE,iCAAiC,EAAE,MAAM,kGAAkG,CAAC;AACrJ,OAAO,EAAE,0BAA0B,EAAE,MAAM,0EAA0E,CAAC;AACtH,YAAY,EACV,0BAA0B,EAC1B,qBAAqB,EACrB,yBAAyB,EACzB,eAAe,EACf,uBAAuB,EACvB,8BAA8B,EAC9B,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,EACtB,2BAA2B,EAC3B,wBAAwB,EACxB,4BAA4B,EAC5B,kBAAkB,EAClB,iCAAiC,GAClC,MAAM,4BAA4B,CAAC"}
1
+ {"version":3,"file":"dependencyGraph.d.ts","sourceRoot":"","sources":["../src/dependencyGraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,oFAAoF,CAAC;AAChI,OAAO,EAAE,2BAA2B,EAAE,MAAM,sFAAsF,CAAC;AACnI,OAAO,EAAE,6BAA6B,EAAE,MAAM,0FAA0F,CAAC;AACzI,OAAO,EAAE,6BAA6B,EAAE,MAAM,0FAA0F,CAAC;AACzI,OAAO,EAAE,iCAAiC,EAAE,MAAM,kGAAkG,CAAC;AACrJ,OAAO,EAAE,0BAA0B,EAAE,MAAM,0EAA0E,CAAC;AACtH,YAAY,EACV,0BAA0B,EAC1B,qBAAqB,EACrB,yBAAyB,EACzB,eAAe,EACf,uBAAuB,EACvB,8BAA8B,EAC9B,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,EACtB,2BAA2B,EAC3B,wBAAwB,EACxB,4BAA4B,EAC5B,kBAAkB,EAClB,iCAAiC,GAClC,MAAM,4BAA4B,CAAC"}
@@ -1,3 +1,4 @@
1
+ export { cppDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/cpp/cppDependencyGraphAnalyzer.js';
1
2
  export { javaDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/java/javaDependencyGraphAnalyzer.js';
2
3
  export { kotlinDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/kotlin/kotlinDependencyGraphAnalyzer.js';
3
4
  export { pythonDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/python/pythonDependencyGraphAnalyzer.js';
@@ -1 +1 @@
1
- {"version":3,"file":"dependencyGraph.js","sourceRoot":"","sources":["../src/dependencyGraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,sFAAsF,CAAC;AACnI,OAAO,EAAE,6BAA6B,EAAE,MAAM,0FAA0F,CAAC;AACzI,OAAO,EAAE,6BAA6B,EAAE,MAAM,0FAA0F,CAAC;AACzI,OAAO,EAAE,iCAAiC,EAAE,MAAM,kGAAkG,CAAC;AACrJ,OAAO,EAAE,0BAA0B,EAAE,MAAM,0EAA0E,CAAC","sourcesContent":["export { javaDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/java/javaDependencyGraphAnalyzer.js';\nexport { kotlinDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/kotlin/kotlinDependencyGraphAnalyzer.js';\nexport { pythonDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/python/pythonDependencyGraphAnalyzer.js';\nexport { typescriptDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/typescript/typescriptDependencyGraphAnalyzer.js';\nexport { createDependencyGraphAsync } from './features/dependency-analysis/application/createDependencyGraphAsync.js';\nexport type {\n CreateDependencyGraphInput,\n DependencyDeclaration,\n DependencyDeclarationKind,\n DependencyGraph,\n DependencyGraphAnalyzer,\n DependencyGraphAnalyzerContext,\n DependencyGraphEdgeData,\n DependencyGraphFragment,\n DependencyGraphNodeData,\n DependencyGraphPackage,\n DependencyGraphProjectInput,\n DependencyImportEvidence,\n DependencyNodeClassification,\n DependencyNodeKind,\n DependencyReferenceClassification,\n} from './types/dependencyGraph.js';\n"]}
1
+ {"version":3,"file":"dependencyGraph.js","sourceRoot":"","sources":["../src/dependencyGraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,oFAAoF,CAAC;AAChI,OAAO,EAAE,2BAA2B,EAAE,MAAM,sFAAsF,CAAC;AACnI,OAAO,EAAE,6BAA6B,EAAE,MAAM,0FAA0F,CAAC;AACzI,OAAO,EAAE,6BAA6B,EAAE,MAAM,0FAA0F,CAAC;AACzI,OAAO,EAAE,iCAAiC,EAAE,MAAM,kGAAkG,CAAC;AACrJ,OAAO,EAAE,0BAA0B,EAAE,MAAM,0EAA0E,CAAC","sourcesContent":["export { cppDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/cpp/cppDependencyGraphAnalyzer.js';\nexport { javaDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/java/javaDependencyGraphAnalyzer.js';\nexport { kotlinDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/kotlin/kotlinDependencyGraphAnalyzer.js';\nexport { pythonDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/python/pythonDependencyGraphAnalyzer.js';\nexport { typescriptDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/typescript/typescriptDependencyGraphAnalyzer.js';\nexport { createDependencyGraphAsync } from './features/dependency-analysis/application/createDependencyGraphAsync.js';\nexport type {\n CreateDependencyGraphInput,\n DependencyDeclaration,\n DependencyDeclarationKind,\n DependencyGraph,\n DependencyGraphAnalyzer,\n DependencyGraphAnalyzerContext,\n DependencyGraphEdgeData,\n DependencyGraphFragment,\n DependencyGraphNodeData,\n DependencyGraphPackage,\n DependencyGraphProjectInput,\n DependencyImportEvidence,\n DependencyNodeClassification,\n DependencyNodeKind,\n DependencyReferenceClassification,\n} from './types/dependencyGraph.js';\n"]}
@@ -0,0 +1,4 @@
1
+ import type { DependencyGraphAnalyzerContext, DependencyGraphFragment } from '../../../../../types/dependencyGraph.js';
2
+ /*** Analyze one detected C++ package into namespace/include dependency evidence. */
3
+ export declare function analyzeCppProjectAsync(context: DependencyGraphAnalyzerContext): Promise<DependencyGraphFragment>;
4
+ //# sourceMappingURL=analyzeCppProjectAsync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analyzeCppProjectAsync.d.ts","sourceRoot":"","sources":["../../../../../../src/features/dependency-analysis/adapters/outbound/cpp/analyzeCppProjectAsync.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,8BAA8B,EAE9B,uBAAuB,EAGxB,MAAM,yCAAyC,CAAC;AAMjD,oFAAoF;AACpF,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,8BAA8B,GACtC,OAAO,CAAC,uBAAuB,CAAC,CA+BlC"}
@@ -0,0 +1,103 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { toPortablePath } from '@ankhorage/utility/node/path';
4
+ import { collectCppFilesAsync } from './collectCppFilesAsync.js';
5
+ import { extractCppDependencies } from './extractCppDependencies.js';
6
+ import { extractCppPackageFromInclude } from './extractCppPackageFromInclude.js';
7
+ /*** Analyze one detected C++ package into namespace/include dependency evidence. */
8
+ export async function analyzeCppProjectAsync(context) {
9
+ const language = context.package.detection.languages.find(({ id }) => id === 'cpp');
10
+ const files = await collectCppFilesAsync(context.package.rootPath, language?.sourceRoots ?? ['src', '.'], context.excludedRoots, context.signal);
11
+ const sources = await Promise.all(files.map(async (file) => ({
12
+ file,
13
+ dependencies: extractCppDependencies(await readFile(file, 'utf8')),
14
+ })));
15
+ const intrinsicNamespaces = new Set(sources
16
+ .map(({ dependencies }) => dependencies.namespace)
17
+ .filter((namespace) => namespace !== ''));
18
+ const nodes = new Map();
19
+ for (const namespace of intrinsicNamespaces)
20
+ addIntrinsicHierarchy(context, namespace, nodes);
21
+ const edges = new Map();
22
+ for (const { file, dependencies } of sources) {
23
+ context.signal?.throwIfAborted();
24
+ const sourceNodeId = nodeIdForNamespace(context, dependencies.namespace);
25
+ for (const include of dependencies.includes) {
26
+ addInclude(context, file, sourceNodeId, include, nodes, edges);
27
+ }
28
+ }
29
+ return { nodes: [...nodes.values()], edges: [...edges.values()] };
30
+ }
31
+ /*** Aggregate one C++ include into stable target nodes and weighted evidence. */
32
+ function addInclude(context, sourceFile, sourceNodeId, include, nodes, edges) {
33
+ const targetPackage = extractCppPackageFromInclude(include.specifier);
34
+ if (targetPackage === '')
35
+ return;
36
+ const targetNodeId = include.local
37
+ ? nodeIdForNamespace(context, targetPackage)
38
+ : `unknown:${targetPackage}`;
39
+ if (targetNodeId === sourceNodeId)
40
+ return;
41
+ if (include.local) {
42
+ addIntrinsicHierarchy(context, targetPackage, nodes);
43
+ }
44
+ else if (!nodes.has(targetNodeId)) {
45
+ nodes.set(targetNodeId, {
46
+ id: targetNodeId,
47
+ data: {
48
+ kind: 'package',
49
+ classification: 'unknown',
50
+ focus: false,
51
+ label: targetPackage,
52
+ packageName: targetPackage,
53
+ },
54
+ });
55
+ }
56
+ const edgeId = `${sourceNodeId}->${targetNodeId}`;
57
+ const existing = edges.get(edgeId);
58
+ const evidence = {
59
+ sourceFile: toPortablePath(path.relative(context.package.rootPath, sourceFile)),
60
+ specifier: include.specifier,
61
+ classification: include.local ? 'intrinsic' : 'unknown',
62
+ declarations: [],
63
+ };
64
+ edges.set(edgeId, {
65
+ id: edgeId,
66
+ source: sourceNodeId,
67
+ target: targetNodeId,
68
+ data: {
69
+ kind: 'import',
70
+ analyzerId: 'cpp',
71
+ weight: (existing?.data.weight ?? 0) + 1,
72
+ evidence: [...(existing?.data.evidence ?? []), evidence],
73
+ },
74
+ });
75
+ }
76
+ /*** Materialize a C++ namespace/package and all ancestor nodes. */
77
+ function addIntrinsicHierarchy(context, namespace, nodes) {
78
+ const segments = namespace.split('.');
79
+ segments.forEach((_, index) => {
80
+ const current = segments.slice(0, index + 1).join('.');
81
+ const id = nodeIdForNamespace(context, current);
82
+ if (nodes.has(id))
83
+ return;
84
+ nodes.set(id, {
85
+ id,
86
+ data: {
87
+ kind: 'module',
88
+ classification: 'intrinsic',
89
+ focus: true,
90
+ label: current.split('.').at(-1) ?? current,
91
+ projectId: context.package.projectId,
92
+ ...(context.package.name === undefined ? {} : { packageName: context.package.name }),
93
+ path: current,
94
+ parentPath: current.includes('.') ? current.split('.').slice(0, -1).join('.') : '',
95
+ },
96
+ });
97
+ });
98
+ }
99
+ /*** Resolve a C++ namespace/package node inside the current focus package. */
100
+ function nodeIdForNamespace(context, namespace) {
101
+ return namespace === '' ? context.package.nodeId : `${context.package.nodeId}#${namespace}`;
102
+ }
103
+ //# sourceMappingURL=analyzeCppProjectAsync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analyzeCppProjectAsync.js","sourceRoot":"","sources":["../../../../../../src/features/dependency-analysis/adapters/outbound/cpp/analyzeCppProjectAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAS9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AAEjF,oFAAoF;AACpF,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,OAAuC;IAEvC,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC;IACpF,MAAM,KAAK,GAAG,MAAM,oBAAoB,CACtC,OAAO,CAAC,OAAO,CAAC,QAAQ,EACxB,QAAQ,EAAE,WAAW,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,EACrC,OAAO,CAAC,aAAa,EACrB,OAAO,CAAC,MAAM,CACf,CAAC;IACF,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,KAAK,CAAC,GA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AAO,CAAC,IAAI,EAAE,CAAC;gBACpF,IAAI,EAAE,OAAO;gBACb,UAAU,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE;aACnF;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,8EAA8E;AAC9E,SAAS,kBAAkB,CAAC,OAAuC,EAAE,SAAiB;IACpF,OAAO,SAAS,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;AAC9F,CAAC","sourcesContent":["import { readFile } from 'node:fs/promises';\nimport path from 'node:path';\n\nimport type { GraphEdge, GraphNode } from '@ankhorage/graph';\nimport { toPortablePath } from '@ankhorage/utility/node/path';\n\nimport type {\n DependencyGraphAnalyzerContext,\n DependencyGraphEdgeData,\n DependencyGraphFragment,\n DependencyGraphNodeData,\n DependencyImportEvidence,\n} from '../../../../../types/dependencyGraph.js';\nimport { collectCppFilesAsync } from './collectCppFilesAsync.js';\nimport type { CppInclude } from './extractCppDependencies.js';\nimport { extractCppDependencies } from './extractCppDependencies.js';\nimport { extractCppPackageFromInclude } from './extractCppPackageFromInclude.js';\n\n/*** Analyze one detected C++ package into namespace/include dependency evidence. */\nexport async function analyzeCppProjectAsync(\n context: DependencyGraphAnalyzerContext,\n): Promise<DependencyGraphFragment> {\n const language = context.package.detection.languages.find(({ id }) => id === 'cpp');\n const files = await collectCppFilesAsync(\n context.package.rootPath,\n language?.sourceRoots ?? ['src', '.'],\n context.excludedRoots,\n context.signal,\n );\n const sources = await Promise.all(\n files.map(async (file) => ({\n file,\n dependencies: extractCppDependencies(await readFile(file, 'utf8')),\n })),\n );\n const intrinsicNamespaces = new Set(\n sources\n .map(({ dependencies }) => dependencies.namespace)\n .filter((namespace) => namespace !== ''),\n );\n const nodes = new Map<string, GraphNode<DependencyGraphNodeData>>();\n for (const namespace of intrinsicNamespaces) addIntrinsicHierarchy(context, namespace, nodes);\n const edges = new Map<string, GraphEdge<DependencyGraphEdgeData>>();\n\n for (const { file, dependencies } of sources) {\n context.signal?.throwIfAborted();\n const sourceNodeId = nodeIdForNamespace(context, dependencies.namespace);\n for (const include of dependencies.includes) {\n addInclude(context, file, sourceNodeId, include, nodes, edges);\n }\n }\n return { nodes: [...nodes.values()], edges: [...edges.values()] };\n}\n\n/*** Aggregate one C++ include into stable target nodes and weighted evidence. */\nfunction addInclude(\n context: DependencyGraphAnalyzerContext,\n sourceFile: string,\n sourceNodeId: string,\n include: CppInclude,\n nodes: Map<string, GraphNode<DependencyGraphNodeData>>,\n edges: Map<string, GraphEdge<DependencyGraphEdgeData>>,\n): void {\n const targetPackage = extractCppPackageFromInclude(include.specifier);\n if (targetPackage === '') return;\n const targetNodeId = include.local\n ? nodeIdForNamespace(context, targetPackage)\n : `unknown:${targetPackage}`;\n if (targetNodeId === sourceNodeId) return;\n\n if (include.local) {\n addIntrinsicHierarchy(context, targetPackage, nodes);\n } else if (!nodes.has(targetNodeId)) {\n nodes.set(targetNodeId, {\n id: targetNodeId,\n data: {\n kind: 'package',\n classification: 'unknown',\n focus: false,\n label: targetPackage,\n packageName: targetPackage,\n },\n });\n }\n\n const edgeId = `${sourceNodeId}->${targetNodeId}`;\n const existing = edges.get(edgeId);\n const evidence: DependencyImportEvidence = {\n sourceFile: toPortablePath(path.relative(context.package.rootPath, sourceFile)),\n specifier: include.specifier,\n classification: include.local ? 'intrinsic' : 'unknown',\n declarations: [],\n };\n edges.set(edgeId, {\n id: edgeId,\n source: sourceNodeId,\n target: targetNodeId,\n data: {\n kind: 'import',\n analyzerId: 'cpp',\n weight: (existing?.data.weight ?? 0) + 1,\n evidence: [...(existing?.data.evidence ?? []), evidence],\n },\n });\n}\n\n/*** Materialize a C++ namespace/package and all ancestor nodes. */\nfunction addIntrinsicHierarchy(\n context: DependencyGraphAnalyzerContext,\n namespace: string,\n nodes: Map<string, GraphNode<DependencyGraphNodeData>>,\n): void {\n const segments = namespace.split('.');\n segments.forEach((_, index) => {\n const current = segments.slice(0, index + 1).join('.');\n const id = nodeIdForNamespace(context, 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: current.split('.').at(-1) ?? current,\n projectId: context.package.projectId,\n ...(context.package.name === undefined ? {} : { packageName: context.package.name }),\n path: current,\n parentPath: current.includes('.') ? current.split('.').slice(0, -1).join('.') : '',\n },\n });\n });\n}\n\n/*** Resolve a C++ namespace/package node inside the current focus package. */\nfunction nodeIdForNamespace(context: DependencyGraphAnalyzerContext, namespace: string): string {\n return namespace === '' ? context.package.nodeId : `${context.package.nodeId}#${namespace}`;\n}\n"]}
@@ -0,0 +1,3 @@
1
+ /*** Collect deterministic C++ source/header files without following symlinks or nested package roots. */
2
+ export declare function collectCppFilesAsync(rootPath: string, sourceRoots: readonly string[], excludedRoots: readonly string[], signal: AbortSignal | undefined): Promise<readonly string[]>;
3
+ //# sourceMappingURL=collectCppFilesAsync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collectCppFilesAsync.d.ts","sourceRoot":"","sources":["../../../../../../src/features/dependency-analysis/adapters/outbound/cpp/collectCppFilesAsync.ts"],"names":[],"mappings":"AAGA,yGAAyG;AACzG,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,SAAS,MAAM,EAAE,EAC9B,aAAa,EAAE,SAAS,MAAM,EAAE,EAChC,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAW5B"}
@@ -0,0 +1,43 @@
1
+ import { opendir } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ /*** Collect deterministic C++ source/header files without following symlinks or nested package roots. */
4
+ export async function collectCppFilesAsync(rootPath, sourceRoots, excludedRoots, signal) {
5
+ const files = await Promise.all(sourceRoots.map((sourceRoot) => visitDirectoryAsync(sourceRoot === '.' ? rootPath : path.resolve(rootPath, sourceRoot), new Set(excludedRoots), signal)));
6
+ return [...new Set(files.flat())].sort();
7
+ }
8
+ const excludedDirectoryNames = new Set(['.git', 'build', 'coverage', 'dist', 'out']);
9
+ const cppExtensions = ['.cpp', '.cc', '.cxx', '.h', '.hpp', '.hxx'];
10
+ /*** Recursively collect supported C++ files from one source root. */
11
+ async function visitDirectoryAsync(directory, excludedRoots, signal) {
12
+ signal?.throwIfAborted();
13
+ try {
14
+ const handle = await opendir(directory);
15
+ const files = [];
16
+ for await (const entry of handle) {
17
+ signal?.throwIfAborted();
18
+ const target = path.join(directory, entry.name);
19
+ if (entry.isSymbolicLink())
20
+ continue;
21
+ if (entry.isDirectory()) {
22
+ if (excludedDirectoryNames.has(entry.name) || excludedRoots.has(target))
23
+ continue;
24
+ files.push(...(await visitDirectoryAsync(target, excludedRoots, signal)));
25
+ }
26
+ else if (entry.isFile() &&
27
+ cppExtensions.some((extension) => entry.name.endsWith(extension))) {
28
+ files.push(target);
29
+ }
30
+ }
31
+ return files;
32
+ }
33
+ catch (error) {
34
+ if (isMissingPathError(error))
35
+ return [];
36
+ throw error;
37
+ }
38
+ }
39
+ /*** Treat absent optional detector source roots as empty instead of analysis failures. */
40
+ function isMissingPathError(error) {
41
+ return error instanceof Error && 'code' in error && error.code === 'ENOENT';
42
+ }
43
+ //# sourceMappingURL=collectCppFilesAsync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collectCppFilesAsync.js","sourceRoot":"","sources":["../../../../../../src/features/dependency-analysis/adapters/outbound/cpp/collectCppFilesAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,IAA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E;gBAAE,SAAS;YACrC,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;gBACxB,IAAI,sBAAsB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC;oBAAE,SAAS;gBAClF,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,mBAAmB,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;YAC5E,CAAC;iBAAM,IACL,KAAK,CAAC,MAAM,EAAE;gBACd,aAAa,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,EACjE,CAAC;gBACD,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACrB,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,kBAAkB,CAAC,KAAK,CAAC;YAAE,OAAO,EAAE,CAAC;QACzC,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,0FAA0F;AAC1F,SAAS,kBAAkB,CAAC,KAAc;IACxC,OAAO,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC;AAC9E,CAAC","sourcesContent":["import { opendir } from 'node:fs/promises';\nimport path from 'node:path';\n\n/*** Collect deterministic C++ source/header files without following symlinks or nested package roots. */\nexport async function collectCppFilesAsync(\n rootPath: string,\n sourceRoots: readonly string[],\n excludedRoots: readonly string[],\n signal: AbortSignal | undefined,\n): Promise<readonly string[]> {\n const files = await Promise.all(\n sourceRoots.map((sourceRoot) =>\n visitDirectoryAsync(\n sourceRoot === '.' ? rootPath : path.resolve(rootPath, sourceRoot),\n new Set(excludedRoots),\n signal,\n ),\n ),\n );\n return [...new Set(files.flat())].sort();\n}\n\nconst excludedDirectoryNames = new Set(['.git', 'build', 'coverage', 'dist', 'out']);\n\nconst cppExtensions = ['.cpp', '.cc', '.cxx', '.h', '.hpp', '.hxx'];\n\n/*** Recursively collect supported C++ files from one source root. */\nasync function visitDirectoryAsync(\n directory: string,\n excludedRoots: ReadonlySet<string>,\n signal: AbortSignal | undefined,\n): Promise<readonly string[]> {\n signal?.throwIfAborted();\n try {\n const handle = await opendir(directory);\n const files: string[] = [];\n for await (const entry of handle) {\n signal?.throwIfAborted();\n const target = path.join(directory, entry.name);\n if (entry.isSymbolicLink()) continue;\n if (entry.isDirectory()) {\n if (excludedDirectoryNames.has(entry.name) || excludedRoots.has(target)) continue;\n files.push(...(await visitDirectoryAsync(target, excludedRoots, signal)));\n } else if (\n entry.isFile() &&\n cppExtensions.some((extension) => entry.name.endsWith(extension))\n ) {\n files.push(target);\n }\n }\n return files;\n } catch (error) {\n if (isMissingPathError(error)) return [];\n throw error;\n }\n}\n\n/*** Treat absent optional detector source roots as empty instead of analysis failures. */\nfunction isMissingPathError(error: unknown): boolean {\n return error instanceof Error && 'code' in error && error.code === 'ENOENT';\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { DependencyGraphAnalyzer } from '../../../../../types/dependencyGraph.js';
2
+ /*** C++ analyzer adapter selected from project-detector language evidence. */
3
+ export declare const cppDependencyGraphAnalyzer: DependencyGraphAnalyzer;
4
+ //# sourceMappingURL=cppDependencyGraphAnalyzer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cppDependencyGraphAnalyzer.d.ts","sourceRoot":"","sources":["../../../../../../src/features/dependency-analysis/adapters/outbound/cpp/cppDependencyGraphAnalyzer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAGvF,8EAA8E;AAC9E,eAAO,MAAM,0BAA0B,EAAE,uBAIxC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { analyzeCppProjectAsync } from './analyzeCppProjectAsync.js';
2
+ /*** C++ analyzer adapter selected from project-detector language evidence. */
3
+ export const cppDependencyGraphAnalyzer = {
4
+ id: 'cpp',
5
+ supports: (detection) => detection.languages.some(({ id }) => id === 'cpp'),
6
+ analyzeAsync: analyzeCppProjectAsync,
7
+ };
8
+ //# sourceMappingURL=cppDependencyGraphAnalyzer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cppDependencyGraphAnalyzer.js","sourceRoot":"","sources":["../../../../../../src/features/dependency-analysis/adapters/outbound/cpp/cppDependencyGraphAnalyzer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE,8EAA8E;AAC9E,MAAM,CAAC,MAAM,0BAA0B,GAA4B;IACjE,EAAE,EAAE,KAAK;IACT,QAAQ,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,KAAK,CAAC;IAC3E,YAAY,EAAE,sBAAsB;CACrC,CAAC","sourcesContent":["import type { DependencyGraphAnalyzer } from '../../../../../types/dependencyGraph.js';\nimport { analyzeCppProjectAsync } from './analyzeCppProjectAsync.js';\n\n/*** C++ analyzer adapter selected from project-detector language evidence. */\nexport const cppDependencyGraphAnalyzer: DependencyGraphAnalyzer = {\n id: 'cpp',\n supports: (detection) => detection.languages.some(({ id }) => id === 'cpp'),\n analyzeAsync: analyzeCppProjectAsync,\n};\n"]}
@@ -0,0 +1,11 @@
1
+ export interface CppInclude {
2
+ readonly specifier: string;
3
+ readonly local: boolean;
4
+ }
5
+ export interface CppDependencies {
6
+ readonly namespace: string;
7
+ readonly includes: readonly CppInclude[];
8
+ }
9
+ /*** Extract C++ namespace and include directives from source text. */
10
+ export declare function extractCppDependencies(content: string): CppDependencies;
11
+ //# sourceMappingURL=extractCppDependencies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractCppDependencies.d.ts","sourceRoot":"","sources":["../../../../../../src/features/dependency-analysis/adapters/outbound/cpp/extractCppDependencies.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,SAAS,UAAU,EAAE,CAAC;CAC1C;AAED,sEAAsE;AACtE,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAQvE"}
@@ -0,0 +1,10 @@
1
+ /*** Extract C++ namespace and include directives from source text. */
2
+ export function extractCppDependencies(content) {
3
+ const namespace = /namespace\s+([a-zA-Z0-9_:]+)\s*\{/u.exec(content)?.[1]?.replace(/::/gu, '.') ?? '';
4
+ const includes = Array.from(content.matchAll(/#include\s+(["<])([^">]+)[">]/gu)).map((match) => ({
5
+ local: match[1] === '"',
6
+ specifier: match[2] ?? '',
7
+ }));
8
+ return { namespace, includes: includes.filter(({ specifier }) => specifier !== '') };
9
+ }
10
+ //# sourceMappingURL=extractCppDependencies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractCppDependencies.js","sourceRoot":"","sources":["../../../../../../src/features/dependency-analysis/adapters/outbound/cpp/extractCppDependencies.ts"],"names":[],"mappings":"AAUA,sEAAsE;AACtE,MAAM,UAAU,sBAAsB,CAAC,OAAe;IACpD,MAAM,SAAS,GACb,oCAAoC,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;IACtF,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,iCAAiC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC/F,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG;QACvB,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE;KAC1B,CAAC,CAAC,CAAC;IACJ,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,SAAS,KAAK,EAAE,CAAC,EAAE,CAAC;AACvF,CAAC","sourcesContent":["export interface CppInclude {\n readonly specifier: string;\n readonly local: boolean;\n}\n\nexport interface CppDependencies {\n readonly namespace: string;\n readonly includes: readonly CppInclude[];\n}\n\n/*** Extract C++ namespace and include directives from source text. */\nexport function extractCppDependencies(content: string): CppDependencies {\n const namespace =\n /namespace\\s+([a-zA-Z0-9_:]+)\\s*\\{/u.exec(content)?.[1]?.replace(/::/gu, '.') ?? '';\n const includes = Array.from(content.matchAll(/#include\\s+([\"<])([^\">]+)[\">]/gu)).map((match) => ({\n local: match[1] === '\"',\n specifier: match[2] ?? '',\n }));\n return { namespace, includes: includes.filter(({ specifier }) => specifier !== '') };\n}\n"]}
@@ -0,0 +1,3 @@
1
+ /*** Reduce a C++ include path to PKGViz-compatible package notation. */
2
+ export declare function extractCppPackageFromInclude(specifier: string): string;
3
+ //# sourceMappingURL=extractCppPackageFromInclude.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractCppPackageFromInclude.d.ts","sourceRoot":"","sources":["../../../../../../src/features/dependency-analysis/adapters/outbound/cpp/extractCppPackageFromInclude.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,wBAAgB,4BAA4B,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAKtE"}
@@ -0,0 +1,9 @@
1
+ /*** Reduce a C++ include path to PKGViz-compatible package notation. */
2
+ export function extractCppPackageFromInclude(specifier) {
3
+ const withoutExtension = specifier.replace(/\.(h|hpp|hxx)$/u, '');
4
+ const segments = withoutExtension.split('/');
5
+ if (segments.length <= 1)
6
+ return '';
7
+ return segments.slice(0, -1).join('.');
8
+ }
9
+ //# sourceMappingURL=extractCppPackageFromInclude.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractCppPackageFromInclude.js","sourceRoot":"","sources":["../../../../../../src/features/dependency-analysis/adapters/outbound/cpp/extractCppPackageFromInclude.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,MAAM,UAAU,4BAA4B,CAAC,SAAiB;IAC5D,MAAM,gBAAgB,GAAG,SAAS,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;IAClE,MAAM,QAAQ,GAAG,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7C,IAAI,QAAQ,CAAC,MAAM,IAAI,CAAC;QAAE,OAAO,EAAE,CAAC;IACpC,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzC,CAAC","sourcesContent":["/*** Reduce a C++ include path to PKGViz-compatible package notation. */\nexport function extractCppPackageFromInclude(specifier: string): string {\n const withoutExtension = specifier.replace(/\\.(h|hpp|hxx)$/u, '');\n const segments = withoutExtension.split('/');\n if (segments.length <= 1) return '';\n return segments.slice(0, -1).join('.');\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"createDependencyGraphAsync.d.ts","sourceRoot":"","sources":["../../../../src/features/dependency-analysis/application/createDependencyGraphAsync.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,0BAA0B,EAC1B,eAAe,EAKhB,MAAM,mCAAmC,CAAC;AAQ3C,sGAAsG;AACtG,wBAAsB,0BAA0B,CAC9C,KAAK,EAAE,0BAA0B,GAChC,OAAO,CAAC,eAAe,CAAC,CA2B1B"}
1
+ {"version":3,"file":"createDependencyGraphAsync.d.ts","sourceRoot":"","sources":["../../../../src/features/dependency-analysis/application/createDependencyGraphAsync.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,0BAA0B,EAC1B,eAAe,EAKhB,MAAM,mCAAmC,CAAC;AAS3C,sGAAsG;AACtG,wBAAsB,0BAA0B,CAC9C,KAAK,EAAE,0BAA0B,GAChC,OAAO,CAAC,eAAe,CAAC,CA4B1B"}
@@ -1,6 +1,7 @@
1
1
  import path from 'node:path';
2
2
  import { createGraph } from '@ankhorage/graph';
3
3
  import { inspectProjectAsync } from '@ankhorage/project-detector/node';
4
+ import { cppDependencyGraphAnalyzer } from '../adapters/outbound/cpp/cppDependencyGraphAnalyzer.js';
4
5
  import { javaDependencyGraphAnalyzer } from '../adapters/outbound/java/javaDependencyGraphAnalyzer.js';
5
6
  import { kotlinDependencyGraphAnalyzer } from '../adapters/outbound/kotlin/kotlinDependencyGraphAnalyzer.js';
6
7
  import { pythonDependencyGraphAnalyzer } from '../adapters/outbound/python/pythonDependencyGraphAnalyzer.js';
@@ -12,6 +13,7 @@ export async function createDependencyGraphAsync(input) {
12
13
  assertProjectInputs(input.projects);
13
14
  const analyzers = input.analyzers ?? [
14
15
  typescriptDependencyGraphAnalyzer,
16
+ cppDependencyGraphAnalyzer,
15
17
  javaDependencyGraphAnalyzer,
16
18
  kotlinDependencyGraphAnalyzer,
17
19
  pythonDependencyGraphAnalyzer,
@@ -1 +1 @@
1
- {"version":3,"file":"createDependencyGraphAsync.js","sourceRoot":"","sources":["../../../../src/features/dependency-analysis/application/createDependencyGraphAsync.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAWvE,OAAO,EAAE,2BAA2B,EAAE,MAAM,0DAA0D,CAAC;AACvG,OAAO,EAAE,6BAA6B,EAAE,MAAM,8DAA8D,CAAC;AAC7G,OAAO,EAAE,6BAA6B,EAAE,MAAM,8DAA8D,CAAC;AAC7G,OAAO,E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,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,iCAAiC,UAAU,CAAC,CAAC,CAAC,EAAE,IAAI,IAAI,SAAS,GAAG,CAAC,CAAC;IACxF,CAAC;IACD,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,kEAAkE;AAClE,SAAS,mBAAmB,CAAC,QAAgD;IAC3E,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;IACxE,CAAC;IAED,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;IACzC,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;IACD,IAAI,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,MAAM,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;AACH,CAAC","sourcesContent":["import path from 'node:path';\n\nimport { createGraph } from '@ankhorage/graph';\nimport { inspectProjectAsync } from '@ankhorage/project-detector/node';\nimport type { InspectedPackage, ProjectInspection } from '@ankhorage/project-detector/types';\n\nimport type {\n CreateDependencyGraphInput,\n DependencyGraph,\n DependencyGraphAnalyzer,\n DependencyGraphFragment,\n DependencyGraphPackage,\n DependencyGraphProjectInput,\n} from '../../../types/dependencyGraph.js';\nimport { javaDependencyGraphAnalyzer } from '../adapters/outbound/java/javaDependencyGraphAnalyzer.js';\nimport { kotlinDependencyGraphAnalyzer } from '../adapters/outbound/kotlin/kotlinDependencyGraphAnalyzer.js';\nimport { pythonDependencyGraphAnalyzer } from '../adapters/outbound/python/pythonDependencyGraphAnalyzer.js';\nimport { typescriptDependencyGraphAnalyzer } from '../adapters/outbound/typescript/typescriptDependencyGraphAnalyzer.js';\nimport { createFocusPackageNode } from '../domain/createFocusPackageNode.js';\nimport { readDependencyDeclarationsAsync } from '../domain/readDependencyDeclarationsAsync.js';\n\n/*** Inspect projects, run supported analyzers and combine their evidence into one canonical graph. */\nexport async function createDependencyGraphAsync(\n input: CreateDependencyGraphInput,\n): Promise<DependencyGraph> {\n assertProjectInputs(input.projects);\n const analyzers = input.analyzers ?? [\n typescriptDependencyGraphAnalyzer,\n javaDependencyGraphAnalyzer,\n kotlinDependencyGraphAnalyzer,\n pythonDependencyGraphAnalyzer,\n ];\n const inspected = await Promise.all(\n input.projects.map((project) => inspectProjectInputAsync(project, input.signal)),\n );\n const packages = inspected.flatMap(({ packages }) => packages);\n const focusPackages = createFocusPackageMap(packages);\n const fragments = await analyzePackagesAsync(inspected, analyzers, focusPackages, input.signal);\n const nodes = new Map(\n packages.map((packageContext) => {\n const node = createFocusPackageNode(packageContext);\n return [node.id, node] as const;\n }),\n );\n\n for (const node of fragments.flatMap(({ nodes: fragmentNodes }) => fragmentNodes)) {\n if (!nodes.has(node.id)) nodes.set(node.id, node);\n }\n\n const edges = fragments.flatMap(({ edges: fragmentEdges }) => fragmentEdges);\n return createGraph({ nodes: [...nodes.values()], edges });\n}\n\ninterface InspectedInput {\n readonly inspection: ProjectInspection;\n readonly packages: readonly DependencyGraphPackage[];\n}\n\n/*** Inspect one input and normalize its package/workspace contexts. */\nasync function inspectProjectInputAsync(\n project: DependencyGraphProjectInput,\n signal: AbortSignal | undefined,\n): Promise<InspectedInput> {\n const inspection = await inspectProjectAsync(project.rootPath, {\n ...(signal === undefined ? {} : { signal }),\n });\n if (!inspection.complete) {\n throw new Error(\n `Dependency graph inspection is incomplete for \"${project.id}\": ${inspection.diagnostics\n .map(({ message }) => message)\n .join('; ')}`,\n );\n }\n\n const detectedPackages: readonly InspectedPackage[] =\n inspection.packages.length > 0\n ? inspection.packages\n : [{ rootPath: '.', detection: inspection.detection, manifestPath: '' }];\n\n const packages = await Promise.all(\n detectedPackages.map(async (detected) => {\n const relativeRoot = detected.rootPath;\n const id = `${project.id}:${relativeRoot}`;\n const manifestPath =\n detected.manifestPath === ''\n ? undefined\n : path.join(inspection.rootPath, detected.manifestPath);\n\n return {\n id,\n nodeId: `package:${id}`,\n projectId: project.id,\n rootPath: path.resolve(inspection.rootPath, relativeRoot),\n relativeRoot,\n ...(detected.name === undefined ? {} : { name: detected.name }),\n detection: detected.detection,\n declarations: await readDependencyDeclarationsAsync(manifestPath),\n } satisfies DependencyGraphPackage;\n }),\n );\n return { inspection, packages };\n}\n\n/*** Analyze each package with the first compatible analyzer and retain mixed-language packages safely. */\nasync function analyzePackagesAsync(\n inspected: readonly InspectedInput[],\n analyzers: readonly DependencyGraphAnalyzer[],\n focusPackages: ReadonlyMap<string, string>,\n signal: AbortSignal | undefined,\n): Promise<readonly DependencyGraphFragment[]> {\n const tasks = inspected.flatMap(({ inspection, packages }) =>\n packages.flatMap((packageContext) => {\n const analyzer = analyzers.find(({ supports }) => supports(packageContext.detection));\n if (analyzer === undefined) return [];\n\n const excludedRoots = packages\n .filter(\n (candidate) =>\n candidate.id !== packageContext.id &&\n candidate.rootPath.startsWith(`${packageContext.rootPath}${path.sep}`),\n )\n .map(({ rootPath }) => rootPath);\n\n return [\n analyzer.analyzeAsync({\n package: packageContext,\n inspection,\n focusPackages,\n excludedRoots,\n ...(signal === undefined ? {} : { signal }),\n }),\n ];\n }),\n );\n\n if (tasks.length === 0) {\n throw new Error('No dependency graph analyzer supports the supplied projects.');\n }\n return Promise.all(tasks);\n}\n\n/*** Build a unique package-name map for focus routing across repositories and workspaces. */\nfunction createFocusPackageMap(\n packages: readonly DependencyGraphPackage[],\n): ReadonlyMap<string, string> {\n const named = packages.filter(\n (packageContext): packageContext is DependencyGraphPackage & { readonly name: string } =>\n packageContext.name !== undefined,\n );\n const duplicates = named.filter(\n (item, index) => named.findIndex(({ name }) => name === item.name) !== index,\n );\n if (duplicates.length > 0) {\n throw new Error(`Duplicate focus package name: ${duplicates[0]?.name ?? 'unknown'}.`);\n }\n return new Map(named.map(({ name, nodeId }) => [name, nodeId]));\n}\n\n/*** Reject ambiguous project IDs before filesystem inspection. */\nfunction assertProjectInputs(projects: readonly DependencyGraphProjectInput[]): void {\n if (projects.length === 0) {\n throw new Error('At least one dependency graph project is required.');\n }\n\n const ids = projects.map(({ id }) => id);\n if (ids.some((id) => id.trim() === '')) {\n throw new Error('Dependency graph project IDs must be non-empty.');\n }\n if (new Set(ids).size !== ids.length) {\n throw new Error('Dependency graph project IDs must be unique.');\n }\n}\n"]}
1
+ {"version":3,"file":"createDependencyGraphAsync.js","sourceRoot":"","sources":["../../../../src/features/dependency-analysis/application/createDependencyGraphAsync.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAWvE,OAAO,EAAE,0BAA0B,EAAE,MAAM,wDAAwD,CAAC;AACpG,OAAO,EAAE,2BAA2B,EAAE,MAAM,0DAA0D,CAAC;AACvG,OAAO,EAAE,6BAA6B,EAAE,MAAM,8DAA8D,CAAC;AAC7G,OAAO,EAAE,6BAA6B,EAAE,MAAM,8DAA8D,CAAC;AAC7G,OAAO,EAAE,iCAAiC,EAAE,MAAM,sEAAsE,CAAC;AACzH,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,EAAE,+BAA+B,EAAE,MAAM,8CAA8C,CAAC;AAE/F,sGAAsG;AACtG,MAAM,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C;IACD,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,kEAAkE;AAClE,SAAS,mBAAmB,CAAC,QAAgD;IAC3E,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;IACxE,CAAC;IAED,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;IACzC,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;IACD,IAAI,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,MAAM,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;AACH,CAAC","sourcesContent":["import path from 'node:path';\n\nimport { createGraph } from '@ankhorage/graph';\nimport { inspectProjectAsync } from '@ankhorage/project-detector/node';\nimport type { InspectedPackage, ProjectInspection } from '@ankhorage/project-detector/types';\n\nimport type {\n CreateDependencyGraphInput,\n DependencyGraph,\n DependencyGraphAnalyzer,\n DependencyGraphFragment,\n DependencyGraphPackage,\n DependencyGraphProjectInput,\n} from '../../../types/dependencyGraph.js';\nimport { cppDependencyGraphAnalyzer } from '../adapters/outbound/cpp/cppDependencyGraphAnalyzer.js';\nimport { javaDependencyGraphAnalyzer } from '../adapters/outbound/java/javaDependencyGraphAnalyzer.js';\nimport { kotlinDependencyGraphAnalyzer } from '../adapters/outbound/kotlin/kotlinDependencyGraphAnalyzer.js';\nimport { pythonDependencyGraphAnalyzer } from '../adapters/outbound/python/pythonDependencyGraphAnalyzer.js';\nimport { typescriptDependencyGraphAnalyzer } from '../adapters/outbound/typescript/typescriptDependencyGraphAnalyzer.js';\nimport { createFocusPackageNode } from '../domain/createFocusPackageNode.js';\nimport { readDependencyDeclarationsAsync } from '../domain/readDependencyDeclarationsAsync.js';\n\n/*** Inspect projects, run supported analyzers and combine their evidence into one canonical graph. */\nexport async function createDependencyGraphAsync(\n input: CreateDependencyGraphInput,\n): Promise<DependencyGraph> {\n assertProjectInputs(input.projects);\n const analyzers = input.analyzers ?? [\n typescriptDependencyGraphAnalyzer,\n cppDependencyGraphAnalyzer,\n javaDependencyGraphAnalyzer,\n kotlinDependencyGraphAnalyzer,\n pythonDependencyGraphAnalyzer,\n ];\n const inspected = await Promise.all(\n input.projects.map((project) => inspectProjectInputAsync(project, input.signal)),\n );\n const packages = inspected.flatMap(({ packages }) => packages);\n const focusPackages = createFocusPackageMap(packages);\n const fragments = await analyzePackagesAsync(inspected, analyzers, focusPackages, input.signal);\n const nodes = new Map(\n packages.map((packageContext) => {\n const node = createFocusPackageNode(packageContext);\n return [node.id, node] as const;\n }),\n );\n\n for (const node of fragments.flatMap(({ nodes: fragmentNodes }) => fragmentNodes)) {\n if (!nodes.has(node.id)) nodes.set(node.id, node);\n }\n\n const edges = fragments.flatMap(({ edges: fragmentEdges }) => fragmentEdges);\n return createGraph({ nodes: [...nodes.values()], edges });\n}\n\ninterface InspectedInput {\n readonly inspection: ProjectInspection;\n readonly packages: readonly DependencyGraphPackage[];\n}\n\n/*** Inspect one input and normalize its package/workspace contexts. */\nasync function inspectProjectInputAsync(\n project: DependencyGraphProjectInput,\n signal: AbortSignal | undefined,\n): Promise<InspectedInput> {\n const inspection = await inspectProjectAsync(project.rootPath, {\n ...(signal === undefined ? {} : { signal }),\n });\n if (!inspection.complete) {\n throw new Error(\n `Dependency graph inspection is incomplete for \"${project.id}\": ${inspection.diagnostics\n .map(({ message }) => message)\n .join('; ')}`,\n );\n }\n\n const detectedPackages: readonly InspectedPackage[] =\n inspection.packages.length > 0\n ? inspection.packages\n : [{ rootPath: '.', detection: inspection.detection, manifestPath: '' }];\n\n const packages = await Promise.all(\n detectedPackages.map(async (detected) => {\n const relativeRoot = detected.rootPath;\n const id = `${project.id}:${relativeRoot}`;\n const manifestPath =\n detected.manifestPath === ''\n ? undefined\n : path.join(inspection.rootPath, detected.manifestPath);\n\n return {\n id,\n nodeId: `package:${id}`,\n projectId: project.id,\n rootPath: path.resolve(inspection.rootPath, relativeRoot),\n relativeRoot,\n ...(detected.name === undefined ? {} : { name: detected.name }),\n detection: detected.detection,\n declarations: await readDependencyDeclarationsAsync(manifestPath),\n } satisfies DependencyGraphPackage;\n }),\n );\n return { inspection, packages };\n}\n\n/*** Analyze each package with the first compatible analyzer and retain mixed-language packages safely. */\nasync function analyzePackagesAsync(\n inspected: readonly InspectedInput[],\n analyzers: readonly DependencyGraphAnalyzer[],\n focusPackages: ReadonlyMap<string, string>,\n signal: AbortSignal | undefined,\n): Promise<readonly DependencyGraphFragment[]> {\n const tasks = inspected.flatMap(({ inspection, packages }) =>\n packages.flatMap((packageContext) => {\n const analyzer = analyzers.find(({ supports }) => supports(packageContext.detection));\n if (analyzer === undefined) return [];\n\n const excludedRoots = packages\n .filter(\n (candidate) =>\n candidate.id !== packageContext.id &&\n candidate.rootPath.startsWith(`${packageContext.rootPath}${path.sep}`),\n )\n .map(({ rootPath }) => rootPath);\n\n return [\n analyzer.analyzeAsync({\n package: packageContext,\n inspection,\n focusPackages,\n excludedRoots,\n ...(signal === undefined ? {} : { signal }),\n }),\n ];\n }),\n );\n\n if (tasks.length === 0) {\n throw new Error('No dependency graph analyzer supports the supplied projects.');\n }\n return Promise.all(tasks);\n}\n\n/*** Build a unique package-name map for focus routing across repositories and workspaces. */\nfunction createFocusPackageMap(\n packages: readonly DependencyGraphPackage[],\n): ReadonlyMap<string, string> {\n const named = packages.filter(\n (packageContext): packageContext is DependencyGraphPackage & { readonly name: string } =>\n packageContext.name !== undefined,\n );\n const duplicates = named.filter(\n (item, index) => named.findIndex(({ name }) => name === item.name) !== index,\n );\n if (duplicates.length > 0) {\n throw new Error(`Duplicate focus package name: ${duplicates[0]?.name ?? 'unknown'}.`);\n }\n return new Map(named.map(({ name, nodeId }) => [name, nodeId]));\n}\n\n/*** Reject ambiguous project IDs before filesystem inspection. */\nfunction assertProjectInputs(projects: readonly DependencyGraphProjectInput[]): void {\n if (projects.length === 0) {\n throw new Error('At least one dependency graph project is required.');\n }\n\n const ids = projects.map(({ id }) => id);\n if (ids.some((id) => id.trim() === '')) {\n throw new Error('Dependency graph project IDs must be non-empty.');\n }\n if (new Set(ids).size !== ids.length) {\n throw new Error('Dependency graph project IDs must be unique.');\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ankhorage/dependency-graph",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "description": "Project-aware dependency analysis that produces canonical Ankhorage graphs.",
6
6
  "license": "MIT",