目录
选择命令行版本:
目录
概要
¥Synopsis
npm view [<package-spec>] [<field>[.subfield]...]aliases: info, show, v
描述
¥Description
此命令显示有关包的数据并将其打印到标准输出。
¥This command shows data about a package and prints it to stdout.
例如,要从注册表中查看有关 connect
包的信息,你可以运行:
¥As an example, to view information about the connect
package from the registry, you would run:
npm view connect
如果未指定,则默认版本为 "latest"
。
¥The default version is "latest"
if unspecified.
可以在包描述符之后指定字段名称。例如,要显示 0.3.5
版本的 ronn
包的依赖,你可以执行以下操作:
¥Field names can be specified after the package descriptor. For example, to show the dependencies of the ronn
package at version 0.3.5
, you could do the following:
npm view ronn@0.3.5 dependencies
你可以通过用句点分隔子字段来查看子字段。要查看最新版本 npm
的 git 存储库 URL,你将运行以下命令:
¥You can view child fields by separating them with a period. To view the git repository URL for the latest version of npm
, you would run the following command:
npm view npm repository.url
这使得使用一些 shell 脚本可以轻松查看有关依赖的信息。例如,要查看 ronn
所依赖的 opts
版本的所有数据,可以这样写:
¥This makes it easy to view information about a dependency with a bit of shell scripting. For example, to view all the data about the version of opts
that ronn
depends on, you could write the following:
npm view opts@$(npm view ronn dependencies.opts)
对于数组字段,请求非数字字段将返回列表中对象的所有值。例如,要获取 express
包的所有贡献者电子邮件地址,你可以运行:
¥For fields that are arrays, requesting a non-numeric field will return all of the values from the objects in the list. For example, to get all the contributor email addresses for the express
package, you would run:
npm view express contributors.email
你还可以在方括号中使用数字索引来专门选择数组字段中的项目。要获取列表中第一个贡献者的电子邮件地址,你可以运行:
¥You may also use numeric indices in square braces to specifically select an item in an array field. To just get the email address of the first contributor in the list, you can run:
npm view express contributors[0].email
可以指定多个字段,并且将一个接一个地打印。例如,要获取所有贡献者名称和电子邮件地址,你可以这样做:
¥Multiple fields may be specified, and will be printed one after another. For example, to get all the contributor names and email addresses, you can do this:
npm view express contributors.name contributors.email
"人" 字段如果显示为对象,则显示为字符串。因此,例如,这将以缩短的字符串格式显示 npm
贡献者的列表。(有关这方面的更多信息,请参见 package.json
。)
¥"Person" fields are shown as a string if they would be shown as an object. So, for example, this will show the list of npm
contributors in the shortened string format. (See package.json
for more on this.)
npm view npm contributors
如果提供了版本范围,则将为包的每个匹配版本打印数据。这将显示每个匹配的 yui3
版本需要哪个版本的 jsdom
:
¥If a version range is provided, then data will be printed for every matching version of the package. This will show which version of jsdom
was required by each matching version of yui3
:
npm view yui3@'>0.5.4' dependencies.jsdom
要显示 connect
包版本历史,你可以这样做:
¥To show the connect
package version history, you can do this:
npm view connect versions
配置
¥Configuration
json
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
是否输出 JSON 数据,而不是正常输出。
¥Whether or not to output JSON data, rather than the normal output.
-
在
npm pkg set
中,它可以使用 JSON.parse() 解析集合值,然后再将它们保存到你的package.json
。¥In
npm pkg set
it enables parsing set values with JSON.parse() before saving them to yourpackage.json
.
并非所有 npm 命令都支持。
¥Not supported by all npm commands.
workspace
-
默认值:
¥Default:
-
类型:字符串(可以设置多次)
¥Type: String (can be set multiple times)
启用在当前项目的已配置工作区的上下文中运行命令,同时通过仅运行此配置选项定义的工作区进行过滤。
¥Enable running a command in the context of the configured workspaces of the current project while filtering by running only the workspaces defined by this configuration option.
workspace
配置的有效值为:
¥Valid values for the workspace
config are either:
-
工作区名称
¥Workspace names
-
工作区目录的路径
¥Path to a workspace directory
-
父工作区目录的路径(将导致选择该文件夹中的所有工作区)
¥Path to a parent workspace directory (will result in selecting all workspaces within that folder)
为 npm init
命令设置时,可以将其设置为尚不存在的工作区的文件夹,以创建文件夹并将其设置为项目中的全新工作区。
¥When set for the npm init
command, this may be set to the folder of a workspace which does not yet exist, to create the folder and set it up as a brand new workspace within the project.
此值不会导出到子进程的环境中。
¥This value is not exported to the environment for child processes.
workspaces
-
默认值:null
¥Default: null
-
类型:空值或布尔值
¥Type: null or Boolean
设置为 true 可在所有已配置工作区的上下文中运行该命令。
¥Set to true to run the command in the context of all configured workspaces.
显式将此设置为 false 将导致像 install
这样的命令完全忽略工作区。未明确设置时:
¥Explicitly setting this to false will cause commands like install
to ignore workspaces altogether. When not set explicitly:
-
在
node_modules
树上运行的命令(安装、更新等)会将工作区链接到node_modules
文件夹。* 执行其他操作(测试、执行、发布等)的命令将在根项目上运行,除非在workspace
配置中指定了一个或多个工作区。¥Commands that operate on the
node_modules
tree (install, update, etc.) will link workspaces into thenode_modules
folder. - Commands that do other things (test, exec, publish, etc.) will operate on the root project, unless one or more workspaces are specified in theworkspace
config.
此值不会导出到子进程的环境中。
¥This value is not exported to the environment for child processes.
include-workspace-root
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
为命令启用工作区时包括工作区根。
¥Include the workspace root when workspaces are enabled for a command.
当为 false 时,通过 workspace
配置指定单个工作区,或通过 workspaces
标志指定所有工作区,将导致 npm 仅在指定的工作区上运行,而不是在根项目上运行。
¥When false, specifying individual workspaces via the workspace
config, or all workspaces via the workspaces
flag, will cause npm to operate only on the specified workspaces, and not on the root project.
此值不会导出到子进程的环境中。
¥This value is not exported to the environment for child processes.
输出
¥Output
如果仅输出单个版本的单个字符串字段,则不会对其进行着色或引用,以将输出通过管道传输到另一个命令。如果该字段是一个对象,它将作为 JavaScript 对象字面量输出。
¥If only a single string field for a single version is output, then it will not be colorized or quoted, to enable piping the output to another command. If the field is an object, it will be output as a JavaScript object literal.
如果给出 --json
标志,则输出字段将为 JSON。
¥If the --json
flag is given, the outputted fields will be JSON.
如果版本范围匹配多个版本,则每个打印的值都将以其适用的版本为前缀。
¥If the version range matches multiple versions then each printed value will be prefixed with the version it applies to.
如果请求多个字段,则每个字段都以字段名称为前缀。
¥If multiple fields are requested, then each of them is prefixed with the field name.
也可以看看
¥See Also