Unverified Commit f4f0c449 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: make stats.json useable (#81318)

Make the `.next/server/webpack-stats.json` file that was already getting generated with `TURBOPACK_STATS=1` actually usable with https://statoscope.tech/.

Not the most efficient implementation, but definitely works for small apps.

- Chunks have the parent/child connection (though I can't see that in the UI)
- Modules have the `reasons` set, so the module graph traversal works now. Note that this all ignores scope hoisting though, so there are some modules missing right now in some views

![Bildschirmfoto 2025-07-04 um 22 44 42](https://github.com/user-attachments/assets/b51c93fd-fd6d-404c-b8db-26de4500beb2)
parent ea9585ae
...@@ -1368,8 +1368,12 @@ impl AppEndpoint { ...@@ -1368,8 +1368,12 @@ impl AppEndpoint {
.should_create_webpack_stats() .should_create_webpack_stats()
.await? .await?
{ {
let webpack_stats = let webpack_stats = generate_webpack_stats(
generate_webpack_stats(app_entry.original_name.clone(), &client_assets).await?; *module_graphs.base,
app_entry.original_name.clone(),
client_assets.iter().copied(),
)
.await?;
let stats_output = VirtualOutputAsset::new( let stats_output = VirtualOutputAsset::new(
node_root.join(&format!( node_root.join(&format!(
"server/app{manifest_path_prefix}/webpack-stats.json", "server/app{manifest_path_prefix}/webpack-stats.json",
......
...@@ -1392,8 +1392,12 @@ impl PageEndpoint { ...@@ -1392,8 +1392,12 @@ impl PageEndpoint {
.should_create_webpack_stats() .should_create_webpack_stats()
.await? .await?
{ {
let webpack_stats = let webpack_stats = generate_webpack_stats(
generate_webpack_stats(original_name.to_owned(), &client_assets.await?).await?; self.client_module_graph(),
original_name.to_owned(),
client_assets.await?.iter().copied(),
)
.await?;
let stats_output = VirtualOutputAsset::new( let stats_output = VirtualOutputAsset::new(
node_root.join(&format!( node_root.join(&format!(
"server/pages{manifest_path_prefix}/webpack-stats.json", "server/pages{manifest_path_prefix}/webpack-stats.json",
......
This diff is collapsed.
...@@ -339,7 +339,7 @@ export class TurbopackManifestLoader { ...@@ -339,7 +339,7 @@ export class TurbopackManifestLoader {
private mergeWebpackStats(statsFiles: Iterable<WebpackStats>): WebpackStats { private mergeWebpackStats(statsFiles: Iterable<WebpackStats>): WebpackStats {
const entrypoints: Record<string, StatsChunkGroup> = {} const entrypoints: Record<string, StatsChunkGroup> = {}
const assets: Map<string, StatsAsset> = new Map() const assets: Map<string, StatsAsset> = new Map()
const chunks: Map<string, StatsChunk> = new Map() const chunks: Map<string | number, StatsChunk> = new Map()
const modules: Map<string | number, StatsModule> = new Map() const modules: Map<string | number, StatsModule> = new Map()
for (const statsFile of statsFiles) { for (const statsFile of statsFiles) {
...@@ -361,8 +361,8 @@ export class TurbopackManifestLoader { ...@@ -361,8 +361,8 @@ export class TurbopackManifestLoader {
if (statsFile.chunks) { if (statsFile.chunks) {
for (const chunk of statsFile.chunks) { for (const chunk of statsFile.chunks) {
if (!chunks.has(chunk.name)) { if (!chunks.has(chunk.id!)) {
chunks.set(chunk.name, chunk) chunks.set(chunk.id!, chunk)
} }
} }
} }
...@@ -388,6 +388,7 @@ export class TurbopackManifestLoader { ...@@ -388,6 +388,7 @@ export class TurbopackManifestLoader {
} }
return { return {
version: 'Turbopack',
entrypoints, entrypoints,
assets: [...assets.values()], assets: [...assets.values()],
chunks: [...chunks.values()], chunks: [...chunks.values()],
......
...@@ -294,6 +294,51 @@ pub enum ChunkingType { ...@@ -294,6 +294,51 @@ pub enum ChunkingType {
Traced, Traced,
} }
impl Display for ChunkingType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ChunkingType::Parallel {
inherit_async,
hoisted,
} => {
write!(
f,
"Parallel(inherit_async: {inherit_async}, hoisted: {hoisted})",
)
}
ChunkingType::Async => write!(f, "Async"),
ChunkingType::Isolated {
_ty,
merge_tag: Some(merge_tag),
} => {
write!(f, "Isolated(merge_tag: {merge_tag})")
}
ChunkingType::Isolated {
_ty,
merge_tag: None,
} => {
write!(f, "Isolated")
}
ChunkingType::Shared {
inherit_async,
merge_tag: Some(merge_tag),
} => {
write!(
f,
"Shared(inherit_async: {inherit_async}, merge_tag: {merge_tag})"
)
}
ChunkingType::Shared {
inherit_async,
merge_tag: None,
} => {
write!(f, "Shared(inherit_async: {inherit_async})")
}
ChunkingType::Traced => write!(f, "Traced"),
}
}
}
impl ChunkingType { impl ChunkingType {
pub fn is_inherit_async(&self) -> bool { pub fn is_inherit_async(&self) -> bool {
matches!( matches!(
......
...@@ -114,6 +114,16 @@ pub enum ExportUsage { ...@@ -114,6 +114,16 @@ pub enum ExportUsage {
Evaluation, Evaluation,
} }
impl Display for ExportUsage {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
ExportUsage::Named(name) => write!(f, "export {name}"),
ExportUsage::All => write!(f, "all"),
ExportUsage::Evaluation => write!(f, "evaluation"),
}
}
}
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl ExportUsage { impl ExportUsage {
#[turbo_tasks::function] #[turbo_tasks::function]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment