You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/content/using-npm/dependency-selectors.md
+17-1
Original file line number
Diff line number
Diff line change
@@ -58,10 +58,26 @@ The [`npm query`](/commands/npm-query) commmand exposes a new dependency selecto
58
58
-`:extraneous` when a dependency exists but is not defined as a dependency of any node
59
59
-`:invalid` when a dependency version is out of its ancestors specified range
60
60
-`:missing` when a dependency is not found on disk
61
-
-`:semver(<spec>)`matching a valid [`node-semver`](https://github.com/npm/node-semver)spec
61
+
-`:semver(<spec>, [selector], [function])`match a valid [`node-semver`](https://github.com/npm/node-semver)version or range to a selector
62
62
-`:path(<path>)`[glob](https://www.npmjs.com/package/glob) matching based on dependencies path relative to the project
63
63
-`:type(<type>)`[based on currently recognized types](https://github.com/npm/npm-package-arg#result-object)
64
64
65
+
##### `:semver(<spec>, [selector], [function])`
66
+
67
+
The `:semver()` pseudo selector allows comparing fields from each node's `package.json` using [semver](https://github.com/npm/node-semver#readme) methods. It accepts up to 3 parameters, all but the first of which are optional.
68
+
69
+
-`spec` a semver version or range
70
+
-`selector` an attribute selector for each node (default `[version]`)
71
+
-`function` a semver method to apply, one of: `satisfies`, `intersects`, `subset`, `gt`, `gte`, `gtr`, `lt`, `lte`, `ltr`, `eq`, `neq` or the special function `infer` (default `infer`)
72
+
73
+
When the special `infer` function is used the `spec` and the actual value from the node are compared. If both are versions, according to `semver.valid()`, `eq` is used. If both values are ranges, according to `!semver.valid()`, `intersects` is used. If the values are mixed types `satisfies` is used.
74
+
75
+
Some examples:
76
+
77
+
-`:semver(^1.0.0)` returns every node that has a `version` satisfied by the provided range `^1.0.0`
78
+
-`:semver(16.0.0, :attr(engines, [node]))` returns every node which has an `engines.node` property satisfying the version `16.0.0`
79
+
-`:semver(1.0.0, [version], lt)` every node with a `version` less than `1.0.0`
0 commit comments