选择命令行版本:
🌐 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
如果你要查询的字段值是对象的属性,你应该运行:
🌐 If the field value you are querying for is a property of an object, you should run:
npm view express time'[4.8.0]'
可以指定多个字段,并将依次打印。例如,要获取所有贡献者的名称和电子邮件地址,可以这样做:
🌐 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
如果“Person”字段本应显示为对象,它们将显示为字符串。例如,这将以简化的字符串格式显示 npm 贡献者列表。(有关更多信息,请参见 package.json)。
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是否输出 JSON 数据,而不是正常输出。
🌐 Whether or not to output JSON data, rather than the normal output.
npm pkg set 中,它可以在将值保存到你的 package.json 之前使用 JSON.parse() 解析设置的值。并非所有 npm 命令都支持。
🌐 Not supported by all npm commands.
workspace启用在当前项目的已配置工作区的上下文中运行命令,同时通过仅运行此配置选项定义的工作区进行过滤。
🌐 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:
对于 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设置为 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 配置中指定了一个或多个工作区。此值不会导出到子进程的环境中。
🌐 This value is not exported to the environment for child processes.
include-workspace-root为命令启用工作区时包括工作区根。
🌐 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