MCPcopy Create free account
hub / github.com/deanrad/rxfx / topologicalSort

Function topologicalSort

scripts/bump-versions.mjs:62–87  ·  view source on GitHub ↗
(pkgMap)

Source from the content-addressed store, hash-verified

60
61// Topological sort (dependencies first)
62function topologicalSort(pkgMap) {
63 const visited = new Set();
64 const result = [];
65
66 function visit(pkgName) {
67 if (visited.has(pkgName)) return;
68 visited.add(pkgName);
69
70 const pkg = pkgMap.get(pkgName);
71 if (!pkg) return;
72
73 // Visit dependencies first
74 for (const depName of pkg.deps) {
75 visit(depName);
76 }
77
78 result.push(pkgName);
79 }
80
81 // Visit all packages
82 for (const pkgName of pkgMap.keys()) {
83 visit(pkgName);
84 }
85
86 return result;
87}
88
89const sorted = topologicalSort(pkgMap);
90

Callers 1

bump-versions.mjsFile · 0.85

Calls 1

visitFunction · 0.85

Tested by

no test coverage detected