Skip to content

Commit 4fcd352

Browse files
authored
feat: add :type(registry) to query selector syntax (#9017)
1 parent e1b21f0 commit 4fcd352

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

docs/lib/content/using-npm/dependency-selectors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ The [`npm query`](/commands/npm-query) command exposes a new dependency selector
6262
- `:missing` when a dependency is not found on disk
6363
- `:semver(<spec>, [selector], [function])` match a valid [`node-semver`](https://github.com/npm/node-semver) version or range to a selector
6464
- `:path(<path>)` [glob](https://www.npmjs.com/package/glob) matching based on dependencies path relative to the project
65-
- `:type(<type>)` [based on currently recognized types](https://github.com/npm/npm-package-arg#result-object)
65+
- `: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)
6666
- `:outdated(<type>)` when a dependency is outdated
6767
- `:vuln(<selector>)` when a dependency has a known vulnerability
6868

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,19 @@ class Results {
427427
if (!this.currentAstNode.typeValue) {
428428
return this.initialItems
429429
}
430+
// TODO this differs subtly with `:type()` because it now iterates on edgesIn, which means extraneous deps won't show up
431+
// note how "@npmcli/[email protected]" is in the `:type()` results in the test but not in any of the other results.
430432
return this.initialItems
431433
.flatMap(node => {
432434
const found = []
435+
const { typeValue } = this.currentAstNode
433436
for (const edge of node.edgesIn) {
434-
if (npa(`${edge.name}@${edge.spec}`).type === this.currentAstNode.typeValue) {
437+
const parsedArg = npa(`${edge.name}@${edge.spec}`)
438+
if (typeValue === 'registry') {
439+
if (parsedArg.registry) {
440+
found.push(edge.to)
441+
}
442+
} else if (parsedArg.type === typeValue) {
435443
found.push(edge.to)
436444
}
437445
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ t.test('query-selector-all', async t => {
569569
570570
571571
572+
// TODO this should show up in the other :type tests, see lib/query-selector-all.js
572573
'@npmcli/[email protected]',
573574
574575
@@ -596,6 +597,22 @@ t.test('query-selector-all', async t => {
596597
597598
598599
]],
600+
[':type(registry)', [
601+
602+
603+
604+
605+
606+
607+
608+
609+
610+
'ipsum@npm:[email protected]',
611+
612+
613+
614+
615+
]],
599616
[':type(git)', []],
600617

601618
// path pseudo

0 commit comments

Comments
 (0)