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(query): properly return :missing nodes #7320

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions lib/commands/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ class Query extends BaseCommand {
// builds a normalized inventory
buildResponse (items) {
for (const node of items) {
if (!this.#seen.has(node.target.location)) {
if (!node.target.location || !this.#seen.has(node.target.location)) {
const item = new QuerySelectorItem(node)
this.#response.push(item)
this.#seen.add(item.location)
if (node.target.location) {
this.#seen.add(item.location)
}
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions tap-snapshots/test/lib/commands/query.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,31 @@ exports[`test/lib/commands/query.js TAP linked node > should return linked node
]
`

exports[`test/lib/commands/query.js TAP missing > should return missing node 1`] = `
[
{
"name": "b",
"version": "^1.0.0",
"_id": "b@^1.0.0",
"pkgid": "b@^1.0.0",
"path": null,
"realpath": null,
"resolved": null,
"from": [
""
],
"to": [],
"dev": true,
"inBundle": false,
"deduped": false,
"overridden": false,
"queryContext": {
"missing": true
}
}
]
`

exports[`test/lib/commands/query.js TAP package-lock-only with package lock > should return valid response with only lock info 1`] = `
[
{
Expand Down
22 changes: 22 additions & 0 deletions test/lib/commands/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,25 @@ t.test('expect entries', t => {
})
t.end()
})

t.test('missing', async t => {
const { npm, joinedOutput } = await loadMockNpm(t, {
prefixDir: {
node_modules: {
a: {
name: 'a',
version: '1.0.0',
},
},
'package.json': JSON.stringify({
name: 'project',
dependencies: {
a: '^1.0.0',
b: '^1.0.0',
},
}),
},
})
await npm.exec('query', [':missing'])
t.matchSnapshot(joinedOutput(), 'should return missing node')
})
7 changes: 6 additions & 1 deletion workspaces/arborist/lib/query-selector-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,12 @@ class Results {
for (const edge of node.edgesOut.values()) {
if (edge.missing) {
const pkg = { name: edge.name, version: edge.spec }
res.push(new this.#targetNode.constructor({ pkg }))
const item = new this.#targetNode.constructor({ pkg })
item.queryContext = {
missing: true,
}
item.edgesIn = new Set([edge])
res.push(item)
}
}
return res
Expand Down
Loading