@@ -129,10 +129,29 @@ pub struct ExternalModule {
129
129
factory_meta : Option < FactoryMeta > ,
130
130
build_info : Option < BuildInfo > ,
131
131
build_meta : Option < BuildMeta > ,
132
+ dependency_meta : DependencyMeta ,
133
+ }
134
+
135
+ #[ derive( Debug ) ]
136
+ pub enum ExternalTypeEnum {
137
+ Import ,
138
+ Module ,
139
+ }
140
+
141
+ pub type MetaExternalType = Option < ExternalTypeEnum > ;
142
+
143
+ #[ derive( Debug ) ]
144
+ pub struct DependencyMeta {
145
+ pub external_type : MetaExternalType ,
132
146
}
133
147
134
148
impl ExternalModule {
135
- pub fn new ( request : ExternalRequest , external_type : ExternalType , user_request : String ) -> Self {
149
+ pub fn new (
150
+ request : ExternalRequest ,
151
+ external_type : ExternalType ,
152
+ user_request : String ,
153
+ dependency_meta : DependencyMeta ,
154
+ ) -> Self {
136
155
Self {
137
156
dependencies : Vec :: new ( ) ,
138
157
blocks : Vec :: new ( ) ,
@@ -147,6 +166,7 @@ impl ExternalModule {
147
166
build_info : None ,
148
167
build_meta : None ,
149
168
source_map_kind : SourceMapKind :: empty ( ) ,
169
+ dependency_meta,
150
170
}
151
171
}
152
172
@@ -170,6 +190,7 @@ impl ExternalModule {
170
190
) -> Result < ( BoxSource , ChunkInitFragments , RuntimeGlobals ) > {
171
191
let mut chunk_init_fragments: ChunkInitFragments = Default :: default ( ) ;
172
192
let mut runtime_requirements: RuntimeGlobals = Default :: default ( ) ;
193
+
173
194
let source = match self . external_type . as_str ( ) {
174
195
"this" if let Some ( request) = request => format ! (
175
196
"{} = (function() {{ return {}; }}());" ,
@@ -234,52 +255,62 @@ impl ExternalModule {
234
255
to_identifier( id)
235
256
)
236
257
}
237
- "import" if let Some ( request) = request => format ! (
238
- "{} = {};" ,
239
- get_namespace_object_export( concatenation_scope) ,
240
- get_source_for_import( request, compilation)
241
- ) ,
258
+ "module" | "import" | "module-import" if let Some ( request) = request => {
259
+ match self . get_module_import_type ( external_type) {
260
+ "import" => {
261
+ format ! (
262
+ "{} = {};" ,
263
+ get_namespace_object_export( concatenation_scope) ,
264
+ get_source_for_import( request, compilation)
265
+ )
266
+ }
267
+ "module" => {
268
+ if compilation. options . output . module {
269
+ let id = to_identifier ( & request. primary ) ;
270
+ chunk_init_fragments. push (
271
+ NormalInitFragment :: new (
272
+ format ! (
273
+ "import * as __WEBPACK_EXTERNAL_MODULE_{}__ from {};\n " ,
274
+ id. clone( ) ,
275
+ json_stringify( request. primary( ) )
276
+ ) ,
277
+ InitFragmentStage :: StageHarmonyImports ,
278
+ 0 ,
279
+ InitFragmentKey :: ExternalModule ( request. primary ( ) . into ( ) ) ,
280
+ None ,
281
+ )
282
+ . boxed ( ) ,
283
+ ) ;
284
+ runtime_requirements. insert ( RuntimeGlobals :: DEFINE_PROPERTY_GETTERS ) ;
285
+ format ! (
286
+ r#"
287
+ var x = y => {{ var x = {{}}; {}(x, y); return x; }}
288
+ var y = x => () => x
289
+ {} = __WEBPACK_EXTERNAL_MODULE_{}__;
290
+ "# ,
291
+ RuntimeGlobals :: DEFINE_PROPERTY_GETTERS ,
292
+ get_namespace_object_export( concatenation_scope) ,
293
+ id. clone( )
294
+ )
295
+ } else {
296
+ format ! (
297
+ "{} = {};" ,
298
+ get_namespace_object_export( concatenation_scope) ,
299
+ get_source_for_import( request, compilation)
300
+ )
301
+ }
302
+ }
303
+ r#type => panic ! (
304
+ "Unhandled external type: {} in \" module-import\" type" ,
305
+ r#type
306
+ ) ,
307
+ }
308
+ }
242
309
"var" | "promise" | "const" | "let" | "assign" if let Some ( request) = request => format ! (
243
310
"{} = {};" ,
244
311
get_namespace_object_export( concatenation_scope) ,
245
312
get_source_for_default_case( false , request)
246
313
) ,
247
- "module" if let Some ( request) = request => {
248
- if compilation. options . output . module {
249
- let id = to_identifier ( & request. primary ) ;
250
- chunk_init_fragments. push (
251
- NormalInitFragment :: new (
252
- format ! (
253
- "import * as __WEBPACK_EXTERNAL_MODULE_{}__ from {};\n " ,
254
- id. clone( ) ,
255
- json_stringify( request. primary( ) )
256
- ) ,
257
- InitFragmentStage :: StageHarmonyImports ,
258
- 0 ,
259
- InitFragmentKey :: ExternalModule ( request. primary ( ) . into ( ) ) ,
260
- None ,
261
- )
262
- . boxed ( ) ,
263
- ) ;
264
- runtime_requirements. insert ( RuntimeGlobals :: DEFINE_PROPERTY_GETTERS ) ;
265
- format ! (
266
- r#"
267
- var x = y => {{ var x = {{}}; {}(x, y); return x; }}
268
- var y = x => () => x
269
- {} = __WEBPACK_EXTERNAL_MODULE_{}__;
270
- "# ,
271
- RuntimeGlobals :: DEFINE_PROPERTY_GETTERS ,
272
- get_namespace_object_export( concatenation_scope) ,
273
- id. clone( )
274
- )
275
- } else {
276
- format ! (
277
- "{} = {};" ,
278
- get_namespace_object_export( concatenation_scope) ,
279
- get_source_for_import( request, compilation)
280
- )
281
- }
282
- }
283
314
"script" if let Some ( request) = request => {
284
315
let url_and_global = extract_url_and_global ( request. primary ( ) ) ?;
285
316
runtime_requirements. insert ( RuntimeGlobals :: LOAD_SCRIPT ) ;
@@ -316,6 +347,24 @@ if(typeof {global} !== "undefined") return resolve();
316
347
runtime_requirements,
317
348
) )
318
349
}
350
+
351
+ fn get_module_import_type < ' a > ( & self , external_type : & ' a ExternalType ) -> & ' a str {
352
+ match external_type. as_str ( ) {
353
+ "module-import" => {
354
+ let external_type = self
355
+ . dependency_meta
356
+ . external_type
357
+ . as_ref ( )
358
+ . expect ( "should get \" module\" or \" import\" external type from dependency" ) ;
359
+
360
+ match external_type {
361
+ ExternalTypeEnum :: Import => "import" ,
362
+ ExternalTypeEnum :: Module => "module" ,
363
+ }
364
+ }
365
+ import_or_module => import_or_module,
366
+ }
367
+ }
319
368
}
320
369
321
370
impl Identifiable for ExternalModule {
@@ -412,6 +461,7 @@ impl Module for ExternalModule {
412
461
) -> Result < BuildResult > {
413
462
let mut hasher = RspackHash :: from ( & build_context. compiler_options . output ) ;
414
463
self . update_hash ( & mut hasher) ;
464
+ let ( _, external_type) = self . get_request_and_external_type ( ) ;
415
465
416
466
let build_info = BuildInfo {
417
467
hash : Some ( hasher. digest ( & build_context. compiler_options . output . hash_digest ) ) ,
@@ -431,12 +481,18 @@ impl Module for ExternalModule {
431
481
match self . external_type . as_str ( ) {
432
482
"this" => build_result. build_info . strict = false ,
433
483
"system" => build_result. build_meta . exports_type = BuildMetaExportsType :: Namespace ,
434
- "module" => build_result. build_meta . exports_type = BuildMetaExportsType :: Namespace ,
435
484
"script" | "promise" => build_result. build_meta . has_top_level_await = true ,
436
- "import" => {
437
- build_result. build_meta . has_top_level_await = true ;
438
- build_result. build_meta . exports_type = BuildMetaExportsType :: Namespace ;
439
- }
485
+ "module" | "import" | "module-import" => match self . get_module_import_type ( external_type) {
486
+ "module" => build_result. build_meta . exports_type = BuildMetaExportsType :: Namespace ,
487
+ "import" => {
488
+ build_result. build_meta . has_top_level_await = true ;
489
+ build_result. build_meta . exports_type = BuildMetaExportsType :: Namespace ;
490
+ }
491
+ r#type => panic ! (
492
+ "Unhandled external type: {} in \" module-import\" type" ,
493
+ r#type
494
+ ) ,
495
+ } ,
440
496
_ => build_result. build_meta . exports_type = BuildMetaExportsType :: Dynamic ,
441
497
}
442
498
build_result
0 commit comments