Skip to content

Commit

Permalink
Revert "Revert "fix: graph-sequencer""
Browse files Browse the repository at this point in the history
This reverts commit 6dc1284.
  • Loading branch information
zkochan committed Feb 8, 2024
1 parent aa2704b commit ec979f3
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/six-ravens-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pnpm/deps.graph-sequencer": patch
---

Don't fail if there's a node with no outgoing edges specified.
4 changes: 3 additions & 1 deletion deps/graph-sequencer/src/index.ts
Original file line number Diff line number Diff line change
@@ -100,7 +100,9 @@ export function graphSequencer<T> (graph: Graph<T>, includedNodes: T[] = [...gra
const cycleVisited = new Set<T>()
while (queue.length) {
const [id, cycle] = queue.shift()!
for (const to of graph.get(id)!) {
const edges = graph.get(id)
if (!edges) continue
for (const to of edges) {
if (to === startNode) {
return cycle
}
15 changes: 15 additions & 0 deletions deps/graph-sequencer/test/index.ts
Original file line number Diff line number Diff line change
@@ -222,6 +222,21 @@ test('graph with multiple cycles. case 1', () => {
)
})

test('graph with multiple cycles. case 1. Node with no outgoing edge is not specified', () => {
expect(graphSequencer(new Map([
['a', ['c']],
['b', ['a', 'd']],
['c', ['b']],
['d', ['c', 'e']],
]))).toStrictEqual(
{
safe: false,
chunks: [['a', 'c', 'b'], ['d']],
cycles: [['a', 'c', 'b']],
}
)
})

test('graph with multiple cycles. case 2', () => {
expect(graphSequencer(new Map([
['a', ['b']],

0 comments on commit ec979f3

Please sign in to comment.