@ankhorage/dependency-graph 0.4.0 → 0.6.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.
- package/CHANGELOG.md +12 -0
- package/dist/dependencyGraph.d.ts +2 -0
- package/dist/dependencyGraph.d.ts.map +1 -1
- package/dist/dependencyGraph.js +2 -0
- package/dist/dependencyGraph.js.map +1 -1
- package/dist/features/dependency-analysis/adapters/outbound/cpp/analyzeCppProjectAsync.d.ts +4 -0
- package/dist/features/dependency-analysis/adapters/outbound/cpp/analyzeCppProjectAsync.d.ts.map +1 -0
- package/dist/features/dependency-analysis/adapters/outbound/cpp/analyzeCppProjectAsync.js +103 -0
- package/dist/features/dependency-analysis/adapters/outbound/cpp/analyzeCppProjectAsync.js.map +1 -0
- package/dist/features/dependency-analysis/adapters/outbound/cpp/collectCppFilesAsync.d.ts +3 -0
- package/dist/features/dependency-analysis/adapters/outbound/cpp/collectCppFilesAsync.d.ts.map +1 -0
- package/dist/features/dependency-analysis/adapters/outbound/cpp/collectCppFilesAsync.js +43 -0
- package/dist/features/dependency-analysis/adapters/outbound/cpp/collectCppFilesAsync.js.map +1 -0
- package/dist/features/dependency-analysis/adapters/outbound/cpp/cppDependencyGraphAnalyzer.d.ts +4 -0
- package/dist/features/dependency-analysis/adapters/outbound/cpp/cppDependencyGraphAnalyzer.d.ts.map +1 -0
- package/dist/features/dependency-analysis/adapters/outbound/cpp/cppDependencyGraphAnalyzer.js +8 -0
- package/dist/features/dependency-analysis/adapters/outbound/cpp/cppDependencyGraphAnalyzer.js.map +1 -0
- package/dist/features/dependency-analysis/adapters/outbound/cpp/extractCppDependencies.d.ts +11 -0
- package/dist/features/dependency-analysis/adapters/outbound/cpp/extractCppDependencies.d.ts.map +1 -0
- package/dist/features/dependency-analysis/adapters/outbound/cpp/extractCppDependencies.js +10 -0
- package/dist/features/dependency-analysis/adapters/outbound/cpp/extractCppDependencies.js.map +1 -0
- package/dist/features/dependency-analysis/adapters/outbound/cpp/extractCppPackageFromInclude.d.ts +3 -0
- package/dist/features/dependency-analysis/adapters/outbound/cpp/extractCppPackageFromInclude.d.ts.map +1 -0
- package/dist/features/dependency-analysis/adapters/outbound/cpp/extractCppPackageFromInclude.js +9 -0
- package/dist/features/dependency-analysis/adapters/outbound/cpp/extractCppPackageFromInclude.js.map +1 -0
- package/dist/features/dependency-analysis/adapters/outbound/delphi/analyzeDelphiProjectAsync.d.ts +4 -0
- package/dist/features/dependency-analysis/adapters/outbound/delphi/analyzeDelphiProjectAsync.d.ts.map +1 -0
- package/dist/features/dependency-analysis/adapters/outbound/delphi/analyzeDelphiProjectAsync.js +105 -0
- package/dist/features/dependency-analysis/adapters/outbound/delphi/analyzeDelphiProjectAsync.js.map +1 -0
- package/dist/features/dependency-analysis/adapters/outbound/delphi/collectDelphiFilesAsync.d.ts +3 -0
- package/dist/features/dependency-analysis/adapters/outbound/delphi/collectDelphiFilesAsync.d.ts.map +1 -0
- package/dist/features/dependency-analysis/adapters/outbound/delphi/collectDelphiFilesAsync.js +43 -0
- package/dist/features/dependency-analysis/adapters/outbound/delphi/collectDelphiFilesAsync.js.map +1 -0
- package/dist/features/dependency-analysis/adapters/outbound/delphi/delphiDependencyGraphAnalyzer.d.ts +4 -0
- package/dist/features/dependency-analysis/adapters/outbound/delphi/delphiDependencyGraphAnalyzer.d.ts.map +1 -0
- package/dist/features/dependency-analysis/adapters/outbound/delphi/delphiDependencyGraphAnalyzer.js +8 -0
- package/dist/features/dependency-analysis/adapters/outbound/delphi/delphiDependencyGraphAnalyzer.js.map +1 -0
- package/dist/features/dependency-analysis/adapters/outbound/delphi/delphiPackageForFile.d.ts +3 -0
- package/dist/features/dependency-analysis/adapters/outbound/delphi/delphiPackageForFile.d.ts.map +1 -0
- package/dist/features/dependency-analysis/adapters/outbound/delphi/delphiPackageForFile.js +17 -0
- package/dist/features/dependency-analysis/adapters/outbound/delphi/delphiPackageForFile.js.map +1 -0
- package/dist/features/dependency-analysis/adapters/outbound/delphi/extractDelphiDependencies.d.ts +7 -0
- package/dist/features/dependency-analysis/adapters/outbound/delphi/extractDelphiDependencies.d.ts.map +1 -0
- package/dist/features/dependency-analysis/adapters/outbound/delphi/extractDelphiDependencies.js +13 -0
- package/dist/features/dependency-analysis/adapters/outbound/delphi/extractDelphiDependencies.js.map +1 -0
- package/dist/features/dependency-analysis/adapters/outbound/delphi/extractDelphiPackageFromImport.d.ts +3 -0
- package/dist/features/dependency-analysis/adapters/outbound/delphi/extractDelphiPackageFromImport.d.ts.map +1 -0
- package/dist/features/dependency-analysis/adapters/outbound/delphi/extractDelphiPackageFromImport.js +6 -0
- package/dist/features/dependency-analysis/adapters/outbound/delphi/extractDelphiPackageFromImport.js.map +1 -0
- package/dist/features/dependency-analysis/application/createDependencyGraphAsync.d.ts.map +1 -1
- package/dist/features/dependency-analysis/application/createDependencyGraphAsync.js +4 -0
- package/dist/features/dependency-analysis/application/createDependencyGraphAsync.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ankhorage/dependency-graph
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- c037021: Add canonical Delphi unit/import dependency analysis.
|
|
8
|
+
|
|
9
|
+
## 0.5.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 7174cf6: Add canonical C++ include/dependency analysis.
|
|
14
|
+
|
|
3
15
|
## 0.4.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { cppDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/cpp/cppDependencyGraphAnalyzer.js';
|
|
2
|
+
export { delphiDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/delphi/delphiDependencyGraphAnalyzer.js';
|
|
1
3
|
export { javaDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/java/javaDependencyGraphAnalyzer.js';
|
|
2
4
|
export { kotlinDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/kotlin/kotlinDependencyGraphAnalyzer.js';
|
|
3
5
|
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,6BAA6B,EAAE,MAAM,0FAA0F,CAAC;AACzI,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"}
|
package/dist/dependencyGraph.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { cppDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/cpp/cppDependencyGraphAnalyzer.js';
|
|
2
|
+
export { delphiDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/delphi/delphiDependencyGraphAnalyzer.js';
|
|
1
3
|
export { javaDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/java/javaDependencyGraphAnalyzer.js';
|
|
2
4
|
export { kotlinDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/kotlin/kotlinDependencyGraphAnalyzer.js';
|
|
3
5
|
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,6BAA6B,EAAE,MAAM,0FAA0F,CAAC;AACzI,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 { delphiDependencyGraphAnalyzer } from './features/dependency-analysis/adapters/outbound/delphi/delphiDependencyGraphAnalyzer.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
|
package/dist/features/dependency-analysis/adapters/outbound/cpp/analyzeCppProjectAsync.d.ts.map
ADDED
|
@@ -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;AAEj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I,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE,OAAO;QAC1B,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE;YACZ,EAAE;YACF,IAAI,EAAE;gBACJ,IAAI,EAAE,QAAQ;gBACd,cAAc,EAAE,WAAW;gBAC3B,KAAK,EAAE,IAAI;gBACX,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,OAAO;gBAC3C,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,SAAS;gBACpC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,OAAO,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,IAAI,MAAM,WAAW,CAAC;AAE7B,yGAAyG;AACzG,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,QAAgB,EAChB,WAA8B,EAC9B,aAAgC,EAChC,MAA+B;IAE/B,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,GAAG,CAC7B,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAC7B,mBAAmB,CACjB,UAAU,KAAK,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,EACl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AAI,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"]}
|
package/dist/features/dependency-analysis/adapters/outbound/cpp/cppDependencyGraphAnalyzer.d.ts
ADDED
|
@@ -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
|
package/dist/features/dependency-analysis/adapters/outbound/cpp/cppDependencyGraphAnalyzer.d.ts.map
ADDED
|
@@ -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
|
package/dist/features/dependency-analysis/adapters/outbound/cpp/cppDependencyGraphAnalyzer.js.map
ADDED
|
@@ -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
|
package/dist/features/dependency-analysis/adapters/outbound/cpp/extractCppDependencies.d.ts.map
ADDED
|
@@ -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 @@
|
|
|
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"}
|
package/dist/features/dependency-analysis/adapters/outbound/cpp/extractCppPackageFromInclude.js
ADDED
|
@@ -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
|
package/dist/features/dependency-analysis/adapters/outbound/cpp/extractCppPackageFromInclude.js.map
ADDED
|
@@ -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"]}
|
package/dist/features/dependency-analysis/adapters/outbound/delphi/analyzeDelphiProjectAsync.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DependencyGraphAnalyzerContext, DependencyGraphFragment } from '../../../../../types/dependencyGraph.js';
|
|
2
|
+
/*** Analyze one detected Delphi package into unit/import dependency evidence. */
|
|
3
|
+
export declare function analyzeDelphiProjectAsync(context: DependencyGraphAnalyzerContext): Promise<DependencyGraphFragment>;
|
|
4
|
+
//# sourceMappingURL=analyzeDelphiProjectAsync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyzeDelphiProjectAsync.d.ts","sourceRoot":"","sources":["../../../../../../src/features/dependency-analysis/adapters/outbound/delphi/analyzeDelphiProjectAsync.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,8BAA8B,EAE9B,uBAAuB,EAGxB,MAAM,yCAAyC,CAAC;AAMjD,iFAAiF;AACjF,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,8BAA8B,GACtC,OAAO,CAAC,uBAAuB,CAAC,CAuClC"}
|
package/dist/features/dependency-analysis/adapters/outbound/delphi/analyzeDelphiProjectAsync.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { toPortablePath } from '@ankhorage/utility/node/path';
|
|
4
|
+
import { collectDelphiFilesAsync } from './collectDelphiFilesAsync.js';
|
|
5
|
+
import { delphiPackageForFile } from './delphiPackageForFile.js';
|
|
6
|
+
import { extractDelphiDependencies } from './extractDelphiDependencies.js';
|
|
7
|
+
import { extractDelphiPackageFromImport } from './extractDelphiPackageFromImport.js';
|
|
8
|
+
/*** Analyze one detected Delphi package into unit/import dependency evidence. */
|
|
9
|
+
export async function analyzeDelphiProjectAsync(context) {
|
|
10
|
+
const language = context.package.detection.languages.find(({ id }) => id === 'delphi');
|
|
11
|
+
const sourceRoots = language?.sourceRoots ?? ['src', 'Source', '.'];
|
|
12
|
+
const files = await collectDelphiFilesAsync(context.package.rootPath, sourceRoots, context.excludedRoots, context.signal);
|
|
13
|
+
const sources = await Promise.all(files.map(async (file) => {
|
|
14
|
+
const dependencies = extractDelphiDependencies(await readFile(file, 'utf8'));
|
|
15
|
+
return {
|
|
16
|
+
file,
|
|
17
|
+
dependencies,
|
|
18
|
+
packageName: delphiPackageForFile(context.package.rootPath, sourceRoots, file, dependencies.unitName),
|
|
19
|
+
};
|
|
20
|
+
}));
|
|
21
|
+
const intrinsicPackages = new Set(sources.map(({ packageName }) => packageName).filter((packageName) => packageName !== ''));
|
|
22
|
+
const nodes = new Map();
|
|
23
|
+
for (const packageName of intrinsicPackages)
|
|
24
|
+
addIntrinsicHierarchy(context, packageName, nodes);
|
|
25
|
+
const edges = new Map();
|
|
26
|
+
for (const { file, packageName, dependencies } of sources) {
|
|
27
|
+
context.signal?.throwIfAborted();
|
|
28
|
+
const sourceNodeId = nodeIdForPackage(context, packageName);
|
|
29
|
+
for (const specifier of dependencies.imports) {
|
|
30
|
+
addImport(context, file, sourceNodeId, specifier, intrinsicPackages, nodes, edges);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return { nodes: [...nodes.values()], edges: [...edges.values()] };
|
|
34
|
+
}
|
|
35
|
+
/*** Aggregate one Delphi uses-clause import into stable target nodes and weighted evidence. */
|
|
36
|
+
function addImport(context, sourceFile, sourceNodeId, specifier, intrinsicPackages, nodes, edges) {
|
|
37
|
+
const targetPackage = extractDelphiPackageFromImport(specifier);
|
|
38
|
+
if (targetPackage === '')
|
|
39
|
+
return;
|
|
40
|
+
const intrinsic = intrinsicPackages.has(targetPackage);
|
|
41
|
+
const targetNodeId = intrinsic
|
|
42
|
+
? nodeIdForPackage(context, targetPackage)
|
|
43
|
+
: `unknown:${targetPackage}`;
|
|
44
|
+
if (targetNodeId === sourceNodeId)
|
|
45
|
+
return;
|
|
46
|
+
if (!intrinsic && !nodes.has(targetNodeId)) {
|
|
47
|
+
nodes.set(targetNodeId, {
|
|
48
|
+
id: targetNodeId,
|
|
49
|
+
data: {
|
|
50
|
+
kind: 'package',
|
|
51
|
+
classification: 'unknown',
|
|
52
|
+
focus: false,
|
|
53
|
+
label: targetPackage,
|
|
54
|
+
packageName: targetPackage,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const edgeId = `${sourceNodeId}->${targetNodeId}`;
|
|
59
|
+
const existing = edges.get(edgeId);
|
|
60
|
+
const evidence = {
|
|
61
|
+
sourceFile: toPortablePath(path.relative(context.package.rootPath, sourceFile)),
|
|
62
|
+
specifier,
|
|
63
|
+
classification: intrinsic ? 'intrinsic' : 'unknown',
|
|
64
|
+
declarations: [],
|
|
65
|
+
};
|
|
66
|
+
edges.set(edgeId, {
|
|
67
|
+
id: edgeId,
|
|
68
|
+
source: sourceNodeId,
|
|
69
|
+
target: targetNodeId,
|
|
70
|
+
data: {
|
|
71
|
+
kind: 'import',
|
|
72
|
+
analyzerId: 'delphi',
|
|
73
|
+
weight: (existing?.data.weight ?? 0) + 1,
|
|
74
|
+
evidence: [...(existing?.data.evidence ?? []), evidence],
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/*** Materialize a Delphi package and all ancestor package nodes. */
|
|
79
|
+
function addIntrinsicHierarchy(context, packageName, nodes) {
|
|
80
|
+
const segments = packageName.split('.');
|
|
81
|
+
segments.forEach((_, index) => {
|
|
82
|
+
const current = segments.slice(0, index + 1).join('.');
|
|
83
|
+
const id = nodeIdForPackage(context, current);
|
|
84
|
+
if (nodes.has(id))
|
|
85
|
+
return;
|
|
86
|
+
nodes.set(id, {
|
|
87
|
+
id,
|
|
88
|
+
data: {
|
|
89
|
+
kind: 'module',
|
|
90
|
+
classification: 'intrinsic',
|
|
91
|
+
focus: true,
|
|
92
|
+
label: current.split('.').at(-1) ?? current,
|
|
93
|
+
projectId: context.package.projectId,
|
|
94
|
+
...(context.package.name === undefined ? {} : { packageName: context.package.name }),
|
|
95
|
+
path: current,
|
|
96
|
+
parentPath: current.includes('.') ? current.split('.').slice(0, -1).join('.') : '',
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/*** Resolve a Delphi package node inside the current focus package. */
|
|
102
|
+
function nodeIdForPackage(context, packageName) {
|
|
103
|
+
return packageName === '' ? context.package.nodeId : `${context.package.nodeId}#${packageName}`;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=analyzeDelphiProjectAsync.js.map
|
package/dist/features/dependency-analysis/adapters/outbound/delphi/analyzeDelphiProjectAsync.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyzeDelphiProjectAsync.js","sourceRoot":"","sources":["../../../../../../src/features/dependency-analysis/adapters/outbound/delphi/analyzeDelphiProjectAsync.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,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AAErF,iFAAiF;AACjF,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,OAAuC;IAEvC,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC;IACvF,MAAM,WAAW,GAAG,QAAQ,EAAE,WAAW,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;IACpE,MAAM,KAAK,GAAG,MAAM,uBAAuB,CACzC,OAAO,CAAC,OAAO,CAAC,QAAQ,EACxB,WAAW,EACX,OAAO,CAAC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I,OAAO;gBAC3C,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,SAAS;gBACpC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,OAAO,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,uEAAuE;AACvE,SAAS,gBAAgB,CAAC,OAAuC,EAAE,WAAmB;IACpF,OAAO,WAAW,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,IAAI,WAAW,EAAE,CAAC;AAClG,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 { collectDelphiFilesAsync } from './collectDelphiFilesAsync.js';\nimport { delphiPackageForFile } from './delphiPackageForFile.js';\nimport { extractDelphiDependencies } from './extractDelphiDependencies.js';\nimport { extractDelphiPackageFromImport } from './extractDelphiPackageFromImport.js';\n\n/*** Analyze one detected Delphi package into unit/import dependency evidence. */\nexport async function analyzeDelphiProjectAsync(\n context: DependencyGraphAnalyzerContext,\n): Promise<DependencyGraphFragment> {\n const language = context.package.detection.languages.find(({ id }) => id === 'delphi');\n const sourceRoots = language?.sourceRoots ?? ['src', 'Source', '.'];\n const files = await collectDelphiFilesAsync(\n context.package.rootPath,\n sourceRoots,\n context.excludedRoots,\n context.signal,\n );\n const sources = await Promise.all(\n files.map(async (file) => {\n const dependencies = extractDelphiDependencies(await readFile(file, 'utf8'));\n return {\n file,\n dependencies,\n packageName: delphiPackageForFile(\n context.package.rootPath,\n sourceRoots,\n file,\n dependencies.unitName,\n ),\n };\n }),\n );\n const intrinsicPackages = new Set(\n sources.map(({ packageName }) => packageName).filter((packageName) => packageName !== ''),\n );\n const nodes = new Map<string, GraphNode<DependencyGraphNodeData>>();\n for (const packageName of intrinsicPackages) addIntrinsicHierarchy(context, packageName, nodes);\n const edges = new Map<string, GraphEdge<DependencyGraphEdgeData>>();\n\n for (const { file, packageName, dependencies } of sources) {\n context.signal?.throwIfAborted();\n const sourceNodeId = nodeIdForPackage(context, packageName);\n for (const specifier of dependencies.imports) {\n addImport(context, file, sourceNodeId, specifier, intrinsicPackages, nodes, edges);\n }\n }\n return { nodes: [...nodes.values()], edges: [...edges.values()] };\n}\n\n/*** Aggregate one Delphi uses-clause import into stable target nodes and weighted evidence. */\nfunction addImport(\n context: DependencyGraphAnalyzerContext,\n sourceFile: string,\n sourceNodeId: string,\n specifier: string,\n intrinsicPackages: ReadonlySet<string>,\n nodes: Map<string, GraphNode<DependencyGraphNodeData>>,\n edges: Map<string, GraphEdge<DependencyGraphEdgeData>>,\n): void {\n const targetPackage = extractDelphiPackageFromImport(specifier);\n if (targetPackage === '') return;\n const intrinsic = intrinsicPackages.has(targetPackage);\n const targetNodeId = intrinsic\n ? nodeIdForPackage(context, targetPackage)\n : `unknown:${targetPackage}`;\n if (targetNodeId === sourceNodeId) return;\n if (!intrinsic && !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 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,\n classification: intrinsic ? '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: 'delphi',\n weight: (existing?.data.weight ?? 0) + 1,\n evidence: [...(existing?.data.evidence ?? []), evidence],\n },\n });\n}\n\n/*** Materialize a Delphi package and all ancestor package nodes. */\nfunction addIntrinsicHierarchy(\n context: DependencyGraphAnalyzerContext,\n packageName: string,\n nodes: Map<string, GraphNode<DependencyGraphNodeData>>,\n): void {\n const segments = packageName.split('.');\n segments.forEach((_, index) => {\n const current = segments.slice(0, index + 1).join('.');\n const id = nodeIdForPackage(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 Delphi package node inside the current focus package. */\nfunction nodeIdForPackage(context: DependencyGraphAnalyzerContext, packageName: string): string {\n return packageName === '' ? context.package.nodeId : `${context.package.nodeId}#${packageName}`;\n}\n"]}
|
package/dist/features/dependency-analysis/adapters/outbound/delphi/collectDelphiFilesAsync.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/*** Collect deterministic Delphi source files without following symlinks or nested package roots. */
|
|
2
|
+
export declare function collectDelphiFilesAsync(rootPath: string, sourceRoots: readonly string[], excludedRoots: readonly string[], signal: AbortSignal | undefined): Promise<readonly string[]>;
|
|
3
|
+
//# sourceMappingURL=collectDelphiFilesAsync.d.ts.map
|
package/dist/features/dependency-analysis/adapters/outbound/delphi/collectDelphiFilesAsync.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectDelphiFilesAsync.d.ts","sourceRoot":"","sources":["../../../../../../src/features/dependency-analysis/adapters/outbound/delphi/collectDelphiFilesAsync.ts"],"names":[],"mappings":"AAGA,qGAAqG;AACrG,wBAAsB,uBAAuB,CAC3C,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 Delphi source files without following symlinks or nested package roots. */
|
|
4
|
+
export async function collectDelphiFilesAsync(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', 'lib']);
|
|
9
|
+
const delphiExtensions = ['.pas', '.pp', '.dpr'];
|
|
10
|
+
/*** Recursively collect supported Delphi 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
|
+
delphiExtensions.some((extension) => entry.name.toLowerCase().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=collectDelphiFilesAsync.js.map
|
package/dist/features/dependency-analysis/adapters/outbound/delphi/collectDelphiFilesAsync.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectDelphiFilesAsync.js","sourceRoot":"","sources":["../../../../../../src/features/dependency-analysis/adapters/outbound/delphi/collectDelphiFilesAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,qGAAqG;AACrG,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,QAAgB,EAChB,WAA8B,EAC9B,aAAgC,EAChC,MAA+B;IAE/B,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,GAAG,CAC7B,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAC7B,mBAAmB,CACjB,UAAU,KAAK,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAA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AAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,EAClF,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 Delphi source files without following symlinks or nested package roots. */\nexport async function collectDelphiFilesAsync(\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', 'lib']);\n\nconst delphiExtensions = ['.pas', '.pp', '.dpr'];\n\n/*** Recursively collect supported Delphi 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 delphiExtensions.some((extension) => entry.name.toLowerCase().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
|
+
/*** Delphi analyzer adapter selected from project-detector language evidence. */
|
|
3
|
+
export declare const delphiDependencyGraphAnalyzer: DependencyGraphAnalyzer;
|
|
4
|
+
//# sourceMappingURL=delphiDependencyGraphAnalyzer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delphiDependencyGraphAnalyzer.d.ts","sourceRoot":"","sources":["../../../../../../src/features/dependency-analysis/adapters/outbound/delphi/delphiDependencyGraphAnalyzer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAGvF,iFAAiF;AACjF,eAAO,MAAM,6BAA6B,EAAE,uBAI3C,CAAC"}
|
package/dist/features/dependency-analysis/adapters/outbound/delphi/delphiDependencyGraphAnalyzer.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { analyzeDelphiProjectAsync } from './analyzeDelphiProjectAsync.js';
|
|
2
|
+
/*** Delphi analyzer adapter selected from project-detector language evidence. */
|
|
3
|
+
export const delphiDependencyGraphAnalyzer = {
|
|
4
|
+
id: 'delphi',
|
|
5
|
+
supports: (detection) => detection.languages.some(({ id }) => id === 'delphi'),
|
|
6
|
+
analyzeAsync: analyzeDelphiProjectAsync,
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=delphiDependencyGraphAnalyzer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delphiDependencyGraphAnalyzer.js","sourceRoot":"","sources":["../../../../../../src/features/dependency-analysis/adapters/outbound/delphi/delphiDependencyGraphAnalyzer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,iFAAiF;AACjF,MAAM,CAAC,MAAM,6BAA6B,GAA4B;IACpE,EAAE,EAAE,QAAQ;IACZ,QAAQ,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,QAAQ,CAAC;IAC9E,YAAY,EAAE,yBAAyB;CACxC,CAAC","sourcesContent":["import type { DependencyGraphAnalyzer } from '../../../../../types/dependencyGraph.js';\nimport { analyzeDelphiProjectAsync } from './analyzeDelphiProjectAsync.js';\n\n/*** Delphi analyzer adapter selected from project-detector language evidence. */\nexport const delphiDependencyGraphAnalyzer: DependencyGraphAnalyzer = {\n id: 'delphi',\n supports: (detection) => detection.languages.some(({ id }) => id === 'delphi'),\n analyzeAsync: analyzeDelphiProjectAsync,\n};\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/*** Derive a Delphi package path from unit namespace or the owning source directory. */
|
|
2
|
+
export declare function delphiPackageForFile(rootPath: string, sourceRoots: readonly string[], file: string, unitName: string): string;
|
|
3
|
+
//# sourceMappingURL=delphiPackageForFile.d.ts.map
|
package/dist/features/dependency-analysis/adapters/outbound/delphi/delphiPackageForFile.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delphiPackageForFile.d.ts","sourceRoot":"","sources":["../../../../../../src/features/dependency-analysis/adapters/outbound/delphi/delphiPackageForFile.ts"],"names":[],"mappings":"AAIA,wFAAwF;AACxF,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,SAAS,MAAM,EAAE,EAC9B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACf,MAAM,CAUR"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { toPortablePath } from '@ankhorage/utility/node/path';
|
|
3
|
+
/*** Derive a Delphi package path from unit namespace or the owning source directory. */
|
|
4
|
+
export function delphiPackageForFile(rootPath, sourceRoots, file, unitName) {
|
|
5
|
+
if (unitName.includes('.'))
|
|
6
|
+
return unitName.split('.').slice(0, -1).join('.');
|
|
7
|
+
const roots = sourceRoots
|
|
8
|
+
.map((sourceRoot) => (sourceRoot === '.' ? rootPath : path.resolve(rootPath, sourceRoot)))
|
|
9
|
+
.filter((sourceRoot) => file === sourceRoot || file.startsWith(`${sourceRoot}${path.sep}`))
|
|
10
|
+
.sort((left, right) => right.length - left.length);
|
|
11
|
+
const analysisRoot = roots[0] ?? rootPath;
|
|
12
|
+
const relativeDirectory = path.dirname(path.relative(analysisRoot, file));
|
|
13
|
+
if (relativeDirectory === '.')
|
|
14
|
+
return '';
|
|
15
|
+
return toPortablePath(relativeDirectory).split('/').join('.');
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=delphiPackageForFile.js.map
|
package/dist/features/dependency-analysis/adapters/outbound/delphi/delphiPackageForFile.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delphiPackageForFile.js","sourceRoot":"","sources":["../../../../../../src/features/dependency-analysis/adapters/outbound/delphi/delphiPackageForFile.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,wFAAwF;AACxF,MAAM,UAAU,oBAAoB,CAClC,QAAgB,EAChB,WAA8B,EAC9B,IAAY,EACZ,QAAgB;IAEhB,IAAI,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC9E,MAAM,KAAK,GAAG,WAAW;SACtB,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,UAAU,KAAK,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC;SACzF,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,KAAK,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;SAC1F,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IACrD,MAAM,YAAY,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC;IAC1C,MAAM,iBAAiB,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC;IAC1E,IAAI,iBAAiB,KAAK,GAAG;QAAE,OAAO,EAAE,CAAC;IACzC,OAAO,cAAc,CAAC,iBAAiB,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAChE,CAAC","sourcesContent":["import path from 'node:path';\n\nimport { toPortablePath } from '@ankhorage/utility/node/path';\n\n/*** Derive a Delphi package path from unit namespace or the owning source directory. */\nexport function delphiPackageForFile(\n rootPath: string,\n sourceRoots: readonly string[],\n file: string,\n unitName: string,\n): string {\n if (unitName.includes('.')) return unitName.split('.').slice(0, -1).join('.');\n const roots = sourceRoots\n .map((sourceRoot) => (sourceRoot === '.' ? rootPath : path.resolve(rootPath, sourceRoot)))\n .filter((sourceRoot) => file === sourceRoot || file.startsWith(`${sourceRoot}${path.sep}`))\n .sort((left, right) => right.length - left.length);\n const analysisRoot = roots[0] ?? rootPath;\n const relativeDirectory = path.dirname(path.relative(analysisRoot, file));\n if (relativeDirectory === '.') return '';\n return toPortablePath(relativeDirectory).split('/').join('.');\n}\n"]}
|
package/dist/features/dependency-analysis/adapters/outbound/delphi/extractDelphiDependencies.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface DelphiDependencies {
|
|
2
|
+
readonly unitName: string;
|
|
3
|
+
readonly imports: readonly string[];
|
|
4
|
+
}
|
|
5
|
+
/*** Extract a Delphi unit declaration and uses-clause dependencies. */
|
|
6
|
+
export declare function extractDelphiDependencies(content: string): DelphiDependencies;
|
|
7
|
+
//# sourceMappingURL=extractDelphiDependencies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractDelphiDependencies.d.ts","sourceRoot":"","sources":["../../../../../../src/features/dependency-analysis/adapters/outbound/delphi/extractDelphiDependencies.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC;AAED,uEAAuE;AACvE,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB,CAU7E"}
|
package/dist/features/dependency-analysis/adapters/outbound/delphi/extractDelphiDependencies.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*** Extract a Delphi unit declaration and uses-clause dependencies. */
|
|
2
|
+
export function extractDelphiDependencies(content) {
|
|
3
|
+
const unitName = /\bunit\s+([A-Za-z_][A-Za-z0-9_.]*)\s*;/iu.exec(content)?.[1] ?? '';
|
|
4
|
+
const imports = Array.from(content.matchAll(/\buses\s+([\s\S]*?);/giu)).flatMap((match) => {
|
|
5
|
+
const clause = match[1] ?? '';
|
|
6
|
+
return clause
|
|
7
|
+
.split(',')
|
|
8
|
+
.map((unit) => unit.replace(/\s+in\s+['"].*?['"]/giu, '').trim())
|
|
9
|
+
.filter(Boolean);
|
|
10
|
+
});
|
|
11
|
+
return { unitName, imports };
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=extractDelphiDependencies.js.map
|
package/dist/features/dependency-analysis/adapters/outbound/delphi/extractDelphiDependencies.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractDelphiDependencies.js","sourceRoot":"","sources":["../../../../../../src/features/dependency-analysis/adapters/outbound/delphi/extractDelphiDependencies.ts"],"names":[],"mappings":"AAKA,uEAAuE;AACvE,MAAM,UAAU,yBAAyB,CAAC,OAAe;IACvD,MAAM,QAAQ,GAAG,0CAA0C,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACrF,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QACxF,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC9B,OAAO,MAAM;aACV,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,wBAAwB,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;aAChE,MAAM,CAAC,OAAO,CAAC,CAAC;IACrB,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;AAC/B,CAAC","sourcesContent":["export interface DelphiDependencies {\n readonly unitName: string;\n readonly imports: readonly string[];\n}\n\n/*** Extract a Delphi unit declaration and uses-clause dependencies. */\nexport function extractDelphiDependencies(content: string): DelphiDependencies {\n const unitName = /\\bunit\\s+([A-Za-z_][A-Za-z0-9_.]*)\\s*;/iu.exec(content)?.[1] ?? '';\n const imports = Array.from(content.matchAll(/\\buses\\s+([\\s\\S]*?);/giu)).flatMap((match) => {\n const clause = match[1] ?? '';\n return clause\n .split(',')\n .map((unit) => unit.replace(/\\s+in\\s+['\"].*?['\"]/giu, '').trim())\n .filter(Boolean);\n });\n return { unitName, imports };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractDelphiPackageFromImport.d.ts","sourceRoot":"","sources":["../../../../../../src/features/dependency-analysis/adapters/outbound/delphi/extractDelphiPackageFromImport.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,wBAAgB,8BAA8B,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAGxE"}
|
package/dist/features/dependency-analysis/adapters/outbound/delphi/extractDelphiPackageFromImport.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/*** Reduce a Delphi unit import to its PKGViz-compatible package target. */
|
|
2
|
+
export function extractDelphiPackageFromImport(specifier) {
|
|
3
|
+
const trimmed = specifier.trim();
|
|
4
|
+
return trimmed.split('.')[0] ?? trimmed;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=extractDelphiPackageFromImport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractDelphiPackageFromImport.js","sourceRoot":"","sources":["../../../../../../src/features/dependency-analysis/adapters/outbound/delphi/extractDelphiPackageFromImport.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,MAAM,UAAU,8BAA8B,CAAC,SAAiB;IAC9D,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC;IACjC,OAAO,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC;AAC1C,CAAC","sourcesContent":["/*** Reduce a Delphi unit import to its PKGViz-compatible package target. */\nexport function extractDelphiPackageFromImport(specifier: string): string {\n const trimmed = specifier.trim();\n return trimmed.split('.')[0] ?? trimmed;\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;
|
|
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;AAU3C,sGAAsG;AACtG,wBAAsB,0BAA0B,CAC9C,KAAK,EAAE,0BAA0B,GAChC,OAAO,CAAC,eAAe,CAAC,CA6B1B"}
|
|
@@ -1,6 +1,8 @@
|
|
|
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';
|
|
5
|
+
import { delphiDependencyGraphAnalyzer } from '../adapters/outbound/delphi/delphiDependencyGraphAnalyzer.js';
|
|
4
6
|
import { javaDependencyGraphAnalyzer } from '../adapters/outbound/java/javaDependencyGraphAnalyzer.js';
|
|
5
7
|
import { kotlinDependencyGraphAnalyzer } from '../adapters/outbound/kotlin/kotlinDependencyGraphAnalyzer.js';
|
|
6
8
|
import { pythonDependencyGraphAnalyzer } from '../adapters/outbound/python/pythonDependencyGraphAnalyzer.js';
|
|
@@ -12,6 +14,8 @@ export async function createDependencyGraphAsync(input) {
|
|
|
12
14
|
assertProjectInputs(input.projects);
|
|
13
15
|
const analyzers = input.analyzers ?? [
|
|
14
16
|
typescriptDependencyGraphAnalyzer,
|
|
17
|
+
cppDependencyGraphAnalyzer,
|
|
18
|
+
delphiDependencyGraphAnalyzer,
|
|
15
19
|
javaDependencyGraphAnalyzer,
|
|
16
20
|
kotlinDependencyGraphAnalyzer,
|
|
17
21
|
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,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,CAAC,KAAK,UAAU,0BAA0B,CAC9C,KAAiC;IAEjC,mBAAmB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACpC,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,IAAI;QACnC,iCAAiC;QACjC,2BAA2B;QAC3B,6BAA6B;QAC7B,6BAA6B;KAC9B,CAAC;IACF,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,GAAG,CACjC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,wBAAwB,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CACjF,CAAC;IACF,MAAM,QAAQ,GA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AAC;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,6BAA6B,EAAE,MAAM,8DAA8D,CAAC;AAC7G,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,CAAC,KAAK,UAAU,0BAA0B,CAC9C,KAAiC;IAEjC,mBAAmB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACpC,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,IAAI;QACnC,iCAAiC;QACjC,0BAA0B;QAC1B,6BAA6B;QAC7B,2BAA2B;QAC3B,6BAA6B;QAC7B,6BAA6B;KAC9B,CAAC;IACF,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,GAAG,CACjC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,wBAAwB,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CACjF,CAAC;IACF,MAAM,QAAQ,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,QAAQ,CAA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,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 { delphiDependencyGraphAnalyzer } from '../adapters/outbound/delphi/delphiDependencyGraphAnalyzer.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 delphiDependencyGraphAnalyzer,\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"]}
|