@@ -88,7 +88,7 @@ use crate::{
8888 all_asset_paths, all_paths_in_root, get_asset_paths_from_root, get_js_paths_from_root,
8989 get_wasm_paths_from_root, paths_to_bindings, wasm_paths_to_bindings,
9090 } ,
91- project:: { BaseAndFullModuleGraph , Project } ,
91+ project:: Project ,
9292 route:: {
9393 AppPageRoute , Endpoint , EndpointOutput , EndpointOutputPaths , ModuleGraphs , Route , Routes ,
9494 } ,
@@ -976,14 +976,13 @@ impl AppProject {
976976 }
977977
978978 #[ turbo_tasks:: function]
979- pub async fn app_module_graphs (
979+ pub async fn app_module_graph (
980980 & self ,
981- endpoint : Vc < AppEndpoint > ,
982981 rsc_entry : ResolvedVc < Box < dyn Module > > ,
983982 server_action_loader_module : ResolvedVc < Box < dyn Module > > ,
984983 client_shared_entries : Vc < EvaluatableAssets > ,
985984 has_layout_segments : bool ,
986- ) -> Result < Vc < BaseAndFullModuleGraph > > {
985+ ) -> Result < Vc < ModuleGraph > > {
987986 if * self . project . per_page_module_graph ( ) . await ? {
988987 let next_mode = self . project . next_mode ( ) ;
989988 let next_mode_ref = next_mode. await ?;
@@ -1002,7 +1001,7 @@ impl AppProject {
10021001 ChunkGroupEntry :: Entry ( vec ! [ server_action_loader_module, rsc_entry] ) ;
10031002
10041003 let mut graphs = vec ! [ ] ;
1005- let mut visited_modules = if has_layout_segments {
1004+ let visited_modules = if has_layout_segments {
10061005 let ServerEntries {
10071006 server_utils,
10081007 server_component_entries,
@@ -1075,50 +1074,33 @@ impl AppProject {
10751074 should_read_binding_usage,
10761075 ) ;
10771076 graphs. push ( graph) ;
1078- visited_modules = VisitedModules :: concatenate ( visited_modules, graph) ;
1079-
1080- let base = ModuleGraph :: from_graphs ( graphs. clone ( ) , None ) ;
1081- let additional_entries = endpoint. additional_entries ( base. connect ( ) ) ;
1082- let additional_module_graph = SingleModuleGraph :: new_with_entries_visited_intern (
1083- additional_entries. owned ( ) . await ?,
1084- visited_modules,
1085- should_trace,
1086- should_read_binding_usage,
1087- ) ;
1088- graphs. push ( additional_module_graph) ;
10891077
10901078 let remove_unused_imports = * self
10911079 . project
10921080 . next_config ( )
10931081 . turbopack_remove_unused_imports ( next_mode)
10941082 . await ?;
1083+ let remove_unused_exports = * self
1084+ . project
1085+ . next_config ( )
1086+ . turbopack_remove_unused_exports ( next_mode)
1087+ . await ?;
10951088
1096- let ( full, binding_usage_info) = if remove_unused_imports {
1097- let full_with_unused_references =
1098- ModuleGraph :: from_graphs ( graphs. clone ( ) , None ) ;
1099- let binding_usage_info = compute_binding_usage_info (
1100- full_with_unused_references,
1101- should_read_binding_usage,
1102- ) ;
1103- (
1104- ModuleGraph :: from_graphs ( graphs, Some ( binding_usage_info) ) ,
1105- Some ( binding_usage_info) ,
1106- )
1089+ let graph = if remove_unused_imports || remove_unused_exports {
1090+ let graph = ModuleGraph :: from_graphs ( graphs. clone ( ) , None ) ;
1091+ let binding_usage_info =
1092+ compute_binding_usage_info ( graph, remove_unused_imports) ;
1093+ ModuleGraph :: from_graphs ( graphs, Some ( binding_usage_info) )
11071094 } else {
1108- ( ModuleGraph :: from_graphs ( graphs, None ) , None )
1095+ ModuleGraph :: from_graphs ( graphs, None )
11091096 } ;
11101097
1111- Ok ( BaseAndFullModuleGraph {
1112- base : base. connect ( ) . to_resolved ( ) . await ?,
1113- full : full. connect ( ) . to_resolved ( ) . await ?,
1114- binding_usage_info,
1115- }
1116- . cell ( ) )
1098+ Ok ( graph. connect ( ) )
11171099 }
11181100 . instrument ( tracing:: info_span!( "module graph for endpoint" ) )
11191101 . await
11201102 } else {
1121- Ok ( self . project . whole_app_module_graphs ( ) )
1103+ Ok ( self . project . whole_app_module_graph ( ) )
11221104 }
11231105 }
11241106}
@@ -1382,21 +1364,17 @@ impl AppEndpoint {
13821364
13831365 let server_action_loader = self . server_action_loader_module ( ) ;
13841366
1385- let module_graphs = this
1386- . app_project
1387- . app_module_graphs (
1388- self ,
1389- * rsc_entry,
1390- server_action_loader,
1391- // We only need the client runtime entries for pages not for Route Handlers
1392- if is_app_page {
1393- this. app_project . client_runtime_entries ( )
1394- } else {
1395- EvaluatableAssets :: empty ( )
1396- } ,
1397- is_app_page,
1398- )
1399- . await ?;
1367+ let module_graph = this. app_project . app_module_graph (
1368+ * rsc_entry,
1369+ server_action_loader,
1370+ // We only need the client runtime entries for pages not for Route Handlers
1371+ if is_app_page {
1372+ this. app_project . client_runtime_entries ( )
1373+ } else {
1374+ EvaluatableAssets :: empty ( )
1375+ } ,
1376+ is_app_page,
1377+ ) ;
14001378
14011379 let client_chunking_context = project. client_chunking_context ( ) . to_resolved ( ) . await ?;
14021380
@@ -1422,7 +1400,7 @@ impl AppEndpoint {
14221400 AssetIdent :: from_path ( project. project_path ( ) . owned ( ) . await ?)
14231401 . with_modifier ( rcstr ! ( "client-shared-chunks" ) ) ,
14241402 this. app_project . client_runtime_entries ( ) ,
1425- * module_graphs . full ,
1403+ module_graph ,
14261404 * client_chunking_context,
14271405 ) ;
14281406
@@ -1439,27 +1417,25 @@ impl AppEndpoint {
14391417
14401418 let per_page_module_graph = * project. per_page_module_graph ( ) . await ?;
14411419
1442- let next_dynamic_imports =
1443- NextDynamicGraphs :: new ( * module_graphs. base , per_page_module_graph)
1444- . get_next_dynamic_imports_for_endpoint ( * rsc_entry)
1445- . await ?;
1420+ let next_dynamic_imports = NextDynamicGraphs :: new ( module_graph, per_page_module_graph)
1421+ . get_next_dynamic_imports_for_endpoint ( * rsc_entry)
1422+ . await ?;
14461423
14471424 let is_production = project. next_mode ( ) . await ?. is_production ( ) ;
14481425
1449- let client_references =
1450- ClientReferencesGraphs :: new ( * module_graphs. base , per_page_module_graph)
1451- . get_client_references_for_endpoint (
1452- * rsc_entry,
1453- matches ! ( this. ty, AppEndpointType :: Page { .. } ) ,
1454- is_production,
1455- is_production,
1456- )
1457- . to_resolved ( )
1458- . await ?;
1426+ let client_references = ClientReferencesGraphs :: new ( module_graph, per_page_module_graph)
1427+ . get_client_references_for_endpoint (
1428+ * rsc_entry,
1429+ matches ! ( this. ty, AppEndpointType :: Page { .. } ) ,
1430+ is_production,
1431+ is_production,
1432+ )
1433+ . to_resolved ( )
1434+ . await ?;
14591435
14601436 let client_references_chunks = get_app_client_references_chunks (
14611437 * client_references,
1462- * module_graphs . full ,
1438+ module_graph ,
14631439 * client_chunking_context,
14641440 availability_info,
14651441 ssr_chunking_context. map ( |ctx| * ctx) ,
@@ -1541,7 +1517,7 @@ impl AppEndpoint {
15411517 . await ?
15421518 {
15431519 let webpack_stats = generate_webpack_stats (
1544- * module_graphs . base ,
1520+ module_graph ,
15451521 app_entry. original_name . clone ( ) ,
15461522 client_assets. await ?. into_iter ( ) . copied ( ) ,
15471523 )
@@ -1595,7 +1571,7 @@ impl AppEndpoint {
15951571 node_root. clone ( ) ,
15961572 app_entry. original_name . clone ( ) ,
15971573 runtime,
1598- * module_graphs . full ,
1574+ module_graph ,
15991575 this. app_project
16001576 . project ( )
16011577 . runtime_chunking_context ( process_client_assets, runtime) ,
@@ -1610,7 +1586,7 @@ impl AppEndpoint {
16101586 * client_references,
16111587 server_path. clone ( ) ,
16121588 process_client_assets,
1613- * module_graphs . full ,
1589+ module_graph ,
16141590 )
16151591 . to_resolved ( )
16161592 . await ?;
@@ -1632,7 +1608,7 @@ impl AppEndpoint {
16321608 client_references_chunks,
16331609 client_chunking_context,
16341610 ssr_chunking_context,
1635- async_module_info : module_graphs . full . async_module_info ( ) . to_resolved ( ) . await ?,
1611+ async_module_info : module_graph . async_module_info ( ) . to_resolved ( ) . await ?,
16361612 next_config : project. next_config ( ) . to_resolved ( ) . await ?,
16371613 runtime,
16381614 mode : * project. next_mode ( ) . await ?,
@@ -1715,7 +1691,7 @@ impl AppEndpoint {
17151691
17161692 if emit_manifests == EmitManifests :: Full {
17171693 let dynamic_import_entries = collect_next_dynamic_chunks (
1718- * module_graphs . full ,
1694+ module_graph ,
17191695 * client_chunking_context,
17201696 next_dynamic_imports,
17211697 NextDynamicChunkAvailability :: ClientReferences (
@@ -1831,7 +1807,7 @@ impl AppEndpoint {
18311807 let loadable_manifest_output = if emit_manifests == EmitManifests :: Full {
18321808 // create react-loadable-manifest for next/dynamic
18331809 let dynamic_import_entries = collect_next_dynamic_chunks (
1834- * module_graphs . full ,
1810+ module_graph ,
18351811 * client_chunking_context,
18361812 next_dynamic_imports,
18371813 NextDynamicChunkAvailability :: ClientReferences (
@@ -2203,17 +2179,17 @@ impl Endpoint for AppEndpoint {
22032179 let this = self . await ?;
22042180 let app_entry = self . app_endpoint_entry ( ) . await ?;
22052181 let server_action_loader = self . server_action_loader_module ( ) ;
2206- let module_graphs = this
2182+ let module_graph = this
22072183 . app_project
2208- . app_module_graphs (
2209- self ,
2184+ . app_module_graph (
22102185 * app_entry. rsc_entry ,
22112186 server_action_loader,
22122187 this. app_project . client_runtime_entries ( ) ,
22132188 matches ! ( this. ty, AppEndpointType :: Page { .. } ) ,
22142189 )
2190+ . to_resolved ( )
22152191 . await ?;
2216- Ok ( Vc :: cell ( vec ! [ module_graphs . full ] ) )
2192+ Ok ( Vc :: cell ( vec ! [ module_graph ] ) )
22172193 }
22182194
22192195 #[ turbo_tasks:: function]
0 commit comments