(tree, arg)
| 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 | |
| 164 | module.exports = Query |
no test coverage detected