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整理維護