@ankhorage/dependency-graph 1.2.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/features/dependency-analysis/adapters/inbound/api/dependencyGraphApi.js +41 -4
- package/dist/features/dependency-analysis/adapters/inbound/api/dependencyGraphApi.js.map +1 -1
- package/dist/features/dependency-analysis/composition/createDependencyGraphAsync.d.ts.map +1 -1
- package/dist/features/dependency-analysis/composition/createDependencyGraphAsync.js +5 -3
- package/dist/features/dependency-analysis/composition/createDependencyGraphAsync.js.map +1 -1
- package/dist/features/dependency-analysis/domain/projectDependencyGraphFromSourceGraph.js +3 -1
- package/dist/features/dependency-analysis/domain/projectDependencyGraphFromSourceGraph.js.map +1 -1
- package/dist/types/dependencyGraph.d.ts +5 -1
- package/dist/types/dependencyGraph.d.ts.map +1 -1
- package/dist/types/dependencyGraph.js.map +1 -1
- package/dist/types/dependencyGraphApi.d.ts +2 -2
- package/dist/types/dependencyGraphApi.d.ts.map +1 -1
- package/dist/types/dependencyGraphApi.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ankhorage/dependency-graph
|
|
2
2
|
|
|
3
|
+
## 1.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 93a207f: Preserve distinct TypeScript root-module identities in dependency projections.
|
|
8
|
+
|
|
9
|
+
## 1.3.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 3815bdd: Allow the dependency-graph API action to consume a bounded project inspection so applications can share one inspection across graph and other project views.
|
|
14
|
+
|
|
3
15
|
## 1.2.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -57,13 +57,50 @@ function readDependencyGraphApiInput(input) {
|
|
|
57
57
|
}
|
|
58
58
|
/*** Validate one project identity/root pair accepted by dependency graph analysis. */
|
|
59
59
|
function isDependencyGraphProjectInput(value) {
|
|
60
|
+
if (typeof value !== 'object' ||
|
|
61
|
+
value === null ||
|
|
62
|
+
!('id' in value) ||
|
|
63
|
+
typeof value.id !== 'string' ||
|
|
64
|
+
value.id.length === 0)
|
|
65
|
+
return false;
|
|
66
|
+
if ('inspection' in value)
|
|
67
|
+
return isProjectInspection(value.inspection);
|
|
68
|
+
return 'rootPath' in value && typeof value.rootPath === 'string' && value.rootPath.length > 0;
|
|
69
|
+
}
|
|
70
|
+
/*** Validate the inspection fields read by canonical graph analysis. */
|
|
71
|
+
function isProjectInspection(value) {
|
|
72
|
+
return isInspectionScope(value) && isInspectionMetadata(value);
|
|
73
|
+
}
|
|
74
|
+
/*** Validate the bounded filesystem scope used by source readers. */
|
|
75
|
+
function isInspectionScope(value) {
|
|
60
76
|
return (typeof value === 'object' &&
|
|
61
77
|
value !== null &&
|
|
62
|
-
'id' in value &&
|
|
63
|
-
typeof value.id === 'string' &&
|
|
64
|
-
value.id.length > 0 &&
|
|
65
78
|
'rootPath' in value &&
|
|
66
79
|
typeof value.rootPath === 'string' &&
|
|
67
|
-
value.rootPath.length > 0
|
|
80
|
+
value.rootPath.length > 0 &&
|
|
81
|
+
'complete' in value &&
|
|
82
|
+
typeof value.complete === 'boolean' &&
|
|
83
|
+
'directories' in value &&
|
|
84
|
+
Array.isArray(value.directories) &&
|
|
85
|
+
value.directories.every((entry) => typeof entry === 'string') &&
|
|
86
|
+
'files' in value &&
|
|
87
|
+
Array.isArray(value.files) &&
|
|
88
|
+
value.files.every((entry) => typeof entry === 'string'));
|
|
89
|
+
}
|
|
90
|
+
/*** Validate metadata collections required for graph projection. */
|
|
91
|
+
function isInspectionMetadata(value) {
|
|
92
|
+
return (typeof value === 'object' &&
|
|
93
|
+
value !== null &&
|
|
94
|
+
'detection' in value &&
|
|
95
|
+
typeof value.detection === 'object' &&
|
|
96
|
+
value.detection !== null &&
|
|
97
|
+
'packages' in value &&
|
|
98
|
+
Array.isArray(value.packages) &&
|
|
99
|
+
'workspaces' in value &&
|
|
100
|
+
Array.isArray(value.workspaces) &&
|
|
101
|
+
'manifests' in value &&
|
|
102
|
+
Array.isArray(value.manifests) &&
|
|
103
|
+
'diagnostics' in value &&
|
|
104
|
+
Array.isArray(value.diagnostics));
|
|
68
105
|
}
|
|
69
106
|
//# sourceMappingURL=dependencyGraphApi.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependencyGraphApi.js","sourceRoot":"","sources":["../../../../../../src/features/dependency-analysis/adapters/inbound/api/dependencyGraphApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGlD,OAAO,EAAE,0BAA0B,EAAE,MAAM,oDAAoD,CAAC;AAEhG,sGAAsG;AACtG,MAAM,CAAC,MAAM,kBAAkB,GAAG,gBAAgB,CAAC;IACjD,UAAU,EAAE;QACV,EAAE,EAAE,kBAAkB;QACtB,MAAM,EAAE,UAAU;QAClB,QAAQ,EAAE,MAAM;QAChB,QAAQ,EAAE,MAAM;QAChB,SAAS,EAAE;YACT,OAAO,EAAE;gBACP,EAAE,EAAE,SAAS;gBACb,IAAI,EAAE,MAAM;gBACZ,UAAU,EAAE;oBACV,kBAAkB,EAAE;wBAClB,EAAE,EAAE,kBAAkB;wBACtB,UAAU,EAAE,SAAS;wBACrB,QAAQ,EAAE,MAAM;wBAChB,MAAM,EAAE,QAAQ;wBAChB,MAAM,EAAE,MAAM;wBACd,IAAI,EAAE,mBAAmB;qBAC1B;iBACF;aACF;SACF;KACF;IACD,QAAQ,EAAE;QACR,kBAAkB,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YACpC,MAAM,KAAK,GAAG,2BAA2B,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACxD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,OAAO;oBACL,MAAM,EAAE,GAAG;oBACX,IAAI,EAAE;wBACJ,KAAK,EAAE;4BACL,IAAI,EAAE,gCAAgC;4BACtC,WAAW,EAAE,kBAAkB;yBAChC;qBACF;iBACF,CAAC;YACJ,CAAC;YAED,OAAO;gBACL,IAAI,EAAE,MAAM,0BAA0B,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;aACrE,CAAC;QACJ,CAAC;KACF;CACF,CAAC,CAAC;AAEH,mGAAmG;AACnG,SAAS,2BAA2B,CAAC,KAAc;IACjD,IACE,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,CAAC,CAAC,UAAU,IAAI,KAAK,CAAC;QACtB,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC;QAC9B,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,6BAA6B,CAAC,EACpD,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;AACtC,CAAC;AAED,sFAAsF;AACtF,SAAS,6BAA6B,CACpC,KAAc;IAEd,
|
|
1
|
+
{"version":3,"file":"dependencyGraphApi.js","sourceRoot":"","sources":["../../../../../../src/features/dependency-analysis/adapters/inbound/api/dependencyGraphApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGlD,OAAO,EAAE,0BAA0B,EAAE,MAAM,oDAAoD,CAAC;AAEhG,sGAAsG;AACtG,MAAM,CAAC,MAAM,kBAAkB,GAAG,gBAAgB,CAAC;IACjD,UAAU,EAAE;QACV,EAAE,EAAE,kBAAkB;QACtB,MAAM,EAAE,UAAU;QAClB,QAAQ,EAAE,MAAM;QAChB,QAAQ,EAAE,MAAM;QAChB,SAAS,EAAE;YACT,OAAO,EAAE;gBACP,EAAE,EAAE,SAAS;gBACb,IAAI,EAAE,MAAM;gBACZ,UAAU,EAAE;oBACV,kBAAkB,EAAE;w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AQ;QACzB,KAAK,KAAK,IAAI;QACd,WAAW,IAAI,KAAK;QACpB,OAAO,KAAK,CAAC,SAAS,KAAK,QAAQ;QACnC,KAAK,CAAC,SAAS,KAAK,IAAI;QACxB,UAAU,IAAI,KAAK;QACnB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC;QAC7B,YAAY,IAAI,KAAK;QACrB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC;QAC/B,WAAW,IAAI,KAAK;QACpB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC;QAC9B,aAAa,IAAI,KAAK;QACtB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CACjC,CAAC;AACJ,CAAC","sourcesContent":["import { createApiRuntime } from '@ankhorage/api';\n\nimport type { DependencyGraphApiInput } from '../../../../../types/dependencyGraphApi.js';\nimport { createDependencyGraphAsync } from '../../../composition/createDependencyGraphAsync.js';\n\n/*** Expose dependency graph creation through the canonical framework-neutral Ankhorage API action. */\nexport const dependencyGraphApi = createApiRuntime({\n definition: {\n id: 'dependency-graph',\n origin: 'internal',\n protocol: 'rest',\n basePath: '/api',\n endpoints: {\n actions: {\n id: 'actions',\n kind: 'http',\n operations: {\n 'dependency-graph': {\n id: 'dependency-graph',\n endpointId: 'actions',\n protocol: 'http',\n intent: 'action',\n method: 'POST',\n path: '/dependency-graph',\n },\n },\n },\n },\n },\n handlers: {\n 'dependency-graph': async (request) => {\n const input = readDependencyGraphApiInput(request.body);\n if (input === undefined) {\n return {\n status: 400,\n body: {\n error: {\n code: 'invalid_dependency_graph_input',\n operationId: 'dependency-graph',\n },\n },\n };\n }\n\n return {\n body: await createDependencyGraphAsync({ projects: input.projects }),\n };\n },\n },\n});\n\n/*** Validate the transport-neutral input before invoking filesystem-backed dependency analysis. */\nfunction readDependencyGraphApiInput(input: unknown): DependencyGraphApiInput | undefined {\n if (\n typeof input !== 'object' ||\n input === null ||\n !('projects' in input) ||\n !Array.isArray(input.projects) ||\n !input.projects.every(isDependencyGraphProjectInput)\n ) {\n return undefined;\n }\n\n return { projects: input.projects };\n}\n\n/*** Validate one project identity/root pair accepted by dependency graph analysis. */\nfunction isDependencyGraphProjectInput(\n value: unknown,\n): value is DependencyGraphApiInput['projects'][number] {\n if (\n typeof value !== 'object' ||\n value === null ||\n !('id' in value) ||\n typeof value.id !== 'string' ||\n value.id.length === 0\n )\n return false;\n if ('inspection' in value) return isProjectInspection(value.inspection);\n return 'rootPath' in value && typeof value.rootPath === 'string' && value.rootPath.length > 0;\n}\n\n/*** Validate the inspection fields read by canonical graph analysis. */\nfunction isProjectInspection(value: unknown): boolean {\n return isInspectionScope(value) && isInspectionMetadata(value);\n}\n\n/*** Validate the bounded filesystem scope used by source readers. */\nfunction isInspectionScope(value: unknown): boolean {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'rootPath' in value &&\n typeof value.rootPath === 'string' &&\n value.rootPath.length > 0 &&\n 'complete' in value &&\n typeof value.complete === 'boolean' &&\n 'directories' in value &&\n Array.isArray(value.directories) &&\n value.directories.every((entry: unknown) => typeof entry === 'string') &&\n 'files' in value &&\n Array.isArray(value.files) &&\n value.files.every((entry: unknown) => typeof entry === 'string')\n );\n}\n\n/*** Validate metadata collections required for graph projection. */\nfunction isInspectionMetadata(value: unknown): boolean {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'detection' in value &&\n typeof value.detection === 'object' &&\n value.detection !== null &&\n 'packages' in value &&\n Array.isArray(value.packages) &&\n 'workspaces' in value &&\n Array.isArray(value.workspaces) &&\n 'manifests' in value &&\n Array.isArray(value.manifests) &&\n 'diagnostics' in value &&\n Array.isArray(value.diagnostics)\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDependencyGraphAsync.d.ts","sourceRoot":"","sources":["../../../../src/features/dependency-analysis/composition/createDependencyGraphAsync.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,0BAA0B,EAC1B,eAAe,EAChB,MAAM,mCAAmC,CAAC;AAI3C,oGAAoG;AACpG,wBAAsB,0BAA0B,CAC9C,KAAK,EAAE,0BAA0B,GAChC,OAAO,CAAC,eAAe,CAAC,
|
|
1
|
+
{"version":3,"file":"createDependencyGraphAsync.d.ts","sourceRoot":"","sources":["../../../../src/features/dependency-analysis/composition/createDependencyGraphAsync.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,0BAA0B,EAC1B,eAAe,EAChB,MAAM,mCAAmC,CAAC;AAI3C,oGAAoG;AACpG,wBAAsB,0BAA0B,CAC9C,KAAK,EAAE,0BAA0B,GAChC,OAAO,CAAC,eAAe,CAAC,CAkB1B"}
|
|
@@ -6,9 +6,11 @@ export async function createDependencyGraphAsync(input) {
|
|
|
6
6
|
assertDependencyGraphProjectIds(input.projects);
|
|
7
7
|
const projects = await Promise.all(input.projects.map(async (project) => ({
|
|
8
8
|
id: project.id,
|
|
9
|
-
inspection:
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
inspection: 'inspection' in project
|
|
10
|
+
? project.inspection
|
|
11
|
+
: await inspectProjectAsync(project.rootPath, {
|
|
12
|
+
...(input.signal === undefined ? {} : { signal: input.signal }),
|
|
13
|
+
}),
|
|
12
14
|
})));
|
|
13
15
|
return createDependencyGraphFromInspectionsAsync({
|
|
14
16
|
projects,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDependencyGraphAsync.js","sourceRoot":"","sources":["../../../../src/features/dependency-analysis/composition/createDependencyGraphAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAMvE,OAAO,EAAE,+BAA+B,EAAE,MAAM,mDAAmD,CAAC;AACpG,OAAO,EAAE,yCAAyC,EAAE,MAAM,gDAAgD,CAAC;AAE3G,oGAAoG;AACpG,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,KAAiC;IAEjC,+BAA+B,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAChD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,CAChC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;QACrC,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,UAAU,
|
|
1
|
+
{"version":3,"file":"createDependencyGraphAsync.js","sourceRoot":"","sources":["../../../../src/features/dependency-analysis/composition/createDependencyGraphAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAMvE,OAAO,EAAE,+BAA+B,EAAE,MAAM,mDAAmD,CAAC;AACpG,OAAO,EAAE,yCAAyC,EAAE,MAAM,gDAAgD,CAAC;AAE3G,oGAAoG;AACpG,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,KAAiC;IAEjC,+BAA+B,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAChD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,CAChC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;QACrC,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,UAAU,EACR,YAAY,IAAI,OAAO;YACrB,CAAC,CAAC,OAAO,CAAC,UAAU;YACpB,CAAC,CAAC,MAAM,mBAAmB,CAAC,OAAO,CAAC,QAAQ,EAAE;gBAC1C,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;aAChE,CAAC;KACT,CAAC,CAAC,CACJ,CAAC;IAEF,OAAO,yCAAyC,CAAC;QAC/C,QAAQ;QACR,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;KAChE,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { inspectProjectAsync } from '@ankhorage/project-detector/node';\n\nimport type {\n CreateDependencyGraphInput,\n DependencyGraph,\n} from '../../../types/dependencyGraph.js';\nimport { assertDependencyGraphProjectIds } from '../application/assertDependencyGraphProjectIds.js';\nimport { createDependencyGraphFromInspectionsAsync } from './createDependencyGraphFromInspectionsAsync.js';\n\n/*** Inspect project roots, then delegate dependency topology construction to the inspection API. */\nexport async function createDependencyGraphAsync(\n input: CreateDependencyGraphInput,\n): Promise<DependencyGraph> {\n assertDependencyGraphProjectIds(input.projects);\n const projects = await Promise.all(\n input.projects.map(async (project) => ({\n id: project.id,\n inspection:\n 'inspection' in project\n ? project.inspection\n : await inspectProjectAsync(project.rootPath, {\n ...(input.signal === undefined ? {} : { signal: input.signal }),\n }),\n })),\n );\n\n return createDependencyGraphFromInspectionsAsync({\n projects,\n ...(input.signal === undefined ? {} : { signal: input.signal }),\n });\n}\n"]}
|
|
@@ -55,7 +55,9 @@ function moduleForFile(file, owner) {
|
|
|
55
55
|
? (file.filePath ?? '')
|
|
56
56
|
: (file.filePath ?? '').slice(owner.relativeRoot.length + 1);
|
|
57
57
|
const directory = relative.split('/').slice(0, -1).join('/');
|
|
58
|
-
|
|
58
|
+
if (directory !== '')
|
|
59
|
+
return directory.split('/').filter(Boolean).join('.');
|
|
60
|
+
return relative.replace(/\.[^.]+$/u, '');
|
|
59
61
|
}
|
|
60
62
|
/*** Preserve the existing package/module node identity and dotted ancestor structure. */
|
|
61
63
|
function addModuleHierarchy(nodes, owner, modulePath) {
|
package/dist/features/dependency-analysis/domain/projectDependencyGraphFromSourceGraph.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projectDependencyGraphFromSourceGraph.js","sourceRoot":"","sources":["../../../../src/features/dependency-analysis/domain/projectDependencyGraphFromSourceGraph.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAA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,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAA4B,EAAE,CAAC,CAAC;QACjE,UAAU,EACR,KAAK,CAAC,YAAY,KAAK,GAAG;YACxB,CAAC,CAAC,IAAI,CAAC,UAAU;YACjB,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC;QAC1D,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,EAAE;QAC/B,cAAc;QACd,YAAY,EAAE,IAAI,CAAC,YAAY,IAAI,EAAE;KACtC,CAAC,CAAC,CAAC;IACJ,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE;QACZ,EAAE;QACF,MAAM,EAAE,QAAQ;QAChB,MAAM,EAAE,QAAQ;QAChB,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,UAAU;YACV,MAAM,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,QAAQ,CAAC,MAAM;YACtD,QAAQ,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC,EAAE,GAAG,QAAQ,CAAC;SAC5D;KACF,CAAC,CAAC;AACL,CAAC;AAED,yEAAyE;AACzE,SAAS,YAAY,CAAC,KAA6B,EAAE,UAAkB;IACrE,OAAO,UAAU,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,IAAI,UAAU,EAAE,CAAC;AAC5E,CAAC","sourcesContent":["import type { GraphEdge, GraphNode } from '@ankhorage/graph';\nimport { createGraph } from '@ankhorage/graph';\n\nimport type {\n DependencyGraph,\n DependencyGraphEdgeData,\n DependencyGraphInspectionProjectInput,\n DependencyGraphNodeData,\n DependencyGraphPackage,\n DependencyImportEvidence,\n DependencyReferenceClassification,\n} from '../../../types/dependencyGraph.js';\nimport type {\n SourceGraph,\n SourceNodeData,\n SourceRelationEvidence,\n} from '../../../types/sourceGraph.js';\nimport { createFocusPackageNode } from './createFocusPackageNode.js';\n\n/*** Derive the established module/package dependency view from canonical source facts. */\nexport function projectDependencyGraphFromSourceGraph(\n sourceGraph: SourceGraph,\n packages: readonly DependencyGraphPackage[],\n projects: readonly DependencyGraphInspectionProjectInput[],\n): DependencyGraph {\n const detectedRoots = new Map(\n projects.map(\n ({ id, inspection }) => [id, inspection.packages.map(({ rootPath }) => rootPath)] as const,\n ),\n );\n const nodes = new Map<string, GraphNode<DependencyGraphNodeData>>(\n packages.map((item) => [item.nodeId, createFocusPackageNode(item)]),\n );\n const edges = new Map<string, GraphEdge<DependencyGraphEdgeData>>();\n const sourceNodes = new Map(sourceGraph.graph.nodes.map((node) => [node.id, node.data]));\n const files = sourceGraph.graph.nodes.filter(\n ({ data }) => data.kind === 'file' && data.analyzerId !== undefined,\n );\n for (const { data } of files) {\n const owner = packageForFile(packages, detectedRoots, data);\n if (owner !== undefined) addModuleHierarchy(nodes, owner, moduleForFile(data, owner));\n }\n for (const edge of sourceGraph.graph.edges) {\n if (edge.data.kind !== 'imports') continue;\n const source = sourceNodes.get(edge.source);\n const target = sourceNodes.get(edge.target);\n if (source === undefined || target === undefined) continue;\n const owner = packageForFile(packages, detectedRoots, source);\n if (owner === undefined || source.analyzerId === undefined) continue;\n const sourceId = moduleNodeId(owner, moduleForFile(source, owner));\n const targetId = projectTarget(target, owner, packages, detectedRoots, nodes);\n if (targetId === undefined || targetId === sourceId) continue;\n addProjectedEdge(\n edges,\n sourceId,\n targetId,\n source.analyzerId,\n owner,\n edge.data.evidence,\n target,\n );\n }\n return createGraph({ nodes: [...nodes.values()], edges: [...edges.values()] });\n}\n\n/*** Select the deepest focus package root containing one project-relative source file. */\nfunction packageForFile(\n packages: readonly DependencyGraphPackage[],\n detectedRoots: ReadonlyMap<string, readonly string[]>,\n file: SourceNodeData,\n): DependencyGraphPackage | undefined {\n if (file.filePath === undefined) return undefined;\n const { filePath } = file;\n const detected =\n (detectedRoots.get(file.projectId) ?? ['.'])\n .filter((root) => root === '.' || filePath === root || filePath.startsWith(`${root}/`))\n .sort((left, right) => right.length - left.length)[0] ?? '.';\n if (!packages.some((item) => item.projectId === file.projectId && item.relativeRoot === detected))\n return undefined;\n return packages\n .filter(\n (item) =>\n item.projectId === file.projectId &&\n (item.relativeRoot === '.' ||\n filePath === item.relativeRoot ||\n filePath.startsWith(`${item.relativeRoot}/`)),\n )\n .sort((left, right) => right.relativeRoot.length - left.relativeRoot.length)[0];\n}\n\n/*** Read the established dotted module path from one analyzed source file. */\nfunction moduleForFile(file: SourceNodeData, owner: DependencyGraphPackage): string {\n if (file.analyzerId !== 'typescript') return file.packageName ?? '';\n const relative =\n owner.relativeRoot === '.'\n ? (file.filePath ?? '')\n : (file.filePath ?? '').slice(owner.relativeRoot.length + 1);\n const directory = relative.split('/').slice(0, -1).join('/');\n return directory.split('/').filter(Boolean).join('.');\n}\n\n/*** Preserve the existing package/module node identity and dotted ancestor structure. */\nfunction addModuleHierarchy(\n nodes: Map<string, GraphNode<DependencyGraphNodeData>>,\n owner: DependencyGraphPackage,\n modulePath: string,\n): void {\n const parts = modulePath.split('.').filter(Boolean);\n parts.forEach((_, index) => {\n const current = parts.slice(0, index + 1).join('.');\n const id = moduleNodeId(owner, current);\n if (nodes.has(id)) return;\n nodes.set(id, {\n id,\n data: {\n kind: 'module',\n classification: 'intrinsic',\n focus: true,\n label: parts.at(index) ?? current,\n projectId: owner.projectId,\n ...(owner.name === undefined ? {} : { packageName: owner.name }),\n path: current,\n parentPath: index === 0 ? '' : parts.slice(0, index).join('.'),\n },\n });\n });\n}\n\n/*** Resolve canonical import targets to stable package/module projection identities. */\nfunction projectTarget(\n target: SourceNodeData,\n sourceOwner: DependencyGraphPackage,\n packages: readonly DependencyGraphPackage[],\n detectedRoots: ReadonlyMap<string, readonly string[]>,\n nodes: Map<string, GraphNode<DependencyGraphNodeData>>,\n): string | undefined {\n if (target.classification === 'vendor' || target.classification === 'unknown') {\n const name = target.packageName ?? target.name;\n const id = `${target.classification}:${name}`;\n if (!nodes.has(id))\n nodes.set(id, {\n id,\n data: {\n kind: 'package',\n classification: target.classification,\n focus: false,\n label: name,\n packageName: name,\n },\n });\n return id;\n }\n if (target.kind === 'package' && target.path !== undefined) {\n return packages.find(\n (item) => item.projectId === target.projectId && item.relativeRoot === target.path,\n )?.nodeId;\n }\n const owner =\n target.filePath === undefined ? sourceOwner : packageForFile(packages, detectedRoots, target);\n if (owner === undefined) return undefined;\n const modulePath =\n target.analyzerId === 'typescript' || target.kind === 'file'\n ? moduleForFile(target, owner)\n : (target.packageName ?? '');\n addModuleHierarchy(nodes, owner, modulePath);\n return moduleNodeId(owner, modulePath);\n}\n\n/*** Add one canonical import to a weighted package edge with original evidence. */\nfunction addProjectedEdge(\n edges: Map<string, GraphEdge<DependencyGraphEdgeData>>,\n sourceId: string,\n targetId: string,\n analyzerId: string,\n owner: DependencyGraphPackage,\n evidence: readonly SourceRelationEvidence[],\n target: SourceNodeData,\n): void {\n const id = `${sourceId}->${targetId}`;\n const previous = edges.get(id);\n const classification: DependencyReferenceClassification =\n target.kind === 'package' && target.path !== undefined\n ? 'focus'\n : (target.classification ?? 'unknown');\n const observed = evidence.map((item): DependencyImportEvidence => ({\n sourceFile:\n owner.relativeRoot === '.'\n ? item.sourcePath\n : item.sourcePath.slice(owner.relativeRoot.length + 1),\n specifier: item.specifier ?? '',\n classification,\n declarations: item.declarations ?? [],\n }));\n edges.set(id, {\n id,\n source: sourceId,\n target: targetId,\n data: {\n kind: 'import',\n analyzerId,\n weight: (previous?.data.weight ?? 0) + observed.length,\n evidence: [...(previous?.data.evidence ?? []), ...observed],\n },\n });\n}\n\n/*** Preserve the legacy projection's readable package/module node ID. */\nfunction moduleNodeId(owner: DependencyGraphPackage, modulePath: string): string {\n return modulePath === '' ? owner.nodeId : `${owner.nodeId}#${modulePath}`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"projectDependencyGraphFromSourceGraph.js","sourceRoot":"","sources":["../../../../src/features/dependency-analysis/domain/projectDependencyGraphFromSourceGraph.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAgB/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE,0FAA0F;AAC1F,MAAM,UAAU,qCAAqC,CACnD,WAAwB,EACxB,QAA2C,EAC3C,QAA0D;IAE1D,MAAM,aAAa,GAAG,IAAI,GAAG,CAC3B,QAAQ,CAAC,GAAG,CACV,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAU,CAC3F,CACF,CAAC;IACF,MAAM,KAAK,GAAG,IAAI,GAAG,CACnB,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC,CACpE,CAAC;IACF,MAAM,KAAK,GAAG,IAAI,GAAG,EAA8C,CAAC;IACpE,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACzF,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAC1C,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,UAAU,KAAK,SAAS,CACpE,CAAC;IACF,KAAK,MAAM,EAAE,IAAI,EAAE,IAAI,KAAK,EAAE,CAAC;QAC7B,MA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esContent":["import type { GraphEdge, GraphNode } from '@ankhorage/graph';\nimport { createGraph } from '@ankhorage/graph';\n\nimport type {\n DependencyGraph,\n DependencyGraphEdgeData,\n DependencyGraphInspectionProjectInput,\n DependencyGraphNodeData,\n DependencyGraphPackage,\n DependencyImportEvidence,\n DependencyReferenceClassification,\n} from '../../../types/dependencyGraph.js';\nimport type {\n SourceGraph,\n SourceNodeData,\n SourceRelationEvidence,\n} from '../../../types/sourceGraph.js';\nimport { createFocusPackageNode } from './createFocusPackageNode.js';\n\n/*** Derive the established module/package dependency view from canonical source facts. */\nexport function projectDependencyGraphFromSourceGraph(\n sourceGraph: SourceGraph,\n packages: readonly DependencyGraphPackage[],\n projects: readonly DependencyGraphInspectionProjectInput[],\n): DependencyGraph {\n const detectedRoots = new Map(\n projects.map(\n ({ id, inspection }) => [id, inspection.packages.map(({ rootPath }) => rootPath)] as const,\n ),\n );\n const nodes = new Map<string, GraphNode<DependencyGraphNodeData>>(\n packages.map((item) => [item.nodeId, createFocusPackageNode(item)]),\n );\n const edges = new Map<string, GraphEdge<DependencyGraphEdgeData>>();\n const sourceNodes = new Map(sourceGraph.graph.nodes.map((node) => [node.id, node.data]));\n const files = sourceGraph.graph.nodes.filter(\n ({ data }) => data.kind === 'file' && data.analyzerId !== undefined,\n );\n for (const { data } of files) {\n const owner = packageForFile(packages, detectedRoots, data);\n if (owner !== undefined) addModuleHierarchy(nodes, owner, moduleForFile(data, owner));\n }\n for (const edge of sourceGraph.graph.edges) {\n if (edge.data.kind !== 'imports') continue;\n const source = sourceNodes.get(edge.source);\n const target = sourceNodes.get(edge.target);\n if (source === undefined || target === undefined) continue;\n const owner = packageForFile(packages, detectedRoots, source);\n if (owner === undefined || source.analyzerId === undefined) continue;\n const sourceId = moduleNodeId(owner, moduleForFile(source, owner));\n const targetId = projectTarget(target, owner, packages, detectedRoots, nodes);\n if (targetId === undefined || targetId === sourceId) continue;\n addProjectedEdge(\n edges,\n sourceId,\n targetId,\n source.analyzerId,\n owner,\n edge.data.evidence,\n target,\n );\n }\n return createGraph({ nodes: [...nodes.values()], edges: [...edges.values()] });\n}\n\n/*** Select the deepest focus package root containing one project-relative source file. */\nfunction packageForFile(\n packages: readonly DependencyGraphPackage[],\n detectedRoots: ReadonlyMap<string, readonly string[]>,\n file: SourceNodeData,\n): DependencyGraphPackage | undefined {\n if (file.filePath === undefined) return undefined;\n const { filePath } = file;\n const detected =\n (detectedRoots.get(file.projectId) ?? ['.'])\n .filter((root) => root === '.' || filePath === root || filePath.startsWith(`${root}/`))\n .sort((left, right) => right.length - left.length)[0] ?? '.';\n if (!packages.some((item) => item.projectId === file.projectId && item.relativeRoot === detected))\n return undefined;\n return packages\n .filter(\n (item) =>\n item.projectId === file.projectId &&\n (item.relativeRoot === '.' ||\n filePath === item.relativeRoot ||\n filePath.startsWith(`${item.relativeRoot}/`)),\n )\n .sort((left, right) => right.relativeRoot.length - left.relativeRoot.length)[0];\n}\n\n/*** Read the established dotted module path from one analyzed source file. */\nfunction moduleForFile(file: SourceNodeData, owner: DependencyGraphPackage): string {\n if (file.analyzerId !== 'typescript') return file.packageName ?? '';\n const relative =\n owner.relativeRoot === '.'\n ? (file.filePath ?? '')\n : (file.filePath ?? '').slice(owner.relativeRoot.length + 1);\n const directory = relative.split('/').slice(0, -1).join('/');\n if (directory !== '') return directory.split('/').filter(Boolean).join('.');\n return relative.replace(/\\.[^.]+$/u, '');\n}\n\n/*** Preserve the existing package/module node identity and dotted ancestor structure. */\nfunction addModuleHierarchy(\n nodes: Map<string, GraphNode<DependencyGraphNodeData>>,\n owner: DependencyGraphPackage,\n modulePath: string,\n): void {\n const parts = modulePath.split('.').filter(Boolean);\n parts.forEach((_, index) => {\n const current = parts.slice(0, index + 1).join('.');\n const id = moduleNodeId(owner, current);\n if (nodes.has(id)) return;\n nodes.set(id, {\n id,\n data: {\n kind: 'module',\n classification: 'intrinsic',\n focus: true,\n label: parts.at(index) ?? current,\n projectId: owner.projectId,\n ...(owner.name === undefined ? {} : { packageName: owner.name }),\n path: current,\n parentPath: index === 0 ? '' : parts.slice(0, index).join('.'),\n },\n });\n });\n}\n\n/*** Resolve canonical import targets to stable package/module projection identities. */\nfunction projectTarget(\n target: SourceNodeData,\n sourceOwner: DependencyGraphPackage,\n packages: readonly DependencyGraphPackage[],\n detectedRoots: ReadonlyMap<string, readonly string[]>,\n nodes: Map<string, GraphNode<DependencyGraphNodeData>>,\n): string | undefined {\n if (target.classification === 'vendor' || target.classification === 'unknown') {\n const name = target.packageName ?? target.name;\n const id = `${target.classification}:${name}`;\n if (!nodes.has(id))\n nodes.set(id, {\n id,\n data: {\n kind: 'package',\n classification: target.classification,\n focus: false,\n label: name,\n packageName: name,\n },\n });\n return id;\n }\n if (target.kind === 'package' && target.path !== undefined) {\n return packages.find(\n (item) => item.projectId === target.projectId && item.relativeRoot === target.path,\n )?.nodeId;\n }\n const owner =\n target.filePath === undefined ? sourceOwner : packageForFile(packages, detectedRoots, target);\n if (owner === undefined) return undefined;\n const modulePath =\n target.analyzerId === 'typescript' || target.kind === 'file'\n ? moduleForFile(target, owner)\n : (target.packageName ?? '');\n addModuleHierarchy(nodes, owner, modulePath);\n return moduleNodeId(owner, modulePath);\n}\n\n/*** Add one canonical import to a weighted package edge with original evidence. */\nfunction addProjectedEdge(\n edges: Map<string, GraphEdge<DependencyGraphEdgeData>>,\n sourceId: string,\n targetId: string,\n analyzerId: string,\n owner: DependencyGraphPackage,\n evidence: readonly SourceRelationEvidence[],\n target: SourceNodeData,\n): void {\n const id = `${sourceId}->${targetId}`;\n const previous = edges.get(id);\n const classification: DependencyReferenceClassification =\n target.kind === 'package' && target.path !== undefined\n ? 'focus'\n : (target.classification ?? 'unknown');\n const observed = evidence.map((item): DependencyImportEvidence => ({\n sourceFile:\n owner.relativeRoot === '.'\n ? item.sourcePath\n : item.sourcePath.slice(owner.relativeRoot.length + 1),\n specifier: item.specifier ?? '',\n classification,\n declarations: item.declarations ?? [],\n }));\n edges.set(id, {\n id,\n source: sourceId,\n target: targetId,\n data: {\n kind: 'import',\n analyzerId,\n weight: (previous?.data.weight ?? 0) + observed.length,\n evidence: [...(previous?.data.evidence ?? []), ...observed],\n },\n });\n}\n\n/*** Preserve the legacy projection's readable package/module node ID. */\nfunction moduleNodeId(owner: DependencyGraphPackage, modulePath: string): string {\n return modulePath === '' ? owner.nodeId : `${owner.nodeId}#${modulePath}`;\n}\n"]}
|
|
@@ -35,6 +35,10 @@ export interface DependencyGraphProjectInput {
|
|
|
35
35
|
readonly id: string;
|
|
36
36
|
readonly rootPath: string;
|
|
37
37
|
}
|
|
38
|
+
export interface DependencyGraphInspectedProjectInput {
|
|
39
|
+
readonly id: string;
|
|
40
|
+
readonly inspection: ProjectInspection;
|
|
41
|
+
}
|
|
38
42
|
export interface DependencyGraphInspectionProjectInput {
|
|
39
43
|
readonly id: string;
|
|
40
44
|
readonly inspection: ProjectInspection;
|
|
@@ -47,7 +51,7 @@ export interface DependencyGraphPackage {
|
|
|
47
51
|
readonly name?: string;
|
|
48
52
|
}
|
|
49
53
|
export interface CreateDependencyGraphInput {
|
|
50
|
-
readonly projects: readonly DependencyGraphProjectInput[];
|
|
54
|
+
readonly projects: readonly (DependencyGraphProjectInput | DependencyGraphInspectedProjectInput)[];
|
|
51
55
|
readonly signal?: AbortSignal;
|
|
52
56
|
}
|
|
53
57
|
export interface CreateDependencyGraphFromInspectionsInput {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependencyGraph.d.ts","sourceRoot":"","sources":["../../src/types/dependencyGraph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAE3E,MAAM,MAAM,4BAA4B,GAAG,WAAW,GAAG,SAAS,GAAG,QAAQ,CAAC;AAC9E,MAAM,MAAM,iCAAiC,GAAG,4BAA4B,GAAG,OAAO,CAAC;AACvF,MAAM,MAAM,kB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C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAC1B,2BAA2B,GAAG,oCAAoC,CACnE,EAAE,CAAC;IACJ,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B;AAED,MAAM,WAAW,yCAAyC;IACxD,QAAQ,CAAC,QAAQ,EAAE,SAAS,qCAAqC,EAAE,CAAC;IACpE,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependencyGraph.js","sourceRoot":"","sources":["../../src/types/dependencyGraph.ts"],"names":[],"mappings":"","sourcesContent":["import type { Graph } from '@ankhorage/graph';\nimport type { ProjectInspection } from '@ankhorage/project-detector/types';\n\nexport type DependencyNodeClassification = 'intrinsic' | 'unknown' | 'vendor';\nexport type DependencyReferenceClassification = DependencyNodeClassification | 'focus';\nexport type DependencyNodeKind = 'module' | 'package';\nexport type DependencyDeclarationKind =\n 'dependency' | 'devDependency' | 'optionalDependency' | 'peerDependency';\n\nexport interface DependencyDeclaration {\n readonly kind: DependencyDeclarationKind;\n readonly range: string;\n}\n\nexport interface DependencyImportEvidence {\n readonly sourceFile: string;\n readonly specifier: string;\n readonly classification: DependencyReferenceClassification;\n readonly declarations: readonly DependencyDeclaration[];\n}\n\nexport interface DependencyGraphNodeData {\n readonly kind: DependencyNodeKind;\n readonly classification: DependencyNodeClassification;\n readonly focus: boolean;\n readonly label: string;\n readonly projectId?: string;\n readonly packageName?: string;\n readonly path?: string;\n readonly parentPath?: string;\n}\n\nexport interface DependencyGraphEdgeData {\n readonly kind: 'import';\n readonly analyzerId: string;\n readonly weight: number;\n readonly evidence: readonly DependencyImportEvidence[];\n}\n\nexport type DependencyGraph = Graph<DependencyGraphNodeData, DependencyGraphEdgeData>;\n\nexport interface DependencyGraphProjectInput {\n readonly id: string;\n readonly rootPath: string;\n}\n\nexport interface DependencyGraphInspectionProjectInput {\n readonly id: string;\n readonly inspection: ProjectInspection;\n}\n\nexport interface DependencyGraphPackage {\n readonly id: string;\n readonly nodeId: string;\n readonly projectId: string;\n readonly relativeRoot: string;\n readonly name?: string;\n}\n\nexport interface CreateDependencyGraphInput {\n readonly projects: readonly DependencyGraphProjectInput[];\n readonly signal?: AbortSignal;\n}\n\nexport interface CreateDependencyGraphFromInspectionsInput {\n readonly projects: readonly DependencyGraphInspectionProjectInput[];\n readonly signal?: AbortSignal;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"dependencyGraph.js","sourceRoot":"","sources":["../../src/types/dependencyGraph.ts"],"names":[],"mappings":"","sourcesContent":["import type { Graph } from '@ankhorage/graph';\nimport type { ProjectInspection } from '@ankhorage/project-detector/types';\n\nexport type DependencyNodeClassification = 'intrinsic' | 'unknown' | 'vendor';\nexport type DependencyReferenceClassification = DependencyNodeClassification | 'focus';\nexport type DependencyNodeKind = 'module' | 'package';\nexport type DependencyDeclarationKind =\n 'dependency' | 'devDependency' | 'optionalDependency' | 'peerDependency';\n\nexport interface DependencyDeclaration {\n readonly kind: DependencyDeclarationKind;\n readonly range: string;\n}\n\nexport interface DependencyImportEvidence {\n readonly sourceFile: string;\n readonly specifier: string;\n readonly classification: DependencyReferenceClassification;\n readonly declarations: readonly DependencyDeclaration[];\n}\n\nexport interface DependencyGraphNodeData {\n readonly kind: DependencyNodeKind;\n readonly classification: DependencyNodeClassification;\n readonly focus: boolean;\n readonly label: string;\n readonly projectId?: string;\n readonly packageName?: string;\n readonly path?: string;\n readonly parentPath?: string;\n}\n\nexport interface DependencyGraphEdgeData {\n readonly kind: 'import';\n readonly analyzerId: string;\n readonly weight: number;\n readonly evidence: readonly DependencyImportEvidence[];\n}\n\nexport type DependencyGraph = Graph<DependencyGraphNodeData, DependencyGraphEdgeData>;\n\nexport interface DependencyGraphProjectInput {\n readonly id: string;\n readonly rootPath: string;\n}\n\nexport interface DependencyGraphInspectedProjectInput {\n readonly id: string;\n readonly inspection: ProjectInspection;\n}\n\nexport interface DependencyGraphInspectionProjectInput {\n readonly id: string;\n readonly inspection: ProjectInspection;\n}\n\nexport interface DependencyGraphPackage {\n readonly id: string;\n readonly nodeId: string;\n readonly projectId: string;\n readonly relativeRoot: string;\n readonly name?: string;\n}\n\nexport interface CreateDependencyGraphInput {\n readonly projects: readonly (\n DependencyGraphProjectInput | DependencyGraphInspectedProjectInput\n )[];\n readonly signal?: AbortSignal;\n}\n\nexport interface CreateDependencyGraphFromInspectionsInput {\n readonly projects: readonly DependencyGraphInspectionProjectInput[];\n readonly signal?: AbortSignal;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { DependencyGraphProjectInput } from './dependencyGraph.js';
|
|
1
|
+
import type { DependencyGraphInspectedProjectInput, DependencyGraphProjectInput } from './dependencyGraph.js';
|
|
2
2
|
export interface DependencyGraphApiInput {
|
|
3
|
-
readonly projects: readonly DependencyGraphProjectInput[];
|
|
3
|
+
readonly projects: readonly (DependencyGraphProjectInput | DependencyGraphInspectedProjectInput)[];
|
|
4
4
|
}
|
|
5
5
|
//# sourceMappingURL=dependencyGraphApi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependencyGraphApi.d.ts","sourceRoot":"","sources":["../../src/types/dependencyGraphApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"dependencyGraphApi.d.ts","sourceRoot":"","sources":["../../src/types/dependencyGraphApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oCAAoC,EACpC,2BAA2B,EAC5B,MAAM,sBAAsB,CAAC;AAE9B,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAC1B,2BAA2B,GAAG,oCAAoC,CACnE,EAAE,CAAC;CACL"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependencyGraphApi.js","sourceRoot":"","sources":["../../src/types/dependencyGraphApi.ts"],"names":[],"mappings":"","sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"dependencyGraphApi.js","sourceRoot":"","sources":["../../src/types/dependencyGraphApi.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n DependencyGraphInspectedProjectInput,\n DependencyGraphProjectInput,\n} from './dependencyGraph.js';\n\nexport interface DependencyGraphApiInput {\n readonly projects: readonly (\n DependencyGraphProjectInput | DependencyGraphInspectedProjectInput\n )[];\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ankhorage/dependency-graph",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Project-aware dependency analysis that produces canonical Ankhorage graphs.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@ankhorage/api": "^0.2.0",
|
|
65
65
|
"@ankhorage/graph": "^0.3.0",
|
|
66
|
-
"@ankhorage/project-detector": "^0.3.
|
|
66
|
+
"@ankhorage/project-detector": "^0.3.3",
|
|
67
67
|
"@ankhorage/utility": "^0.8.0",
|
|
68
68
|
"java-parser": "^3.0.1",
|
|
69
69
|
"typescript": "~6.0.3"
|