feat(build): add --metafile-md CLI option for LLM-friendly bundle analysis

Merged
RO
8mo ago
+1676-42

Summary

  • Adds --metafile-md CLI option to bun build that 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:

  1. Quick Summary - Module counts, sizes, ESM/CJS breakdown, output/input ratio
  2. Largest Input Files - Sorted by size to identify potential bloat
  3. Entry Point Analysis - Shows bundle size, exports, CSS bundles, and bundled modules
  4. Dependency Chains - Most commonly imported modules and reverse dependencies
  5. Full Module Graph - Complete import/export info for each module
  6. 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 --metafile and --metafile-md together
  • 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