bun why
解釋為什麼安裝了某個包
bun why 通過顯示導致安裝某個包的相依鏈,解釋為什麼該包安裝在你的專案中。
用法
terminal
bun why <package>
引數
<package>:需要解釋的包名。支援類似@org/*或*-lodash的萬用字元模式。
選項
--top:只顯示頂層相依,而不是完整的相依樹。--depth <number>:顯示相依樹的最大層級深度。
範例
檢查某個特定包為何被安裝:
terminal
bun why react
Text
react@18.2.0
└─ my-app@1.0.0 (requires ^18.0.0)
檢查所有匹配某個模式的包為何被安裝:
terminal
bun why "@types/*"
Text
@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)
只顯示頂層相依:
terminal
bun why express --top
Text
express@4.18.2
└─ my-app@1.0.0 (requires ^4.18.2)
限制相依樹的顯示深度:
terminal
bun why express --depth 2
Text
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)
└─ (更深的相依被隱藏)
理解輸出內容
輸出顯示:
- 被查詢的包名和版本
- 導致該包安裝的相依鏈
- 相依的型別(開發相依 dev、同行相依 peer、可選相依 optional 或生產相依 production)
- 每個包相依中指定的版本要求
對於巢狀相依,命令預設顯示完整的相依樹,縮排表示層級關係。