Skip to content

Commit e290352

Browse files
authored
fix: revert DepsQueue to re-sort on pop() (#7499)
1 parent c3d2819 commit e290352

File tree

1 file changed

+8
-30
lines changed

1 file changed

+8
-30
lines changed

workspaces/arborist/lib/arborist/build-ideal-tree.js

+8-30
Original file line numberDiff line numberDiff line change
@@ -53,48 +53,26 @@ const _addNodeToTrashList = Symbol.for('addNodeToTrashList')
5353
// they'll affect things deeper in, then alphabetical for consistency between
5454
// installs
5555
class DepsQueue {
56-
// [{ sorted, items }] indexed by depth
5756
#deps = []
5857
#sorted = true
59-
#minDepth = 0
60-
#length = 0
6158

6259
get length () {
63-
return this.#length
60+
return this.#deps.length
6461
}
6562

6663
push (item) {
67-
if (!this.#deps[item.depth]) {
68-
this.#length++
69-
this.#deps[item.depth] = { sorted: true, items: [item] }
70-
// no minDepth check needed, this branch is only reached when we are in
71-
// the middle of a shallower depth and creating a new one
72-
return
73-
}
74-
if (!this.#deps[item.depth].items.includes(item)) {
75-
this.#length++
76-
this.#deps[item.depth].sorted = false
77-
this.#deps[item.depth].items.push(item)
78-
if (item.depth < this.#minDepth) {
79-
this.#minDepth = item.depth
80-
}
64+
if (!this.#deps.includes(item)) {
65+
this.#sorted = false
66+
this.#deps.push(item)
8167
}
8268
}
8369

8470
pop () {
85-
let depth
86-
while (!depth?.items.length) {
87-
depth = this.#deps[this.#minDepth]
88-
if (!depth?.items.length) {
89-
this.#minDepth++
90-
}
91-
}
92-
if (!depth.sorted) {
93-
depth.items.sort((a, b) => localeCompare(a.path, b.path))
94-
depth.sorted = true
71+
if (!this.#sorted) {
72+
this.#deps.sort((a, b) => (a.depth - b.depth) || localeCompare(a.path, b.path))
73+
this.#sorted = true
9574
}
96-
this.#length--
97-
return depth.items.shift()
75+
return this.#deps.shift()
9876
}
9977
}
10078

0 commit comments

Comments
 (0)