Skip to content
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
2 changes: 1 addition & 1 deletion docs/lib/content/using-npm/dependency-selectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ The [`npm query`](/commands/npm-query) command exposes a new dependency selector
- `:missing` when a dependency is not found on disk
- `:semver(<spec>, [selector], [function])` match a valid [`node-semver`](https://github.com/npm/node-semver) version or range to a selector
- `:path(<path>)` [glob](https://www.npmjs.com/package/glob) matching based on dependencies path relative to the project
- `:type(<type>)` [based on currently recognized types](https://github.com/npm/npm-package-arg#result-object)
- `:type(<type>)` [based on currently recognized types](https://github.com/npm/npm-package-arg#result-object). You can also use the aggregate type of `registry` for any registry dependency (e.g. tag, version, range, alias)
- `:outdated(<type>)` when a dependency is outdated
- `:vuln(<selector>)` when a dependency has a known vulnerability

Expand Down
10 changes: 9 additions & 1 deletion workspaces/arborist/lib/query-selector-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,19 @@ class Results {
if (!this.currentAstNode.typeValue) {
return this.initialItems
}
// TODO this differs subtly with `:type()` because it now iterates on edgesIn, which means extraneous deps won't show up
// note how "@npmcli/abbrev@2.0.0-beta.45" is in the `:type()` results in the test but not in any of the other results.
return this.initialItems
.flatMap(node => {
const found = []
const { typeValue } = this.currentAstNode
for (const edge of node.edgesIn) {
if (npa(`${edge.name}@${edge.spec}`).type === this.currentAstNode.typeValue) {
const parsedArg = npa(`${edge.name}@${edge.spec}`)
if (typeValue === 'registry') {
if (parsedArg.registry) {
found.push(edge.to)
}
} else if (parsedArg.type === typeValue) {
found.push(edge.to)
}
}
Expand Down
17 changes: 17 additions & 0 deletions workspaces/arborist/test/query-selector-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ t.test('query-selector-all', async t => {
'a@1.0.0',
'b@1.0.0',
'c@1.0.0',
// TODO this should show up in the other :type tests, see lib/query-selector-all.js
'@npmcli/abbrev@2.0.0-beta.45',
'abbrev@1.1.1',
'bar@2.0.0',
Expand Down Expand Up @@ -596,6 +597,22 @@ t.test('query-selector-all', async t => {
'bar@1.4.0',
'moo@3.0.0',
]],
[':type(registry)', [
'a@1.0.0',
'abbrev@1.1.1',
'b@1.0.0',
'bar@2.0.0',
'baz@1.0.0',
'dash-separated-pkg@1.0.0',
'dasher@2.0.0',
'foo@2.2.2',
'bar@1.4.0',
'ipsum@npm:sit@1.0.0',
'lorem@1.0.0',
'moo@3.0.0',
'recur@1.0.0',
'sive@1.0.0',
]],
[':type(git)', []],

// path pseudo
Expand Down
Loading