@ankhorage/dependency-graph 1.5.1 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ankhorage/dependency-graph
2
2
 
3
+ ## 1.5.2
4
+
5
+ ### Patch Changes
6
+
7
+ - e8398e3: Exclude incidental package-cache trees from project analysis snapshots.
8
+
3
9
  ## 1.5.1
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  # @ankhorage/dependency-graph
5
5
 
6
- ![license: MIT](././paradox/badges/license.svg) ![npm: v1.3.0](././paradox/badges/npm.svg) ![runtime: bun](././paradox/badges/runtime.svg) ![typescript: strict](././paradox/badges/typescript.svg) ![eslint: checked](././paradox/badges/eslint.svg) ![prettier: checked](././paradox/badges/prettier.svg) ![build: checked](././paradox/badges/build.svg) ![tests: checked](././paradox/badges/tests.svg) ![docs: paradox](././paradox/badges/docs.svg)
6
+ ![license: MIT](././paradox/badges/license.svg) ![npm: v1.5.2](././paradox/badges/npm.svg) ![runtime: bun](././paradox/badges/runtime.svg) ![typescript: strict](././paradox/badges/typescript.svg) ![eslint: checked](././paradox/badges/eslint.svg) ![prettier: checked](././paradox/badges/prettier.svg) ![build: checked](././paradox/badges/build.svg) ![tests: configured](././paradox/badges/tests.svg) ![docs: paradox](././paradox/badges/docs.svg)
7
7
 
8
8
  Project-aware dependency analysis that produces canonical Ankhorage graphs.
9
9
 
@@ -16,16 +16,18 @@ Project-aware dependency analysis that produces canonical Ankhorage graphs.
16
16
  - [Module relationships](././paradox/diagrams/module-relationships.mmd)
17
17
  - [Export graph](././paradox/diagrams/export-graph.mmd)
18
18
  - [createProjectAnalysisSnapshotAsync sequence](././paradox/diagrams/sequences/create-project-analysis-snapshot-async.mmd)
19
+ - [createSourceFeatureProjectionIndex sequence](././paradox/diagrams/sequences/create-source-feature-projection-index.mmd)
19
20
  - [createSourceGraph sequence](././paradox/diagrams/sequences/create-source-graph.mmd)
20
21
  - [createSourceGraphIndex sequence](././paradox/diagrams/sequences/create-source-graph-index.mmd)
21
22
  - [createSourceRollupIndex sequence](././paradox/diagrams/sequences/create-source-rollup-index.mmd)
22
- - [deserializeProjectAnalysisSnapshot sequence](././paradox/diagrams/sequences/deserialize-project-analysis-snapshot.mmd)
23
23
  - [deserializeSourceGraph sequence](././paradox/diagrams/sequences/deserialize-source-graph.mmd)
24
24
  - [findRolledUpDependency sequence](././paradox/diagrams/sequences/find-rolled-up-dependency.mmd)
25
25
  - [findSourceRelationsBetween sequence](././paradox/diagrams/sequences/find-source-relations-between.mmd)
26
26
  - [incomingSourceRelations sequence](././paradox/diagrams/sequences/incoming-source-relations.mmd)
27
+ - [listSourceFeatureMembers sequence](././paradox/diagrams/sequences/list-source-feature-members.mmd)
28
+ - [listSourceFeatures sequence](././paradox/diagrams/sequences/list-source-features.mmd)
27
29
  - [outgoingSourceRelations sequence](././paradox/diagrams/sequences/outgoing-source-relations.mmd)
30
+ - [projectSourceFeatures sequence](././paradox/diagrams/sequences/project-source-features.mmd)
28
31
  - [rollupSourceRelations sequence](././paradox/diagrams/sequences/rollup-source-relations.mmd)
29
- - [serializeProjectAnalysisSnapshot sequence](././paradox/diagrams/sequences/serialize-project-analysis-snapshot.mmd)
30
32
  - [serializeSourceGraph sequence](././paradox/diagrams/sequences/serialize-source-graph.mmd)
31
33
  - [summarizeSourceNode sequence](././paradox/diagrams/sequences/summarize-source-node.mmd)
@@ -1 +1 @@
1
- {"version":3,"file":"createProjectAnalysisSnapshotAsync.d.ts","sourceRoot":"","sources":["../../../../src/features/source-graph/composition/createProjectAnalysisSnapshotAsync.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,kCAAkC,EAClC,uBAAuB,EACxB,MAAM,2CAA2C,CAAC;AASnD,kGAAkG;AAClG,wBAAsB,kCAAkC,CACtD,KAAK,EAAE,kCAAkC,GAAG;IAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,GAC5E,OAAO,CAAC,uBAAuB,CAAC,CAoClC"}
1
+ {"version":3,"file":"createProjectAnalysisSnapshotAsync.d.ts","sourceRoot":"","sources":["../../../../src/features/source-graph/composition/createProjectAnalysisSnapshotAsync.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,kCAAkC,EAClC,uBAAuB,EACxB,MAAM,2CAA2C,CAAC;AASnD,kGAAkG;AAClG,wBAAsB,kCAAkC,CACtD,KAAK,EAAE,kCAAkC,GAAG;IAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,GAC5E,OAAO,CAAC,uBAAuB,CAAC,CAuClC"}
@@ -16,21 +16,22 @@ export async function createProjectAnalysisSnapshotAsync(input) {
16
16
  });
17
17
  if (!inspection.complete)
18
18
  throw new Error(`Project analysis inspection is incomplete for ${input.id}.`);
19
- const analyzedFiles = await readProjectFilesAsync(input.id, inspection, input.signal);
19
+ const scopedInspection = createScopedInspection(inspection);
20
+ const analyzedFiles = await readProjectFilesAsync(input.id, scopedInspection, input.signal);
20
21
  const analyzerIds = new Set([
21
22
  'project-detector',
22
- ...inspection.detection.languages.map(({ id }) => id),
23
+ ...scopedInspection.packages.flatMap(({ detection }) => detection.languages.map(({ id }) => id)),
23
24
  ...analyzedFiles.map(({ analyzerId }) => analyzerId),
24
25
  ]);
25
26
  return {
26
27
  version: 1,
27
28
  projectId: input.id,
28
- directories: [...inspection.directories].sort(compareText),
29
- files: [...inspection.files].sort(compareText),
30
- packages: inspection.packages
29
+ directories: [...scopedInspection.directories].sort(compareText),
30
+ files: [...scopedInspection.files].sort(compareText),
31
+ packages: scopedInspection.packages
31
32
  .map(({ rootPath, name }) => ({ rootPath, ...(name === undefined ? {} : { name }) }))
32
33
  .sort((left, right) => compareText(left.rootPath, right.rootPath)),
33
- workspaces: inspection.workspaces
34
+ workspaces: scopedInspection.workspaces
34
35
  .map(({ rootPath, packagePaths }) => ({
35
36
  rootPath,
36
37
  packagePaths: [...packagePaths].sort(compareText),
@@ -44,6 +45,50 @@ export async function createProjectAnalysisSnapshotAsync(input) {
44
45
  .sort((left, right) => compareText(left.path, right.path)),
45
46
  };
46
47
  }
48
+ /*** Retain the root package and its declared workspace members, excluding discovered caches. */
49
+ function createScopedInspection(inspection) {
50
+ const packageRoots = selectedPackageRoots(inspection);
51
+ const packages = inspection.packages.filter(({ rootPath }) => packageRoots.has(rootPath));
52
+ const workspaces = inspection.workspaces.filter(({ rootPath }) => packageRoots.has(rootPath));
53
+ const isOwnedBySelectedPackage = (candidate) => {
54
+ const owner = owningPackageRoot(candidate, inspection.packages);
55
+ return owner === undefined || packageRoots.has(owner);
56
+ };
57
+ return {
58
+ ...inspection,
59
+ directories: inspection.directories.filter(isOwnedBySelectedPackage),
60
+ files: inspection.files.filter(isOwnedBySelectedPackage),
61
+ packages,
62
+ workspaces,
63
+ };
64
+ }
65
+ /*** Select the root project package and recursively declared workspace package roots. */
66
+ function selectedPackageRoots(inspection) {
67
+ if (!inspection.packages.some(({ rootPath }) => rootPath === '.'))
68
+ return new Set(inspection.packages.map(({ rootPath }) => rootPath));
69
+ const roots = new Set(['.']);
70
+ let changed = true;
71
+ while (changed) {
72
+ changed = false;
73
+ for (const workspace of inspection.workspaces) {
74
+ if (!roots.has(workspace.rootPath))
75
+ continue;
76
+ for (const rootPath of workspace.packagePaths) {
77
+ if (roots.has(rootPath))
78
+ continue;
79
+ roots.add(rootPath);
80
+ changed = true;
81
+ }
82
+ }
83
+ }
84
+ return roots;
85
+ }
86
+ /*** Resolve the nearest inspected package boundary that owns a project-relative path. */
87
+ function owningPackageRoot(candidate, packages) {
88
+ return packages
89
+ .filter(({ rootPath }) => rootPath === '.' || candidate === rootPath || candidate.startsWith(`${rootPath}/`))
90
+ .sort((left, right) => right.rootPath.length - left.rootPath.length)[0]?.rootPath;
91
+ }
47
92
  /*** Read project-relative source files once and retain only portable analyzer facts. */
48
93
  async function readProjectFilesAsync(projectId, inspection, signal) {
49
94
  const declarations = await readPackageDeclarationsAsync(inspection);
@@ -1 +1 @@
1
- {"version":3,"file":"createProjectAnalysisSnapshotAsync.js","sourceRoot":"","sources":["../../../../src/features/source-graph/composition/createProjectAnalysisSnapshotAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAQvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4EAA4E,CAAC;AACpH,OAAO,EAAE,8BAA8B,EAAE,MAAM,0FAA0F,CAAC;AAC1I,OAAO,EAAE,4BAA4B,EAAE,MAAM,wFAAwF,CAAC;AACtI,OAAO,EAAE,+BAA+B,EAAE,MAAM,qEAAqE,CAAC;AACtH,OAAO,EAAE,yBAAyB,EAAE,MAAM,mDAAmD,CAAC;AAC9F,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AAErF,kGAAkG;AAClG,MAAM,CAAC,KAAK,UAAU,kCAAkC,CACtD,KAA6E;IAE7E,MAAM,UAAU,GACd,YAAY,IAAI,KAAK;QACnB,CAAC,CAAC,KAAK,CAAC,UAAU;QAClB,CAAC,CAAC,MAAM,mBAAmB,CAAC,KAAK,CAAC,QAAQ,EAAE;YACxC,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;SAChE,CAAC,CAAC;IACT,IAAI,CAAC,UAAU,CAAC,QAAQ;QACtB,MAAM,IAAI,KAAK,CAAC,iDAAiD,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC;IAChF,MAAM,aAAa,GAAG,MAAM,qBAAqB,CAAC,KAAK,CAAC,EAAE,EAAE,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC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AAI,UAAU,KAAK,QAAQ;QAAE,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;IACxD,IAAI,UAAU,KAAK,QAAQ;QAAE,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;IAC3D,OAAO,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAED,gFAAgF;AAChF,SAAS,WAAW,CAAC,IAAY,EAAE,KAAa;IAC9C,IAAI,IAAI,GAAG,KAAK;QAAE,OAAO,CAAC,CAAC,CAAC;IAC5B,OAAO,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["import { readFile } from 'node:fs/promises';\nimport path from 'node:path';\n\nimport { inspectProjectAsync } from '@ankhorage/project-detector/node';\nimport type { ProjectInspection } from '@ankhorage/project-detector/types';\n\nimport type {\n CreateProjectAnalysisSnapshotInput,\n ProjectAnalysisSnapshot,\n} from '../../../types/projectAnalysisSnapshot.js';\nimport type { SourceAnalyzedFile } from '../../../types/sourceGraph.js';\nimport { extractJavaSourceFacts } from '../../dependency-analysis/adapters/outbound/java/extractJavaSourceFacts.js';\nimport { createTypeScriptImportResolver } from '../../dependency-analysis/adapters/outbound/typescript/createTypeScriptImportResolver.js';\nimport { extractTypeScriptSourceFacts } from '../../dependency-analysis/adapters/outbound/typescript/extractTypeScriptSourceFacts.js';\nimport { readDependencyDeclarationsAsync } from '../../dependency-analysis/domain/readDependencyDeclarationsAsync.js';\nimport { extractOtherLanguageFacts } from '../adapters/outbound/extractOtherLanguageFacts.js';\nimport { sourceAnalyzerCapabilities } from '../domain/sourceAnalyzerCapabilities.js';\n\n/*** Analyze one bounded project into facts that remain valid after its source root is removed. */\nexport async function createProjectAnalysisSnapshotAsync(\n input: CreateProjectAnalysisSnapshotInput & { readonly signal?: AbortSignal },\n): Promise<ProjectAnalysisSnapshot> {\n const inspection =\n 'inspection' in input\n ? input.inspection\n : await inspectProjectAsync(input.rootPath, {\n ...(input.signal === undefined ? {} : { signal: input.signal }),\n });\n if (!inspection.complete)\n throw new Error(`Project analysis inspection is incomplete for ${input.id}.`);\n const analyzedFiles = await readProjectFilesAsync(input.id, inspection, input.signal);\n const analyzerIds = new Set([\n 'project-detector',\n ...inspection.detection.languages.map(({ id }) => id),\n ...analyzedFiles.map(({ analyzerId }) => analyzerId),\n ]);\n return {\n version: 1,\n projectId: input.id,\n directories: [...inspection.directories].sort(compareText),\n files: [...inspection.files].sort(compareText),\n packages: inspection.packages\n .map(({ rootPath, name }) => ({ rootPath, ...(name === undefined ? {} : { name }) }))\n .sort((left, right) => compareText(left.rootPath, right.rootPath)),\n workspaces: inspection.workspaces\n .map(({ rootPath, packagePaths }) => ({\n rootPath,\n packagePaths: [...packagePaths].sort(compareText),\n }))\n .sort((left, right) => compareText(left.rootPath, right.rootPath)),\n analyzers: [...analyzerIds]\n .sort(compareText)\n .map((id) => ({ id, capabilities: sourceAnalyzerCapabilities(id) })),\n analyzedFiles: analyzedFiles\n .map(({ projectId: _, ...file }) => file)\n .sort((left, right) => compareText(left.path, right.path)),\n };\n}\n\n/*** Read project-relative source files once and retain only portable analyzer facts. */\nasync function readProjectFilesAsync(\n projectId: string,\n inspection: ProjectInspection,\n signal: AbortSignal | undefined,\n): Promise<readonly SourceAnalyzedFile[]> {\n const declarations = await readPackageDeclarationsAsync(inspection);\n const resolveTypeScriptImports = createTypeScriptImportResolver(inspection.rootPath);\n return Promise.all(\n inspection.files.flatMap((file) => {\n const analyzerId = analyzerForPath(file);\n if (analyzerId === undefined) return [];\n const [owner] = inspection.packages\n .filter(({ rootPath }) => rootPath === '.' || file.startsWith(`${rootPath}/`))\n .sort((left, right) => right.rootPath.length - left.rootPath.length);\n const root = owner?.rootPath ?? '.';\n const sourceRoots =\n owner?.detection.languages.find(({ id }) => id === analyzerId)?.sourceRoots ??\n defaultSourceRoots(analyzerId);\n const relative = root === '.' ? file : file.slice(root.length + 1);\n if (\n !sourceRoots.some(\n (sourceRoot) => sourceRoot === '.' || relative.startsWith(`${sourceRoot}/`),\n )\n )\n return [];\n return [\n readAnalyzedFileAsync({\n projectId,\n file,\n analyzerId,\n projectRoot: inspection.rootPath,\n packageRoot: path.resolve(inspection.rootPath, root),\n sourceRoots,\n declaredDependencies: declarations.get(root),\n resolveTypeScriptImports,\n signal,\n }),\n ];\n }),\n );\n}\n\n/*** Preserve manifest declarations as project-relative import evidence. */\nasync function readPackageDeclarationsAsync(\n inspection: ProjectInspection,\n): Promise<ReadonlyMap<string, SourceAnalyzedFile['declaredDependencies']>> {\n const entries = await Promise.all(\n inspection.packages.map(\n async (item) =>\n [\n item.rootPath,\n item.manifestPath.endsWith('.json')\n ? await readDependencyDeclarationsAsync(\n path.join(inspection.rootPath, item.manifestPath),\n )\n : {},\n ] as const,\n ),\n );\n return new Map(entries);\n}\n\ninterface ReadSourceFileInput {\n readonly projectId: string;\n readonly projectRoot: string;\n readonly packageRoot: string;\n readonly sourceRoots: readonly string[];\n readonly file: string;\n readonly analyzerId: Exclude<ReturnType<typeof analyzerForPath>, undefined>;\n readonly declaredDependencies: SourceAnalyzedFile['declaredDependencies'];\n readonly resolveTypeScriptImports: ReturnType<typeof createTypeScriptImportResolver>;\n readonly signal: AbortSignal | undefined;\n}\n\n/*** Read one source file at the materialization boundary and discard its absolute path afterward. */\nasync function readAnalyzedFileAsync(input: ReadSourceFileInput): Promise<SourceAnalyzedFile> {\n input.signal?.throwIfAborted();\n const absolute = path.resolve(input.projectRoot, ...input.file.split('/'));\n const content = await readFile(absolute, 'utf8');\n input.signal?.throwIfAborted();\n return {\n projectId: input.projectId,\n path: input.file,\n analyzerId: input.analyzerId,\n ...(input.declaredDependencies === undefined\n ? {}\n : { declaredDependencies: input.declaredDependencies }),\n facts:\n input.analyzerId === 'java'\n ? extractJavaSourceFacts(content)\n : input.analyzerId === 'typescript'\n ? input.resolveTypeScriptImports(\n absolute,\n input.packageRoot,\n extractTypeScriptSourceFacts(input.file, content),\n )\n : extractOtherLanguageFacts(\n input.analyzerId,\n content,\n absolute,\n input.packageRoot,\n input.sourceRoots,\n ),\n };\n}\n\n/*** Select the implemented language analyzer from a project-relative source filename. */\nfunction analyzerForPath(\n file: string,\n): 'java' | 'typescript' | 'cpp' | 'delphi' | 'kotlin' | 'python' | undefined {\n if (file.endsWith('.java')) return 'java';\n if (['.ts', '.tsx', '.mts', '.cts'].some((extension) => file.endsWith(extension)))\n return 'typescript';\n if (file.endsWith('.kt') || file.endsWith('.kts')) return 'kotlin';\n if (file.endsWith('.py') || file.endsWith('.pyi')) return 'python';\n if (['.cpp', '.cc', '.cxx', '.h', '.hpp', '.hxx'].some((extension) => file.endsWith(extension)))\n return 'cpp';\n if (['.pas', '.pp', '.dpr'].some((extension) => file.toLowerCase().endsWith(extension)))\n return 'delphi';\n return undefined;\n}\n\n/*** Keep established default source roots for analyzers without explicit project metadata. */\nfunction defaultSourceRoots(analyzerId: string): readonly string[] {\n if (analyzerId === 'java') return ['src/main/java', '.'];\n if (analyzerId === 'kotlin') return ['src/main/kotlin', 'src', '.'];\n if (analyzerId === 'python') return ['src', 'app', '.'];\n if (analyzerId === 'delphi') return ['src', 'Source', '.'];\n return ['.'];\n}\n\n/*** Compare portable identities deterministically without host locale rules. */\nfunction compareText(left: string, right: string): number {\n if (left < right) return -1;\n return left > right ? 1 : 0;\n}\n"]}
1
+ {"version":3,"file":"createProjectAnalysisSnapshotAsync.js","sourceRoot":"","sources":["../../../../src/features/source-graph/composition/createProjectAnalysisSnapshotAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAQvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4EAA4E,CAAC;AACpH,OAAO,EAAE,8BAA8B,EAAE,MAAM,0FAA0F,CAAC;AAC1I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I,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QAC7F,OAAO,KAAK,CAAC;IACf,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QACrF,OAAO,QAAQ,CAAC;IAClB,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,8FAA8F;AAC9F,SAAS,kBAAkB,CAAC,UAAkB;IAC5C,IAAI,UAAU,KAAK,MAAM;QAAE,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC;IACzD,IAAI,UAAU,KAAK,QAAQ;QAAE,OAAO,CAAC,iBAAiB,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;IACpE,IAAI,UAAU,KAAK,QAAQ;QAAE,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;IACxD,IAAI,UAAU,KAAK,QAAQ;QAAE,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;IAC3D,OAAO,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAED,gFAAgF;AAChF,SAAS,WAAW,CAAC,IAAY,EAAE,KAAa;IAC9C,IAAI,IAAI,GAAG,KAAK;QAAE,OAAO,CAAC,CAAC,CAAC;IAC5B,OAAO,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["import { readFile } from 'node:fs/promises';\nimport path from 'node:path';\n\nimport { inspectProjectAsync } from '@ankhorage/project-detector/node';\nimport type { InspectedPackage, ProjectInspection } from '@ankhorage/project-detector/types';\n\nimport type {\n CreateProjectAnalysisSnapshotInput,\n ProjectAnalysisSnapshot,\n} from '../../../types/projectAnalysisSnapshot.js';\nimport type { SourceAnalyzedFile } from '../../../types/sourceGraph.js';\nimport { extractJavaSourceFacts } from '../../dependency-analysis/adapters/outbound/java/extractJavaSourceFacts.js';\nimport { createTypeScriptImportResolver } from '../../dependency-analysis/adapters/outbound/typescript/createTypeScriptImportResolver.js';\nimport { extractTypeScriptSourceFacts } from '../../dependency-analysis/adapters/outbound/typescript/extractTypeScriptSourceFacts.js';\nimport { readDependencyDeclarationsAsync } from '../../dependency-analysis/domain/readDependencyDeclarationsAsync.js';\nimport { extractOtherLanguageFacts } from '../adapters/outbound/extractOtherLanguageFacts.js';\nimport { sourceAnalyzerCapabilities } from '../domain/sourceAnalyzerCapabilities.js';\n\n/*** Analyze one bounded project into facts that remain valid after its source root is removed. */\nexport async function createProjectAnalysisSnapshotAsync(\n input: CreateProjectAnalysisSnapshotInput & { readonly signal?: AbortSignal },\n): Promise<ProjectAnalysisSnapshot> {\n const inspection =\n 'inspection' in input\n ? input.inspection\n : await inspectProjectAsync(input.rootPath, {\n ...(input.signal === undefined ? {} : { signal: input.signal }),\n });\n if (!inspection.complete)\n throw new Error(`Project analysis inspection is incomplete for ${input.id}.`);\n const scopedInspection = createScopedInspection(inspection);\n const analyzedFiles = await readProjectFilesAsync(input.id, scopedInspection, input.signal);\n const analyzerIds = new Set([\n 'project-detector',\n ...scopedInspection.packages.flatMap(({ detection }) =>\n detection.languages.map(({ id }) => id),\n ),\n ...analyzedFiles.map(({ analyzerId }) => analyzerId),\n ]);\n return {\n version: 1,\n projectId: input.id,\n directories: [...scopedInspection.directories].sort(compareText),\n files: [...scopedInspection.files].sort(compareText),\n packages: scopedInspection.packages\n .map(({ rootPath, name }) => ({ rootPath, ...(name === undefined ? {} : { name }) }))\n .sort((left, right) => compareText(left.rootPath, right.rootPath)),\n workspaces: scopedInspection.workspaces\n .map(({ rootPath, packagePaths }) => ({\n rootPath,\n packagePaths: [...packagePaths].sort(compareText),\n }))\n .sort((left, right) => compareText(left.rootPath, right.rootPath)),\n analyzers: [...analyzerIds]\n .sort(compareText)\n .map((id) => ({ id, capabilities: sourceAnalyzerCapabilities(id) })),\n analyzedFiles: analyzedFiles\n .map(({ projectId: _, ...file }) => file)\n .sort((left, right) => compareText(left.path, right.path)),\n };\n}\n\n/*** Retain the root package and its declared workspace members, excluding discovered caches. */\nfunction createScopedInspection(inspection: ProjectInspection): ProjectInspection {\n const packageRoots = selectedPackageRoots(inspection);\n const packages = inspection.packages.filter(({ rootPath }) => packageRoots.has(rootPath));\n const workspaces = inspection.workspaces.filter(({ rootPath }) => packageRoots.has(rootPath));\n const isOwnedBySelectedPackage = (candidate: string): boolean => {\n const owner = owningPackageRoot(candidate, inspection.packages);\n return owner === undefined || packageRoots.has(owner);\n };\n return {\n ...inspection,\n directories: inspection.directories.filter(isOwnedBySelectedPackage),\n files: inspection.files.filter(isOwnedBySelectedPackage),\n packages,\n workspaces,\n };\n}\n\n/*** Select the root project package and recursively declared workspace package roots. */\nfunction selectedPackageRoots(inspection: ProjectInspection): ReadonlySet<string> {\n if (!inspection.packages.some(({ rootPath }) => rootPath === '.'))\n return new Set(inspection.packages.map(({ rootPath }) => rootPath));\n const roots = new Set<string>(['.']);\n let changed = true;\n while (changed) {\n changed = false;\n for (const workspace of inspection.workspaces) {\n if (!roots.has(workspace.rootPath)) continue;\n for (const rootPath of workspace.packagePaths) {\n if (roots.has(rootPath)) continue;\n roots.add(rootPath);\n changed = true;\n }\n }\n }\n return roots;\n}\n\n/*** Resolve the nearest inspected package boundary that owns a project-relative path. */\nfunction owningPackageRoot(\n candidate: string,\n packages: readonly InspectedPackage[],\n): string | undefined {\n return packages\n .filter(\n ({ rootPath }) =>\n rootPath === '.' || candidate === rootPath || candidate.startsWith(`${rootPath}/`),\n )\n .sort((left, right) => right.rootPath.length - left.rootPath.length)[0]?.rootPath;\n}\n\n/*** Read project-relative source files once and retain only portable analyzer facts. */\nasync function readProjectFilesAsync(\n projectId: string,\n inspection: ProjectInspection,\n signal: AbortSignal | undefined,\n): Promise<readonly SourceAnalyzedFile[]> {\n const declarations = await readPackageDeclarationsAsync(inspection);\n const resolveTypeScriptImports = createTypeScriptImportResolver(inspection.rootPath);\n return Promise.all(\n inspection.files.flatMap((file) => {\n const analyzerId = analyzerForPath(file);\n if (analyzerId === undefined) return [];\n const [owner] = inspection.packages\n .filter(({ rootPath }) => rootPath === '.' || file.startsWith(`${rootPath}/`))\n .sort((left, right) => right.rootPath.length - left.rootPath.length);\n const root = owner?.rootPath ?? '.';\n const sourceRoots =\n owner?.detection.languages.find(({ id }) => id === analyzerId)?.sourceRoots ??\n defaultSourceRoots(analyzerId);\n const relative = root === '.' ? file : file.slice(root.length + 1);\n if (\n !sourceRoots.some(\n (sourceRoot) => sourceRoot === '.' || relative.startsWith(`${sourceRoot}/`),\n )\n )\n return [];\n return [\n readAnalyzedFileAsync({\n projectId,\n file,\n analyzerId,\n projectRoot: inspection.rootPath,\n packageRoot: path.resolve(inspection.rootPath, root),\n sourceRoots,\n declaredDependencies: declarations.get(root),\n resolveTypeScriptImports,\n signal,\n }),\n ];\n }),\n );\n}\n\n/*** Preserve manifest declarations as project-relative import evidence. */\nasync function readPackageDeclarationsAsync(\n inspection: ProjectInspection,\n): Promise<ReadonlyMap<string, SourceAnalyzedFile['declaredDependencies']>> {\n const entries = await Promise.all(\n inspection.packages.map(\n async (item) =>\n [\n item.rootPath,\n item.manifestPath.endsWith('.json')\n ? await readDependencyDeclarationsAsync(\n path.join(inspection.rootPath, item.manifestPath),\n )\n : {},\n ] as const,\n ),\n );\n return new Map(entries);\n}\n\ninterface ReadSourceFileInput {\n readonly projectId: string;\n readonly projectRoot: string;\n readonly packageRoot: string;\n readonly sourceRoots: readonly string[];\n readonly file: string;\n readonly analyzerId: Exclude<ReturnType<typeof analyzerForPath>, undefined>;\n readonly declaredDependencies: SourceAnalyzedFile['declaredDependencies'];\n readonly resolveTypeScriptImports: ReturnType<typeof createTypeScriptImportResolver>;\n readonly signal: AbortSignal | undefined;\n}\n\n/*** Read one source file at the materialization boundary and discard its absolute path afterward. */\nasync function readAnalyzedFileAsync(input: ReadSourceFileInput): Promise<SourceAnalyzedFile> {\n input.signal?.throwIfAborted();\n const absolute = path.resolve(input.projectRoot, ...input.file.split('/'));\n const content = await readFile(absolute, 'utf8');\n input.signal?.throwIfAborted();\n return {\n projectId: input.projectId,\n path: input.file,\n analyzerId: input.analyzerId,\n ...(input.declaredDependencies === undefined\n ? {}\n : { declaredDependencies: input.declaredDependencies }),\n facts:\n input.analyzerId === 'java'\n ? extractJavaSourceFacts(content)\n : input.analyzerId === 'typescript'\n ? input.resolveTypeScriptImports(\n absolute,\n input.packageRoot,\n extractTypeScriptSourceFacts(input.file, content),\n )\n : extractOtherLanguageFacts(\n input.analyzerId,\n content,\n absolute,\n input.packageRoot,\n input.sourceRoots,\n ),\n };\n}\n\n/*** Select the implemented language analyzer from a project-relative source filename. */\nfunction analyzerForPath(\n file: string,\n): 'java' | 'typescript' | 'cpp' | 'delphi' | 'kotlin' | 'python' | undefined {\n if (file.endsWith('.java')) return 'java';\n if (['.ts', '.tsx', '.mts', '.cts'].some((extension) => file.endsWith(extension)))\n return 'typescript';\n if (file.endsWith('.kt') || file.endsWith('.kts')) return 'kotlin';\n if (file.endsWith('.py') || file.endsWith('.pyi')) return 'python';\n if (['.cpp', '.cc', '.cxx', '.h', '.hpp', '.hxx'].some((extension) => file.endsWith(extension)))\n return 'cpp';\n if (['.pas', '.pp', '.dpr'].some((extension) => file.toLowerCase().endsWith(extension)))\n return 'delphi';\n return undefined;\n}\n\n/*** Keep established default source roots for analyzers without explicit project metadata. */\nfunction defaultSourceRoots(analyzerId: string): readonly string[] {\n if (analyzerId === 'java') return ['src/main/java', '.'];\n if (analyzerId === 'kotlin') return ['src/main/kotlin', 'src', '.'];\n if (analyzerId === 'python') return ['src', 'app', '.'];\n if (analyzerId === 'delphi') return ['src', 'Source', '.'];\n return ['.'];\n}\n\n/*** Compare portable identities deterministically without host locale rules. */\nfunction compareText(left: string, right: string): number {\n if (left < right) return -1;\n return left > right ? 1 : 0;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ankhorage/dependency-graph",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "type": "module",
5
5
  "description": "Project-aware dependency analysis that produces canonical Ankhorage graphs.",
6
6
  "license": "MIT",
@@ -69,7 +69,7 @@
69
69
  "typescript": "~6.0.3"
70
70
  },
71
71
  "devDependencies": {
72
- "@ankhorage/devtools": "^1.14.7",
72
+ "@ankhorage/devtools": "^2.10.5",
73
73
  "@ankhorage/paradox": "^0.1.26",
74
74
  "@types/bun": "^1.4.2",
75
75
  "@types/node": "^26.5.1"