Expand description
Convert Next.js Turbopack bundle analysis data into Unigraph MapGraph JSON.
§Background
Next.js ships a command next experimental-analyze -o that runs a production
Turbopack build and writes binary analysis data to .next/diagnostics/analyze/data/.
This data contains the full module dependency graph plus per-route size attribution.
This crate reads that data and produces a Unigraph MapGraph — a JSON format
that Unigraph Explorer can visualize with dominator trees, tiered metrics,
force-directed layout, and more.
§Data sources
The analyze output directory contains three kinds of files:
-
modules.data— Global module dependency graph. Contains every module across all routes and RSC layers, plus sync and async dependency edges. This is ONE graph — edges do not vary per route. -
routes.json— JSON array of route path strings (e.g.["/", "/about"]). -
Per-route
analyze.data— Size attribution data. For each route, which source files contribute how many bytes to the route’s output chunks. Contains NO dependency edges — only sizes.
See ANALYZE_DATA_FORMAT.md in this crate for the full binary format specification.
§Key design decisions
-
Layers always separate: The same file compiled in different RSC layers (
app-rsc,app-client,app-ssr) has genuinely different dependency edges and produces separate nodes. Alayerlabel enables UI filtering. -
Single graph, routes as labels: Since edges are global, we produce one graph with
routelabels on each node indicating which routes include it. Sizes are summed across routes. -
Fragments collapsed by default: Tree-shaking fragments (
<exports>,<module evaluation>) are merged back into their parent module unless--fragmentsis passed. Collapsing unions edges, sums sizes, and removes self-edges that arise from inter-fragment references. -
Tiered traversal: Sync imports map to the “eager” tier, async imports (
import()) map to the “lazy” tier. This gives Unigraph’s tiered metrics:size#eager(initial load),size#lazy(total),size#eager~dominated(unique cost per module in the initial bundle).
§Usage
# Generate analyze data
cd your-next-app && ./node_modules/.bin/next experimental-analyze -o
# Convert to Unigraph (via task runner)
ut unigraph_turbopack .next/diagnostics/analyze/data/ -o graph.json --pretty
# Visualize
ut serve -f graph.jsonStructs§
- Options
- Controls how the Turbopack data is mapped to Unigraph nodes.
Functions§
- build_
map_ graph - Read Turbopack analyze data from
data_dirand produce a UnigraphMapGraph.