Unverified Commit ee1f9d79 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Remove webpack stats generation from Turbopack (#91515)

### What?

Remove the `TURBOPACK_STATS` feature that generated webpack-compatible
`webpack-stats.json` files from Turbopack's output.

**Deleted:**
- `crates/next-api/src/webpack_stats.rs` — the entire 305-line Rust
implementation that built webpack-format stats (assets, chunks, modules,
entrypoints) from Turbopack's module graph

**Rust changes:**
- `crates/next-api/src/lib.rs` — removed `mod webpack_stats;`
- `crates/next-api/src/project.rs` — removed
`should_create_webpack_stats()` which read the `TURBOPACK_STATS` env var
- `crates/next-api/src/pages.rs` — removed `generate_webpack_stats`
import and stats output emission
- `crates/next-api/src/app.rs` — same

**TypeScript changes:**
- `packages/next/src/shared/lib/constants.ts` — removed `WEBPACK_STATS =
'webpack-stats.json'` constant
- `packages/next/src/shared/lib/turbopack/manifest-loader.ts` — removed
`loadWebpackStats()`, `writeWebpackStats()`, `mergeWebpackStats()`, the
`webpackStats` field, webpack type imports, and the `TURBOPACK_STATS`
env guard in `writeManifests()`
- `packages/next/src/server/dev/turbopack-utils.ts` — removed
`shouldCreateWebpackStats` flag and two `loadWebpackStats()` call sites
- `packages/next/src/build/handle-entrypoints.ts` — same

### Why?

This feature is no longer needed and adds dead complexity. It was opt-in
via `TURBOPACK_STATS=1` but nothing in the current codebase or tooling
depends on it.

### How?

Pure deletion — no behavior change for any existing user, as the feature
was opt-in via an environment variable that is no longer checked.

**Intentionally left untouched:**
- Webpack's own `stats.json` generation (non-Turbopack path)
- The Turbopack bundle analyzer / `analyze` feature
- `route-bundle-stats.json` in `.next/diagnostics/`
Co-authored-by: 's avatarTobias Koppers <sokra@users.noreply.github.com>
Co-authored-by: 's avatarClaude <noreply@anthropic.com>
parent d0a0474d
...@@ -88,7 +88,6 @@ use crate::{ ...@@ -88,7 +88,6 @@ use crate::{
}, },
server_actions::{build_server_actions_loader, create_server_actions_manifest}, server_actions::{build_server_actions_loader, create_server_actions_manifest},
sri_manifest::get_sri_manifest_asset, sri_manifest::get_sri_manifest_asset,
webpack_stats::generate_webpack_stats,
}; };
#[turbo_tasks::value] #[turbo_tasks::value]
...@@ -1407,34 +1406,6 @@ impl AppEndpoint { ...@@ -1407,34 +1406,6 @@ impl AppEndpoint {
ResolvedVc::cell(client_assets.into_iter().collect::<Vec<_>>()); ResolvedVc::cell(client_assets.into_iter().collect::<Vec<_>>());
if emit_manifests != EmitManifests::None { if emit_manifests != EmitManifests::None {
if *this
.app_project
.project()
.should_create_webpack_stats()
.await?
{
let webpack_stats = generate_webpack_stats(
*module_graphs.base,
app_entry.original_name.clone(),
client_assets.await?.into_iter().copied(),
)
.await?;
let stats_output = VirtualOutputAsset::new(
node_root.join(&format!(
"server/app{manifest_path_prefix}/webpack-stats.json",
))?,
AssetContent::file(
FileContent::Content(File::from(serde_json::to_string_pretty(
&webpack_stats,
)?))
.cell(),
),
)
.to_resolved()
.await?;
server_assets.insert(ResolvedVc::upcast(stats_output));
}
let build_manifest = BuildManifest { let build_manifest = BuildManifest {
output_path: node_root.join(&format!( output_path: node_root.join(&format!(
"server/app{manifest_path_prefix}/build-manifest.json", "server/app{manifest_path_prefix}/build-manifest.json",
......
...@@ -27,4 +27,3 @@ pub mod routes_hashes_manifest; ...@@ -27,4 +27,3 @@ pub mod routes_hashes_manifest;
mod server_actions; mod server_actions;
mod sri_manifest; mod sri_manifest;
mod versioned_content_map; mod versioned_content_map;
mod webpack_stats;
...@@ -81,7 +81,6 @@ use crate::{ ...@@ -81,7 +81,6 @@ use crate::{
project::Project, project::Project,
route::{Endpoint, EndpointOutput, EndpointOutputPaths, ModuleGraphs, Route, Routes}, route::{Endpoint, EndpointOutput, EndpointOutputPaths, ModuleGraphs, Route, Routes},
sri_manifest::get_sri_manifest_asset, sri_manifest::get_sri_manifest_asset,
webpack_stats::generate_webpack_stats,
}; };
#[turbo_tasks::value] #[turbo_tasks::value]
...@@ -1348,32 +1347,6 @@ impl PageEndpoint { ...@@ -1348,32 +1347,6 @@ impl PageEndpoint {
server_assets.push(next_font_manifest_output); server_assets.push(next_font_manifest_output);
} }
if *this
.pages_project
.project()
.should_create_webpack_stats()
.await?
{
let webpack_stats = generate_webpack_stats(
self.client_module_graph(),
this.original_name.clone(),
client_assets.await?.into_iter().copied(),
)
.await?;
let stats_output = VirtualOutputAsset::new(
node_root.join(&format!(
"server/pages{manifest_path_prefix}/webpack-stats.json",
))?,
AssetContent::file(
FileContent::Content(File::from(serde_json::to_string_pretty(&webpack_stats)?))
.cell(),
),
)
.to_resolved()
.await?;
server_assets.push(ResolvedVc::upcast(stats_output));
}
let page_output = match *ssr_chunk.await? { let page_output = match *ssr_chunk.await? {
SsrChunk::NodeJs { SsrChunk::NodeJs {
entry, entry,
......
...@@ -1221,13 +1221,6 @@ impl Project { ...@@ -1221,13 +1221,6 @@ impl Project {
Vc::cell(self.no_mangling) Vc::cell(self.no_mangling)
} }
#[turbo_tasks::function]
pub(super) async fn should_create_webpack_stats(&self) -> Result<Vc<bool>> {
Ok(Vc::cell(
self.env.read(rcstr!("TURBOPACK_STATS")).await?.is_some(),
))
}
#[turbo_tasks::function] #[turbo_tasks::function]
pub(super) async fn execution_context(self: Vc<Self>) -> Result<Vc<ExecutionContext>> { pub(super) async fn execution_context(self: Vc<Self>) -> Result<Vc<ExecutionContext>> {
let node_root = self.node_root().owned().await?; let node_root = self.node_root().owned().await?;
......
This diff is collapsed.
...@@ -63,8 +63,6 @@ export async function handleRouteType({ ...@@ -63,8 +63,6 @@ export async function handleRouteType({
route: PageRoute | AppRoute route: PageRoute | AppRoute
manifestLoader: TurbopackManifestLoader manifestLoader: TurbopackManifestLoader
}) { }) {
const shouldCreateWebpackStats = process.env.TURBOPACK_STATS != null
switch (route.type) { switch (route.type) {
case 'page': { case 'page': {
const serverKey = getEntryKey('pages', 'server', page) const serverKey = getEntryKey('pages', 'server', page)
...@@ -84,10 +82,6 @@ export async function handleRouteType({ ...@@ -84,10 +82,6 @@ export async function handleRouteType({
await manifestLoader.loadSriManifest(page, 'pages') await manifestLoader.loadSriManifest(page, 'pages')
if (shouldCreateWebpackStats) {
await manifestLoader.loadWebpackStats(page, 'pages')
}
break break
} }
case 'page-api': { case 'page-api': {
...@@ -118,10 +112,6 @@ export async function handleRouteType({ ...@@ -118,10 +112,6 @@ export async function handleRouteType({
manifestLoader.loadSriManifest(page, 'app') manifestLoader.loadSriManifest(page, 'app')
if (shouldCreateWebpackStats) {
manifestLoader.loadWebpackStats(page, 'app')
}
break break
} }
case 'app-route': { case 'app-route': {
......
...@@ -169,8 +169,6 @@ export async function handleRouteType({ ...@@ -169,8 +169,6 @@ export async function handleRouteType({
hooks?: HandleRouteTypeHooks // dev hooks?: HandleRouteTypeHooks // dev
}) { }) {
const shouldCreateWebpackStats = process.env.TURBOPACK_STATS != null
switch (route.type) { switch (route.type) {
case 'page': { case 'page': {
const clientKey = getEntryKey('pages', 'client', page) const clientKey = getEntryKey('pages', 'client', page)
...@@ -236,10 +234,6 @@ export async function handleRouteType({ ...@@ -236,10 +234,6 @@ export async function handleRouteType({
await manifestLoader.loadFontManifest('/_app', 'pages') await manifestLoader.loadFontManifest('/_app', 'pages')
await manifestLoader.loadFontManifest(page, 'pages') await manifestLoader.loadFontManifest(page, 'pages')
if (shouldCreateWebpackStats) {
await manifestLoader.loadWebpackStats(page, 'pages')
}
manifestLoader.writeManifests({ manifestLoader.writeManifests({
devRewrites, devRewrites,
productionRewrites, productionRewrites,
...@@ -389,10 +383,6 @@ export async function handleRouteType({ ...@@ -389,10 +383,6 @@ export async function handleRouteType({
manifestLoader.loadActionManifest(page) manifestLoader.loadActionManifest(page)
manifestLoader.loadFontManifest(page, 'app') manifestLoader.loadFontManifest(page, 'app')
if (shouldCreateWebpackStats) {
manifestLoader.loadWebpackStats(page, 'app')
}
manifestLoader.writeManifests({ manifestLoader.writeManifests({
devRewrites, devRewrites,
productionRewrites, productionRewrites,
......
...@@ -85,7 +85,6 @@ export type PHASE_TYPE = ...@@ -85,7 +85,6 @@ export type PHASE_TYPE =
| typeof PHASE_DEVELOPMENT_SERVER | typeof PHASE_DEVELOPMENT_SERVER
export const PAGES_MANIFEST = 'pages-manifest.json' export const PAGES_MANIFEST = 'pages-manifest.json'
export const WEBPACK_STATS = 'webpack-stats.json'
export const APP_PATHS_MANIFEST = 'app-paths-manifest.json' export const APP_PATHS_MANIFEST = 'app-paths-manifest.json'
export const APP_PATH_ROUTES_MANIFEST = 'app-path-routes-manifest.json' export const APP_PATH_ROUTES_MANIFEST = 'app-path-routes-manifest.json'
export const BUILD_MANIFEST = 'build-manifest.json' export const BUILD_MANIFEST = 'build-manifest.json'
......
...@@ -2,13 +2,6 @@ import type { ...@@ -2,13 +2,6 @@ import type {
EdgeFunctionDefinition, EdgeFunctionDefinition,
MiddlewareManifest, MiddlewareManifest,
} from '../../../build/webpack/plugins/middleware-plugin' } from '../../../build/webpack/plugins/middleware-plugin'
import type {
StatsAsset,
StatsChunk,
StatsChunkGroup,
StatsModule,
StatsCompilation as WebpackStats,
} from 'webpack'
import type { BuildManifest } from '../../../server/get-page-files' import type { BuildManifest } from '../../../server/get-page-files'
import type { PagesManifest } from '../../../build/webpack/plugins/pages-manifest-plugin' import type { PagesManifest } from '../../../build/webpack/plugins/pages-manifest-plugin'
import type { ActionManifest } from '../../../build/webpack/plugins/flight-client-entry-plugin' import type { ActionManifest } from '../../../build/webpack/plugins/flight-client-entry-plugin'
...@@ -27,7 +20,6 @@ import { ...@@ -27,7 +20,6 @@ import {
SUBRESOURCE_INTEGRITY_MANIFEST, SUBRESOURCE_INTEGRITY_MANIFEST,
TURBOPACK_CLIENT_BUILD_MANIFEST, TURBOPACK_CLIENT_BUILD_MANIFEST,
TURBOPACK_CLIENT_MIDDLEWARE_MANIFEST, TURBOPACK_CLIENT_MIDDLEWARE_MANIFEST,
WEBPACK_STATS,
} from '../constants' } from '../constants'
import { join, posix } from 'path' import { join, posix } from 'path'
import { readFileSync } from 'fs' import { readFileSync } from 'fs'
...@@ -69,7 +61,6 @@ type ManifestName = ...@@ -69,7 +61,6 @@ type ManifestName =
| typeof MIDDLEWARE_MANIFEST | typeof MIDDLEWARE_MANIFEST
| typeof BUILD_MANIFEST | typeof BUILD_MANIFEST
| typeof PAGES_MANIFEST | typeof PAGES_MANIFEST
| typeof WEBPACK_STATS
| typeof APP_PATHS_MANIFEST | typeof APP_PATHS_MANIFEST
| `${typeof SERVER_REFERENCE_MANIFEST}.json` | `${typeof SERVER_REFERENCE_MANIFEST}.json`
| `${typeof SUBRESOURCE_INTEGRITY_MANIFEST}.json` | `${typeof SUBRESOURCE_INTEGRITY_MANIFEST}.json`
...@@ -200,8 +191,6 @@ export class TurbopackManifestLoader { ...@@ -200,8 +191,6 @@ export class TurbopackManifestLoader {
> = new ManifestsMap() > = new ManifestsMap()
private pagesManifests: ManifestsMap<string, PagesManifest> = private pagesManifests: ManifestsMap<string, PagesManifest> =
new ManifestsMap() new ManifestsMap()
private webpackStats: ManifestsMap<EntryKey, WebpackStats> =
new ManifestsMap()
private sriManifests: ManifestsMap<EntryKey, SubresourceIntegrityManifest> = private sriManifests: ManifestsMap<EntryKey, SubresourceIntegrityManifest> =
new ManifestsMap() new ManifestsMap()
private encryptionKey: string private encryptionKey: string
...@@ -243,7 +232,6 @@ export class TurbopackManifestLoader { ...@@ -243,7 +232,6 @@ export class TurbopackManifestLoader {
this.fontManifests.delete(key) this.fontManifests.delete(key)
this.middlewareManifests.delete(key) this.middlewareManifests.delete(key)
this.pagesManifests.delete(key) this.pagesManifests.delete(key)
this.webpackStats.delete(key)
} }
loadActionManifest(pageName: string): void { loadActionManifest(pageName: string): void {
...@@ -354,16 +342,6 @@ export class TurbopackManifestLoader { ...@@ -354,16 +342,6 @@ export class TurbopackManifestLoader {
) )
} }
private writeWebpackStats(): void {
if (!this.webpackStats.takeChanged()) {
return
}
const webpackStats = this.mergeWebpackStats(this.webpackStats.values())
const path = join(this.distDir, 'server', WEBPACK_STATS)
this.pendingCacheDeletes.push(path)
writeFileAtomic(path, JSON.stringify(webpackStats, null, 2))
}
private writeSriManifest(): void { private writeSriManifest(): void {
if (!this.sriEnabled || !this.sriManifests.takeChanged()) { if (!this.sriEnabled || !this.sriManifests.takeChanged()) {
return return
...@@ -412,13 +390,6 @@ export class TurbopackManifestLoader { ...@@ -412,13 +390,6 @@ export class TurbopackManifestLoader {
) )
} }
loadWebpackStats(pageName: string, type: 'app' | 'pages' = 'pages'): void {
this.webpackStats.set(
getEntryKey(type, 'client', pageName),
readPartialManifestContent(this.distDir, WEBPACK_STATS, pageName, type)
)
}
loadSriManifest(pageName: string, type: 'app' | 'pages' = 'pages'): void { loadSriManifest(pageName: string, type: 'app' | 'pages' = 'pages'): void {
if (!this.sriEnabled) return if (!this.sriEnabled) return
this.sriManifests.set( this.sriManifests.set(
...@@ -432,66 +403,6 @@ export class TurbopackManifestLoader { ...@@ -432,66 +403,6 @@ 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 | number, StatsChunk> = new Map()
const modules: Map<string | number, StatsModule> = new Map()
for (const statsFile of statsFiles) {
if (statsFile.entrypoints) {
for (const [k, v] of Object.entries(statsFile.entrypoints)) {
if (!entrypoints[k]) {
entrypoints[k] = v
}
}
}
if (statsFile.assets) {
for (const asset of statsFile.assets) {
if (!assets.has(asset.name)) {
assets.set(asset.name, asset)
}
}
}
if (statsFile.chunks) {
for (const chunk of statsFile.chunks) {
if (!chunks.has(chunk.id!)) {
chunks.set(chunk.id!, chunk)
}
}
}
if (statsFile.modules) {
for (const module of statsFile.modules) {
const id = module.id
if (id != null) {
// Merge the chunk list for the module. This can vary across endpoints.
const existing = modules.get(id)
if (existing == null) {
modules.set(id, module)
} else if (module.chunks != null && existing.chunks != null) {
for (const chunk of module.chunks) {
if (!existing.chunks.includes(chunk)) {
existing.chunks.push(chunk)
}
}
}
}
}
}
}
return {
version: 'Turbopack',
entrypoints,
assets: [...assets.values()],
chunks: [...chunks.values()],
modules: [...modules.values()],
}
}
private mergeBuildManifests( private mergeBuildManifests(
manifests: Iterable<BuildManifest>, manifests: Iterable<BuildManifest>,
lowPriorityFiles: string[] lowPriorityFiles: string[]
...@@ -956,10 +867,6 @@ export class TurbopackManifestLoader { ...@@ -956,10 +867,6 @@ export class TurbopackManifestLoader {
this.writeSriManifest() this.writeSriManifest()
if (process.env.TURBOPACK_STATS != null) {
this.writeWebpackStats()
}
// Flush all queued cache deletions in a single require.cache scan // Flush all queued cache deletions in a single require.cache scan
if (this.pendingCacheDeletes.length > 0) { if (this.pendingCacheDeletes.length > 0) {
deleteCache(this.pendingCacheDeletes) deleteCache(this.pendingCacheDeletes)
......
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