MCPcopy Create free account
hub / github.com/dmno-dev/bumpy / DependencyGraph

Class DependencyGraph

packages/bumpy/src/core/dep-graph.ts:3–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1import type { WorkspacePackage, DependentInfo, DepType } from '../types.ts';
2
3export class DependencyGraph {
4 /** Map from package name → packages that depend on it */
5 private dependents = new Map<string, DependentInfo[]>();
6 /** Set of all internal package names */
7 private internalPackages: Set<string>;
8
9 constructor(packages: Map<string, WorkspacePackage>) {
10 this.internalPackages = new Set(packages.keys());
11 this.build(packages);
12 }
13
14 private build(packages: Map<string, WorkspacePackage>) {
15 for (const [name, pkg] of packages) {
16 const depTypes: [DepType, Record<string, string>][] = [
17 ['dependencies', pkg.dependencies],
18 ['devDependencies', pkg.devDependencies],
19 ['peerDependencies', pkg.peerDependencies],
20 ['optionalDependencies', pkg.optionalDependencies],
21 ];
22
23 for (const [depType, deps] of depTypes) {
24 for (const [depName, versionRange] of Object.entries(deps)) {
25 if (!this.internalPackages.has(depName)) continue;
26 if (!this.dependents.has(depName)) {
27 this.dependents.set(depName, []);
28 }
29 this.dependents.get(depName)!.push({
30 name,
31 depType,
32 versionRange,
33 });
34 }
35 }
36 }
37 }
38
39 /** Get all packages that depend on the given package */
40 getDependents(pkgName: string): DependentInfo[] {
41 return this.dependents.get(pkgName) || [];
42 }
43
44 /** Check if a package is an internal workspace package */
45 isInternal(pkgName: string): boolean {
46 return this.internalPackages.has(pkgName);
47 }
48
49 /** Get all internal package names */
50 allPackages(): string[] {
51 return [...this.internalPackages];
52 }
53
54 /** Topological sort — returns packages in dependency order (deps first) */
55 topologicalSort(packages: Map<string, WorkspacePackage>): string[] {
56 const visited = new Set<string>();
57 const result: string[] = [];
58
59 const visit = (name: string) => {
60 if (visited.has(name)) return;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…