Skip to content

Commit f7b7f3c

Browse files
authored
Turbopack: add NEXT_TURBOPACK_WRITE_ROUTES_HASHES_MANIFEST to write hashes into manifest (#86257)
### What? Add an env var to write route hashes into a diagnostics file.
1 parent 2d01e08 commit f7b7f3c

File tree

47 files changed

+635
-34
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+635
-34
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/napi/src/next_api/project.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use next_api::{
2121
ProjectOptions, WatchOptions,
2222
},
2323
route::Endpoint,
24+
routes_hashes_manifest::routes_hashes_manifest_asset_if_enabled,
2425
};
2526
use next_core::tracing_presets::{
2627
TRACING_NEXT_OVERVIEW_TARGETS, TRACING_NEXT_TARGETS, TRACING_NEXT_TURBO_TASKS_TARGETS,
@@ -175,6 +176,9 @@ pub struct NapiProjectOptions {
175176
/// debugging/profiling purposes.
176177
pub no_mangling: bool,
177178

179+
/// Whether to write the route hashes manifest.
180+
pub write_routes_hashes_manifest: bool,
181+
178182
/// The version of Node.js that is available/currently running.
179183
pub current_node_js_version: RcStr,
180184
}
@@ -220,6 +224,9 @@ pub struct NapiPartialProjectOptions {
220224
/// The browserslist query to use for targeting browsers.
221225
pub browserslist_query: Option<RcStr>,
222226

227+
/// Whether to write the route hashes manifest.
228+
pub write_routes_hashes_manifest: Option<bool>,
229+
223230
/// When the code is minified, this opts out of the default mangling of
224231
/// local names for variables, functions etc., which can be useful for
225232
/// debugging/profiling purposes.
@@ -277,6 +284,7 @@ impl From<NapiProjectOptions> for ProjectOptions {
277284
preview_props,
278285
browserslist_query,
279286
no_mangling,
287+
write_routes_hashes_manifest,
280288
current_node_js_version,
281289
} = val;
282290
ProjectOptions {
@@ -292,6 +300,7 @@ impl From<NapiProjectOptions> for ProjectOptions {
292300
preview_props: preview_props.into(),
293301
browserslist_query,
294302
no_mangling,
303+
write_routes_hashes_manifest,
295304
current_node_js_version,
296305
}
297306
}
@@ -312,6 +321,7 @@ impl From<NapiPartialProjectOptions> for PartialProjectOptions {
312321
preview_props,
313322
browserslist_query,
314323
no_mangling,
324+
write_routes_hashes_manifest,
315325
} = val;
316326
PartialProjectOptions {
317327
root_path,
@@ -326,6 +336,7 @@ impl From<NapiPartialProjectOptions> for PartialProjectOptions {
326336
preview_props: preview_props.map(|props| props.into()),
327337
browserslist_query,
328338
no_mangling,
339+
write_routes_hashes_manifest,
329340
}
330341
}
331342
}
@@ -1057,12 +1068,15 @@ async fn output_assets_operation(
10571068

10581069
let nft = next_server_nft_assets(project).await?;
10591070

1071+
let routes_hashes_manifest = routes_hashes_manifest_asset_if_enabled(project).await?;
1072+
10601073
whole_app_module_graphs.as_side_effect().await?;
10611074

10621075
Ok(Vc::cell(
10631076
output_assets
10641077
.into_iter()
10651078
.chain(nft.iter().copied())
1079+
.chain(routes_hashes_manifest.iter().copied())
10661080
.collect(),
10671081
))
10681082
}

crates/next-api/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ swc_core = { workspace = true }
2828
tracing = { workspace = true }
2929
turbo-rcstr = { workspace = true }
3030
turbo-tasks = { workspace = true }
31+
turbo-tasks-hash = { workspace = true }
3132
turbo-tasks-env = { workspace = true }
3233
turbo-tasks-fs = { workspace = true }
3334
turbo-unix-path = { workspace = true }

crates/next-api/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ mod pages;
2121
pub mod paths;
2222
pub mod project;
2323
pub mod route;
24+
pub mod routes_hashes_manifest;
2425
mod server_actions;
2526
mod versioned_content_map;
2627
mod webpack_stats;

crates/next-api/src/pages.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1713,7 +1713,11 @@ impl Endpoint for PageEndpoint {
17131713
async fn module_graphs(self: Vc<Self>) -> Result<Vc<ModuleGraphs>> {
17141714
let client_module_graph = self.client_module_graph().to_resolved().await?;
17151715
let ssr_module_graph = self.ssr_module_graph().to_resolved().await?;
1716-
Ok(Vc::cell(vec![client_module_graph, ssr_module_graph]))
1716+
Ok(Vc::cell(if client_module_graph != ssr_module_graph {
1717+
vec![client_module_graph, ssr_module_graph]
1718+
} else {
1719+
vec![ssr_module_graph]
1720+
}))
17171721
}
17181722
}
17191723

crates/next-api/src/project.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ pub struct ProjectOptions {
189189
/// debugging/profiling purposes.
190190
pub no_mangling: bool,
191191

192+
/// Whether to write the route hashes manifest.
193+
pub write_routes_hashes_manifest: bool,
194+
192195
/// The version of Node.js that is available/currently running.
193196
pub current_node_js_version: RcStr,
194197
}
@@ -237,6 +240,9 @@ pub struct PartialProjectOptions {
237240
/// local names for variables, functions etc., which can be useful for
238241
/// debugging/profiling purposes.
239242
pub no_mangling: Option<bool>,
243+
244+
/// Whether to write the route hashes manifest.
245+
pub write_routes_hashes_manifest: Option<bool>,
240246
}
241247

242248
#[derive(
@@ -357,6 +363,7 @@ impl ProjectContainer {
357363
preview_props,
358364
browserslist_query,
359365
no_mangling,
366+
write_routes_hashes_manifest,
360367
} = options;
361368

362369
let resolved_self = self.to_resolved().await?;
@@ -404,6 +411,9 @@ impl ProjectContainer {
404411
if let Some(no_mangling) = no_mangling {
405412
new_options.no_mangling = no_mangling;
406413
}
414+
if let Some(write_routes_hashes_manifest) = write_routes_hashes_manifest {
415+
new_options.write_routes_hashes_manifest = write_routes_hashes_manifest;
416+
}
407417

408418
// TODO: Handle mode switch, should prevent mode being switched.
409419
let watch = new_options.watch;
@@ -468,6 +478,7 @@ impl ProjectContainer {
468478
let preview_props;
469479
let browserslist_query;
470480
let no_mangling;
481+
let write_routes_hashes_manifest;
471482
let current_node_js_version;
472483
{
473484
let options = self.options_state.get();
@@ -491,6 +502,7 @@ impl ProjectContainer {
491502
preview_props = options.preview_props.clone();
492503
browserslist_query = options.browserslist_query.clone();
493504
no_mangling = options.no_mangling;
505+
write_routes_hashes_manifest = options.write_routes_hashes_manifest;
494506
current_node_js_version = options.current_node_js_version.clone();
495507
}
496508

@@ -516,6 +528,7 @@ impl ProjectContainer {
516528
encryption_key,
517529
preview_props,
518530
no_mangling,
531+
write_routes_hashes_manifest,
519532
current_node_js_version,
520533
}
521534
.cell())
@@ -603,6 +616,9 @@ pub struct Project {
603616
/// debugging/profiling purposes.
604617
no_mangling: bool,
605618

619+
/// Whether to write the route hashes manifest.
620+
write_routes_hashes_manifest: bool,
621+
606622
current_node_js_version: RcStr,
607623
}
608624

@@ -823,6 +839,11 @@ impl Project {
823839
Ok(Vc::cell(self.watch.enable))
824840
}
825841

842+
#[turbo_tasks::function]
843+
pub(super) fn should_write_routes_hashes_manifest(&self) -> Result<Vc<bool>> {
844+
Ok(Vc::cell(self.write_routes_hashes_manifest))
845+
}
846+
826847
#[turbo_tasks::function]
827848
pub(super) async fn per_page_module_graph(&self) -> Result<Vc<bool>> {
828849
Ok(Vc::cell(*self.mode.await? == NextMode::Development))

0 commit comments

Comments
 (0)