@@ -11,14 +11,16 @@ use turbopack_core::{
1111} ;
1212use turbopack_ecmascript:: utils:: StringifyJs ;
1313
14- use crate :: { RuntimeType , asset_context:: get_runtime_asset_context, embed_js:: embed_static_code} ;
14+ use crate :: {
15+ ChunkSuffix , RuntimeType , asset_context:: get_runtime_asset_context, embed_js:: embed_static_code,
16+ } ;
1517
1618/// Returns the code for the ECMAScript runtime.
1719#[ turbo_tasks:: function]
1820pub async fn get_browser_runtime_code (
1921 environment : ResolvedVc < Environment > ,
2022 chunk_base_path : Vc < Option < RcStr > > ,
21- chunk_suffix_path : Vc < Option < RcStr > > ,
23+ chunk_suffix : Vc < ChunkSuffix > ,
2224 runtime_type : RuntimeType ,
2325 output_root_to_root_path : RcStr ,
2426 generate_source_map : bool ,
@@ -80,10 +82,7 @@ pub async fn get_browser_runtime_code(
8082 let relative_root_path = output_root_to_root_path;
8183 let chunk_base_path = chunk_base_path. await ?;
8284 let chunk_base_path = chunk_base_path. as_ref ( ) . map_or_else ( || "" , |f| f. as_str ( ) ) ;
83- let chunk_suffix_path = chunk_suffix_path. await ?;
84- let chunk_suffix_path = chunk_suffix_path
85- . as_ref ( )
86- . map_or_else ( || "" , |f| f. as_str ( ) ) ;
85+ let chunk_suffix = chunk_suffix. await ?;
8786
8887 writedoc ! (
8988 code,
@@ -94,16 +93,42 @@ pub async fn get_browser_runtime_code(
9493 }}
9594
9695 const CHUNK_BASE_PATH = {};
97- const CHUNK_SUFFIX_PATH = {};
9896 const RELATIVE_ROOT_PATH = {};
9997 const RUNTIME_PUBLIC_PATH = {};
10098 "# ,
10199 StringifyJs ( chunk_base_path) ,
102- StringifyJs ( chunk_suffix_path) ,
103100 StringifyJs ( relative_root_path. as_str( ) ) ,
104101 StringifyJs ( chunk_base_path) ,
105102 ) ?;
106103
104+ match & * chunk_suffix {
105+ ChunkSuffix :: None => {
106+ writedoc ! (
107+ code,
108+ r#"
109+ const CHUNK_SUFFIX_PATH = "";
110+ "#
111+ ) ?;
112+ }
113+ ChunkSuffix :: Constant ( suffix) => {
114+ writedoc ! (
115+ code,
116+ r#"
117+ const CHUNK_SUFFIX_PATH = {};
118+ "# ,
119+ StringifyJs ( suffix. as_str( ) )
120+ ) ?;
121+ }
122+ ChunkSuffix :: FromScriptSrc => {
123+ writedoc ! (
124+ code,
125+ r#"
126+ const CHUNK_SUFFIX_PATH = document?.currentScript?.getAttribute?.('src')?.replace(/^(.*(?=\?)|^.*$)/, "") || "";
127+ "#
128+ ) ?;
129+ }
130+ }
131+
107132 code. push_code ( & * shared_runtime_utils_code. await ?) ;
108133 for runtime_code in runtime_base_code {
109134 code. push_code (
0 commit comments