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 {
.should_create_webpack_stats()
.await?
{
let webpack_stats =
generate_webpack_stats(app_entry.original_name.clone(), &client_assets).await?;
let webpack_stats = generate_webpack_stats(
*module_graphs.base,
app_entry.original_name.clone(),
client_assets.iter().copied(),
)
.await?;
let stats_output = VirtualOutputAsset::new(
node_root.join(&format!(
"server/app{manifest_path_prefix}/webpack-stats.json",
......
......@@ -1392,8 +1392,12 @@ impl PageEndpoint {
.should_create_webpack_stats()
.await?
{
let webpack_stats =
generate_webpack_stats(original_name.to_owned(), &client_assets.await?).await?;
let webpack_stats = generate_webpack_stats(
self.client_module_graph(),
original_name.to_owned(),
client_assets.await?.iter().copied(),
)
.await?;
let stats_output = VirtualOutputAsset::new(
node_root.join(&format!(
"server/pages{manifest_path_prefix}/webpack-stats.json",
......
This diff is collapsed.
......@@ -339,7 +339,7 @@ export class TurbopackManifestLoader {
private mergeWebpackStats(statsFiles: Iterable<WebpackStats>): WebpackStats {
const entrypoints: Record<string, StatsChunkGroup> = {}
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()
for (const statsFile of statsFiles) {
......@@ -361,8 +361,8 @@ export class TurbopackManifestLoader {
if (statsFile.chunks) {
for (const chunk of statsFile.chunks) {
if (!chunks.has(chunk.name)) {
chunks.set(chunk.name, chunk)
if (!chunks.has(chunk.id!)) {
chunks.set(chunk.id!, chunk)
}
}
}
......@@ -388,6 +388,7 @@ export class TurbopackManifestLoader {
}
return {
version: 'Turbopack',
entrypoints,
assets: [...assets.values()],
chunks: [...chunks.values()],
......
......@@ -294,6 +294,51 @@ pub enum ChunkingType {
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 {
pub fn is_inherit_async(&self) -> bool {
matches!(
......
......@@ -114,6 +114,16 @@ pub enum ExportUsage {
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]
impl ExportUsage {
#[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