11use std:: { collections:: BTreeSet , str:: FromStr } ;
22
33use anyhow:: Result ;
4+ use serde:: { Deserialize , Serialize } ;
45use turbo_rcstr:: { RcStr , rcstr} ;
5- use turbo_tasks:: { FxIndexMap , ResolvedVc , TryJoinIterExt , ValueToString , Vc } ;
6+ use turbo_tasks:: {
7+ FxIndexMap , ResolvedVc , TaskInput , TryJoinIterExt , ValueToString , Vc , trace:: TraceRawVcs ,
8+ } ;
69use turbo_tasks_env:: EnvMap ;
710use turbo_tasks_fs:: FileSystemPath ;
811use turbopack:: {
@@ -26,6 +29,7 @@ use turbopack_core::{
2629 environment:: { BrowserEnvironment , Environment , ExecutionEnvironment } ,
2730 file_source:: FileSource ,
2831 free_var_references,
32+ module_graph:: export_usage:: OptionExportUsageInfo ,
2933} ;
3034use turbopack_ecmascript:: { TypeofWindow , chunk:: EcmascriptChunkType } ;
3135use turbopack_node:: {
@@ -470,18 +474,37 @@ pub async fn get_client_resolve_options_context(
470474 . cell ( ) )
471475}
472476
477+ #[ derive( Clone , Debug , PartialEq , Eq , Hash , TaskInput , TraceRawVcs , Serialize , Deserialize ) ]
478+ pub struct ClientChunkingContextOptions {
479+ pub mode : Vc < Mode > ,
480+ pub root_path : FileSystemPath ,
481+ pub output_root : FileSystemPath ,
482+ pub output_root_to_root_path : RcStr ,
483+ pub chunk_base_path : Option < RcStr > ,
484+ pub environment : Vc < Environment > ,
485+ pub module_id_strategy : Vc < Box < dyn ModuleIdStrategy > > ,
486+ pub no_mangling : Vc < bool > ,
487+ pub config : Vc < Config > ,
488+ pub export_usage : Vc < OptionExportUsageInfo > ,
489+ }
490+
473491#[ turbo_tasks:: function]
474492pub async fn get_client_chunking_context (
475- root_path : FileSystemPath ,
476- output_root : FileSystemPath ,
477- output_root_to_root_path : RcStr ,
478- chunk_base_path : Option < RcStr > ,
479- environment : ResolvedVc < Environment > ,
480- mode : Vc < Mode > ,
481- module_id_strategy : ResolvedVc < Box < dyn ModuleIdStrategy > > ,
482- no_mangling : Vc < bool > ,
483- config : ResolvedVc < Config > ,
493+ options : ClientChunkingContextOptions ,
484494) -> Result < Vc < Box < dyn ChunkingContext > > > {
495+ let ClientChunkingContextOptions {
496+ mode,
497+ root_path,
498+ output_root,
499+ output_root_to_root_path,
500+ chunk_base_path,
501+ environment,
502+ module_id_strategy,
503+ no_mangling,
504+ config,
505+ export_usage,
506+ } = options;
507+
485508 let minify = config. minify ( mode) ;
486509 let concatenate_modules = config. concatenate_modules ( mode) ;
487510 let mode = mode. await ?;
@@ -509,7 +532,7 @@ pub async fn get_client_chunking_context(
509532 output_root. clone ( ) ,
510533 output_root. clone ( ) ,
511534 output_root,
512- environment,
535+ environment. to_resolved ( ) . await ? ,
513536 runtime_type,
514537 )
515538 . minify_type ( if mode. is_production ( ) && * minify. await ? {
@@ -526,10 +549,13 @@ pub async fn get_client_chunking_context(
526549 } )
527550 . chunk_base_path ( chunk_base_path)
528551 . current_chunk_method ( CurrentChunkMethod :: DocumentCurrentScript )
529- . module_id_strategy ( module_id_strategy) ;
552+ . export_usage ( * export_usage. await ?)
553+ . module_id_strategy ( module_id_strategy. to_resolved ( ) . await ?) ;
530554
531555 let output = config. output ( ) . await ?;
532556
557+ builder = builder. asset_base_path ( output. asset_prefix . clone ( ) ) ;
558+
533559 if !mode. is_development ( ) {
534560 if let Some ( filename) = & output. filename {
535561 builder = builder. filename ( filename. clone ( ) ) ;
0 commit comments