How zunaib/bundle-size-guardian works
bundle-size-guardian audits JavaScript/TypeScript dependencies, recommends smaller alternatives, and can rewrite imports through a CLI or MCP interface. The principal flow is analyze imports and sizes, surface alternatives, then optionally generate and apply refactor patches. Edges reflect the shown calls and documented external behavior; test/rollback behavior is visible in the refactor implementation, while some CLI branches are only partially excerpted.
Main entry points: cli.ts CLI commands · refactor.ts Patch and package changes · mcp-server.ts MCP tools · suggest.ts Alternative selection
Components 19
User interfaces
- CLI commands
src/cli.ts - MCP tools
src/mcp-server.ts
Dependency audit
- Import analysis
src/analyze.ts - Bundle size lookup
src/bundlesize.ts - Local size estimate
src/bundlesize.ts
Alternative recommendations
- Alternative selection
src/suggest.ts - Built-in mappings
src/known-alternatives.ts
Refactor workflow
- Affected file discovery
src/refactor.ts - Patch generation
src/refactor.ts - Patch and package changes
src/refactor.ts - Test and rollback
src/refactor.ts - Savings log
src/refactor.ts
Other components
- CLI user
- MCP client
- Target project
- Bundlephobia API
- Anthropic Claude
- Project test command
- npm package manager
Connections 25
- CLI user → CLI commands: runs commands
README.md - CLI commands → Import analysis: analyzes imports
src/cli.ts - CLI commands → Alternative selection: requests suggestions
src/cli.ts - CLI commands → Affected file discovery: requests refactor
src/cli.ts - CLI commands → MCP tools: starts server
src/cli.ts - MCP client → MCP tools: calls tools
README.md - MCP tools → Import analysis: analyzes imports
src/mcp-server.ts - MCP tools → Alternative selection: requests suggestions
src/mcp-server.ts - MCP tools → Affected file discovery: requests refactor
src/mcp-server.ts - Target project → Import analysis: provides manifests and source
src/analyze.ts - Import analysis → Bundle size lookup: looks up sizes
src/analyze.ts - Bundle size lookup → Bundlephobia API: queries sizes
src/bundlesize.ts - Bundle size lookup → Local size estimate: falls back to estimate
src/bundlesize.ts - Alternative selection → Built-in mappings: checks mappings
src/suggest.ts - Alternative selection → Anthropic Claude: queries unknown packages
src/suggest.ts - Target project → Affected file discovery: provides source files
src/refactor.ts - Affected file discovery → Patch generation: provides affected contents
src/refactor.ts - Patch generation → Anthropic Claude: requests rewritten files
src/refactor.ts - Patch generation → Patch and package changes: returns patches
src/refactor.ts - Patch and package changes → Target project: writes files
src/refactor.ts - Patch and package changes → npm package manager: installs replacement and removes old package
src/refactor.ts - Patch and package changes → Test and rollback: optionally tests changes
src/refactor.ts - Test and rollback → Project test command: runs test commands
src/refactor.ts - Test and rollback → Target project: restores files on failure
src/refactor.ts - Patch and package changes → Savings log: records completed change
src/refactor.ts