Skip to content

bun why 命令通过显示导致其安装的依赖链来解释为什么包被安装在你的项目中。

用法

bash
bun why <package>

参数

  • <package>:要解释的包名。支持 glob 模式,如 @org/**-lodash

选项

  • --top:仅显示顶级依赖,而不是完整的依赖树。
  • --depth <number>:要显示的依赖树的最大深度。

示例

检查为什么安装了特定包:

bash
bun why react
txt
react@18.2.0
  └─ my-app@1.0.0 (requires ^18.0.0)

检查为什么安装了具有特定模式的所有包:

bash
bun why "@types/*"
txt
@types/react@18.2.15
  └─ dev my-app@1.0.0 (requires ^18.0.0)

@types/react-dom@18.2.7
  └─ dev my-app@1.0.0 (requires ^18.0.0)

仅显示顶级依赖:

bash
bun why express --top
txt
express@4.18.2
  └─ my-app@1.0.0 (requires ^4.18.2)

限制依赖树深度:

bash
bun why express --depth 2
txt
express@4.18.2
  └─ express-pollyfill@1.20.1 (requires ^4.18.2)
     └─ body-parser@1.20.1 (requires ^1.20.1)
     └─ accepts@1.3.8 (requires ^1.3.8)
        └─ (deeper dependencies hidden)

理解输出

输出显示:

  • 查询的包名和版本
  • 导致其安装的依赖链
  • 依赖类型(dev、peer、optional 或 production)
  • 每个包的依赖中指定的版本要求

对于嵌套依赖,命令默认显示完整的依赖树,缩进表示关系层次结构。

Bun学习网由www.bunjs.com.cn整理维护