MCPcopy
hub / github.com/npmx-dev/npmx.dev / sortByDependencies

Method sortByDependencies

cli/src/mock-state.ts:496–517  ·  view source on GitHub ↗

Topological sort by dependsOn.

(operations: PendingOperation[])

Source from the content-addressed store, hash-verified

494
495 /** Topological sort by dependsOn. */
496 private sortByDependencies(operations: PendingOperation[]): PendingOperation[] {
497 const result: PendingOperation[] = []
498 const visited = new Set<string>()
499
500 const visit = (op: PendingOperation) => {
501 if (visited.has(op.id)) return
502 visited.add(op.id)
503
504 if (op.dependsOn) {
505 const dep = operations.find(d => d.id === op.dependsOn)
506 if (dep) visit(dep)
507 }
508
509 result.push(op)
510 }
511
512 for (const op of operations) {
513 visit(op)
514 }
515
516 return result
517 }
518
519 reset(): void {
520 this.state.connected = false

Callers 1

executeOperationsMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected