Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: revert DepsQueue to re-sort on pop() #7499

Merged
merged 1 commit into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 8 additions & 30 deletions workspaces/arborist/lib/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,48 +53,26 @@ const _addNodeToTrashList = Symbol.for('addNodeToTrashList')
// they'll affect things deeper in, then alphabetical for consistency between
// installs
class DepsQueue {
// [{ sorted, items }] indexed by depth
#deps = []
#sorted = true
#minDepth = 0
#length = 0

get length () {
return this.#length
return this.#deps.length
}

push (item) {
if (!this.#deps[item.depth]) {
this.#length++
this.#deps[item.depth] = { sorted: true, items: [item] }
// no minDepth check needed, this branch is only reached when we are in
// the middle of a shallower depth and creating a new one
return
}
if (!this.#deps[item.depth].items.includes(item)) {
this.#length++
this.#deps[item.depth].sorted = false
this.#deps[item.depth].items.push(item)
if (item.depth < this.#minDepth) {
this.#minDepth = item.depth
}
if (!this.#deps.includes(item)) {
this.#sorted = false
this.#deps.push(item)
}
}

pop () {
let depth
while (!depth?.items.length) {
depth = this.#deps[this.#minDepth]
if (!depth?.items.length) {
this.#minDepth++
}
}
if (!depth.sorted) {
depth.items.sort((a, b) => localeCompare(a.path, b.path))
depth.sorted = true
if (!this.#sorted) {
this.#deps.sort((a, b) => (a.depth - b.depth) || localeCompare(a.path, b.path))
this.#sorted = true
}
this.#length--
return depth.items.shift()
return this.#deps.shift()
}
}

Expand Down
Loading