MCPcopy Create free account
hub / github.com/npm/cli / #queryTree

Method #queryTree

lib/commands/query.js:139–161  ·  view source on GitHub ↗
(tree, arg)

Source from the content-addressed store, hash-verified

137
138 // builds a normalized inventory
139 async #queryTree (tree, arg) {
140 const items = await tree.querySelectorAll(arg, this.npm.flatOptions)
141 for (const node of items) {
142 // Dedup by the target's physical location so multiple logical links to the same store node collapse to one result.
143 const { location } = node.target
144 if (!location) {
145 this.#response.push(new QuerySelectorItem(node))
146 continue
147 }
148 const seen = this.#seen.get(location)
149 if (seen === undefined) {
150 this.#seen.set(location, { index: this.#response.length, rank: locationRank(node) })
151 this.#response.push(new QuerySelectorItem(node))
152 } else {
153 // Replace the stored representation only with a more logical one for the same physical package.
154 const rank = locationRank(node)
155 if (rank > seen.rank) {
156 this.#response[seen.index] = new QuerySelectorItem(node)
157 seen.rank = rank
158 }
159 }
160 }
161 }
162}
163
164module.exports = Query

Callers 2

execMethod · 0.95
execWorkspacesMethod · 0.95

Calls 5

locationRankFunction · 0.85
querySelectorAllMethod · 0.80
pushMethod · 0.80
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected