Files
bun.sh/docs/cli/why.md
Claude Bot 38117fb07d docs: update documentation for recent API additions
Adds comprehensive documentation for features introduced in recent releases:

## CLI Commands & Features
- Enhanced `bun pm pkg` subcommands (get/set/delete/fix)
- `bun install --linker=isolated` for pnpm-style installs
- `bun audit` filtering flags (--audit-level, --prod, --ignore)
- Security Scanner API for vulnerability scanning
- Fixed examples in `bun why` command docs

## Testing APIs
- `expectTypeOf` for TypeScript type-level testing
- New mock return value matchers: `toHaveReturnedWith`, `toHaveLastReturnedWith`, `toHaveNthReturnedWith`
- `mock.clearAllMocks()` for global mock state management

## Runtime & Build APIs
- ReadableStream convenience methods (`.text()`, `.json()`, `.bytes()`, `.blob()`)
- WebSocket `permessage-deflate` compression support
- `Math.sumPrecise` high-precision summation
- Enhanced `Bun.build()` compile API with cross-platform targets
- Ahead-of-time bundling for HTML imports in server-side code

All examples tested and verified working in Bun v1.2.21.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-01 08:04:33 +00:00

1.6 KiB

The bun why command explains why a package is installed in your project by showing the dependency chain that led to its installation.

Usage

$ bun why <package>

Arguments

  • <package>: The name of the package to explain. Supports glob patterns like @org/* or *-lodash.

Options

  • --top: Show only the top-level dependencies instead of the complete dependency tree.
  • --depth <number>: Maximum depth of the dependency tree to display.

Examples

Check why a specific package is installed:

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

Check why all packages with a specific pattern are installed:

$ bun why "@types/*"
@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)

Show only top-level dependencies:

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

Limit the dependency tree depth:

$ bun why express --depth 2
express@4.18.2
  └─ my-app@1.0.0 (requires ^4.18.2)
     └─ body-parser@1.20.2 (requires ^1.20.1)
     └─ accepts@1.3.8 (requires ^1.3.5)
        └─ (deeper dependencies hidden)

Understanding the Output

The output shows:

  • The package name and version being queried
  • The dependency chain that led to its installation
  • The type of dependency (dev, peer, optional, or production)
  • The version requirement specified in each package's dependencies

For nested dependencies, the command shows the complete dependency tree by default, with indentation indicating the relationship hierarchy.