feat(build): add --metafile-md CLI option for LLM-friendly bundle analysis
Merged
RO
8mo ago+1676+1676+0123456789012345678901234567890123456789-42-42-01234567890123456789
Summary
- Adds
--metafile-mdCLI option tobun buildthat generates a markdown visualization of the module graph - Designed to help Claude and other LLMs analyze bundle composition, identify bloat, and understand dependency chains
- Reuses existing metafile JSON generation code as a post-processing step
Features
The generated markdown includes:
- Quick Summary - Module counts, sizes, ESM/CJS breakdown, output/input ratio
- Largest Input Files - Sorted by size to identify potential bloat
- Entry Point Analysis - Shows bundle size, exports, CSS bundles, and bundled modules
- Dependency Chains - Most commonly imported modules and reverse dependencies
- Full Module Graph - Complete import/export info for each module
- Raw Data for Searching - Grep-friendly markers in code blocks:
[MODULE:],[SIZE:],[IMPORT:],[IMPORTED_BY:][ENTRY:],[EXTERNAL:],[NODE_MODULES:]
Usage
# Default filename (meta.md)
bun build entry.js --metafile-md --outdir=dist
# Custom filename
bun build entry.js --metafile-md=analysis.md --outdir=dist
# Both JSON and markdown
bun build entry.js --metafile=meta.json --metafile-md=meta.md --outdir=dist
Example Output
See sample output: https://gist.github.com/example (will add)
Test plan
- Test default filename (
meta.md) - Test custom filename
- Test both
--metafileand--metafile-mdtogether - Test summary metrics
- Test module format info (ESM/CJS)
- Test external imports
- Test exports list
- Test bundled modules table
- Test CSS bundle reference
- Test import kinds (static, dynamic, require)
- Test commonly imported modules
- Test largest files sorting (bloat analysis)
- Test output/input ratio
- Test grep-friendly raw data section
- Test entry point markers
- Test external import markers
- Test node_modules markers
All 17 new tests pass.
š¤ Generated with Claude Code