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

  • 默认:否
  • 类型:布尔

是否输出 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.

也可以看看

🌐 See Also