Skip to content

Commit 9bffa13

Browse files
authored
fix(query): properly return :missing nodes (#7320)
Fixes #7316
1 parent 1da5cf0 commit 9bffa13

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed

lib/commands/query.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,12 @@ class Query extends BaseCommand {
113113
// builds a normalized inventory
114114
buildResponse (items) {
115115
for (const node of items) {
116-
if (!this.#seen.has(node.target.location)) {
116+
if (!node.target.location || !this.#seen.has(node.target.location)) {
117117
const item = new QuerySelectorItem(node)
118118
this.#response.push(item)
119-
this.#seen.add(item.location)
119+
if (node.target.location) {
120+
this.#seen.add(item.location)
121+
}
120122
}
121123
}
122124
}

tap-snapshots/test/lib/commands/query.js.test.cjs

+25
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,31 @@ exports[`test/lib/commands/query.js TAP linked node > should return linked node
9999
]
100100
`
101101

102+
exports[`test/lib/commands/query.js TAP missing > should return missing node 1`] = `
103+
[
104+
{
105+
"name": "b",
106+
"version": "^1.0.0",
107+
"_id": "b@^1.0.0",
108+
"pkgid": "b@^1.0.0",
109+
"path": null,
110+
"realpath": null,
111+
"resolved": null,
112+
"from": [
113+
""
114+
],
115+
"to": [],
116+
"dev": true,
117+
"inBundle": false,
118+
"deduped": false,
119+
"overridden": false,
120+
"queryContext": {
121+
"missing": true
122+
}
123+
}
124+
]
125+
`
126+
102127
exports[`test/lib/commands/query.js TAP package-lock-only with package lock > should return valid response with only lock info 1`] = `
103128
[
104129
{

test/lib/commands/query.js

+22
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,25 @@ t.test('expect entries', t => {
320320
})
321321
t.end()
322322
})
323+
324+
t.test('missing', async t => {
325+
const { npm, joinedOutput } = await loadMockNpm(t, {
326+
prefixDir: {
327+
node_modules: {
328+
a: {
329+
name: 'a',
330+
version: '1.0.0',
331+
},
332+
},
333+
'package.json': JSON.stringify({
334+
name: 'project',
335+
dependencies: {
336+
a: '^1.0.0',
337+
b: '^1.0.0',
338+
},
339+
}),
340+
},
341+
})
342+
await npm.exec('query', [':missing'])
343+
t.matchSnapshot(joinedOutput(), 'should return missing node')
344+
})

workspaces/arborist/lib/query-selector-all.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,12 @@ class Results {
257257
for (const edge of node.edgesOut.values()) {
258258
if (edge.missing) {
259259
const pkg = { name: edge.name, version: edge.spec }
260-
res.push(new this.#targetNode.constructor({ pkg }))
260+
const item = new this.#targetNode.constructor({ pkg })
261+
item.queryContext = {
262+
missing: true,
263+
}
264+
item.edgesIn = new Set([edge])
265+
res.push(item)
261266
}
262267
}
263268
return res

0 commit comments

Comments
 (0)