npm-explain

解释已安装的包

选择命令行版本:

概要

¥Synopsis

npm explain <package-spec>
alias: why

描述

¥Description

此命令将打印导致在当前项目中安装给定包的依赖链。

¥This command will print the chain of dependencies causing a given package to be installed in the current project.

如果提供了一个或多个包规范,则只有与其中一个说明符匹配的包才会解释它们的关系。

¥If one or more package specs are provided, then only packages matching one of the specifiers will have their relationships explained.

包规范还可以引用 ./node_modules 中的文件夹

¥The package spec can also refer to a folder within ./node_modules

例如,在 npm 的源代码树中运行 npm explain glob 将显示:

¥For example, running npm explain glob within npm's source tree will show:

glob@7.1.6
node_modules/glob
glob@"^7.1.4" from the root project
glob@7.1.1 dev
node_modules/tacks/node_modules/glob
glob@"^7.0.5" from rimraf@2.6.2
node_modules/tacks/node_modules/rimraf
rimraf@"^2.6.2" from tacks@1.3.0
node_modules/tacks
dev tacks@"^1.3.0" from the root project

要仅解释驻留在特定文件夹中的包,请将其作为参数传递给命令。当试图弄清楚为什么要复制给定的依赖以满足项目中冲突的版本要求时,这可能很有用。

¥To explain just the package residing at a specific folder, pass that as the argument to the command. This can be useful when trying to figure out exactly why a given dependency is being duplicated to satisfy conflicting version requirements within the project.

$ npm explain node_modules/nyc/node_modules/find-up
find-up@3.0.0 dev
node_modules/nyc/node_modules/find-up
find-up@"^3.0.0" from nyc@14.1.1
node_modules/nyc
nyc@"^14.1.1" from tap@14.10.8
node_modules/tap
dev tap@"^14.10.8" from the root project

配置

¥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 your package.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.

也可以看看

¥See Also

npm 中文网 - 粤ICP备13048890号