依赖选择器语法和查询
选择命令行版本:
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 ofNode
that can be queried -
"dependencies" 一词是指在
Arborist
返回的tree
中找到的任何Node
¥the term "dependencies" is in reference to any
Node
found in atree
returned 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
依赖,或者是所述依赖的子项¥
.prod
dependency found in thedependencies
section ofpackage.json
, or is a child of said dependency -
在
package.json
的devDependencies
部 分中找到的.dev
依赖,或者是所述依赖的子项¥
.dev
dependency found in thedevDependencies
section ofpackage.json
, or is a child of said dependency -
在
package.json
的optionalDependencies
部分中找到.optional
依赖,或者在package.json
的peerDependenciesMeta
部分的条目中设置了"optional": true
,或者所述依赖的子项¥
.optional
dependency found in theoptionalDependencies
section ofpackage.json
, or has"optional": true
set in its entry in thepeerDependenciesMeta
section ofpackage.json
, or a child of said dependency -
在
package.json
的peerDependencies
部分中找到.peer
依赖¥
.peer
dependency found in thepeerDependencies
section ofpackage.json
-
在
package.json
的workspaces
部分中找到.workspace
依赖¥
.workspace
dependency found in theworkspaces
section ofpackage.json
-
在
package.json
的bundleDependencies
部分中找到的.bundled
依赖,或者是所述依赖的子项¥
.bundled
dependency found in thebundleDependencies
section ofpackage.json
, or is a child of said dependency