依赖选择器语法和查询
选择命令行版本:
See Details
目录
描述
¥Description
npm query 命令公开了一个新的依赖选择器语法(参考并尊重 CSS 选择器 4 规范 的许多方面),其中:
¥The npm query command exposes a new dependency selector syntax (informed by & respecting many aspects of the CSS Selectors 4 Spec) which:
-
使用健壮的对象模型、元数据和选择器语法标准化依赖图的形状和查询
¥Standardizes the shape of, & querying of, dependency graphs with a robust object model, metadata & selector syntax
-
利用 CSS 中现有的已知语言语法和运算符来广泛访问不同的包信息
¥Leverages existing, known language syntax & operators from CSS to make disparate package information broadly accessible
-
解锁回答有关依赖、它们的关系和关联元数据的复杂、多方面问题的能力
¥Unlocks the ability to answer complex, multi-faceted questions about dependencies, their relationships & associative metadata
-
合并
npm中类似查询命令的冗余逻辑(例如npm fund、npm ls、npm outdated、npm audit...)¥Consolidates redundant logic of similar query commands in
npm(ex.npm fund,npm ls,npm outdated,npm audit...)
依赖选择器语法 v1.0.0
¥Dependency Selector Syntax v1.0.0
概述
¥Overview:
-
没有 "type" 或 "tag" 选择器(例如
div, h1, a),因为依赖/目标是唯一可以查询的Node类型¥there is no "type" or "tag" selectors (ex.
div, h1, a) as a dependency/target is the only type ofNodethat can be queried -
"dependencies" 一词是指在
Arborist返回的tree中找到的任何Node¥the term "dependencies" is in reference to any
Nodefound in atreereturned byArborist
组合器
¥Combinators
-
>直系后代/子代¥
>direct descendant/child -
任何后代/子级¥
any descendant/child -
~兄弟姐妹¥
~sibling
选择器
¥Selectors
-
*万能选择器¥
*universal selector -
#<name>依赖选择器(相当于[name="..."])¥
#<name>dependency selector (equivalent to[name="..."]) -
#<name>@<version>(相当于[name=<name>]:semver(<version>))¥
#<name>@<version>(equivalent to[name=<name>]:semver(<version>)) -
,选择器列表分隔符¥
,selector list delimiter -
.依赖类型选择器¥
.dependency type selector -
:伪选择器¥
:pseudo selector
依赖类型选择器
¥Dependency Type Selectors
-
在
package.json的dependencies部分中找到的.prod依赖,或者是所述依赖的子项¥
.proddependency found in thedependenciessection ofpackage.json, or is a child of said dependency -
在
package.json的devDependencies部 分中找到的.dev依赖,或者是所述依赖的子项¥
.devdependency found in thedevDependenciessection ofpackage.json, or is a child of said dependency -
在
package.json的optionalDependencies部分中找到.optional依赖,或者在package.json的peerDependenciesMeta部分的条目中设置了"optional": true,或者所述依赖的子项¥
.optionaldependency found in theoptionalDependenciessection ofpackage.json, or has"optional": trueset in its entry in thepeerDependenciesMetasection ofpackage.json, or a child of said dependency -
在
package.json的peerDependencies部分中找到.peer依赖¥
.peerdependency found in thepeerDependenciessection ofpackage.json -
在
package.json的workspaces部分中找到.workspace依赖¥
.workspacedependency found in theworkspacessection ofpackage.json -
在
package.json的bundleDependencies部分中找到的.bundled依赖,或者是所述依赖的子项¥
.bundleddependency found in thebundleDependenciessection ofpackage.json, or is a child of said dependency