@@ -194,10 +194,10 @@ impl ModuleConcatenationPlugin {
194
194
if cached. runtime == * runtime {
195
195
// runtime is same, use cached value
196
196
* cached_active
197
- } else if cached. runtime . is_subset ( runtime) && * cached_active {
197
+ } else if * cached_active && cached. runtime . is_subset ( runtime) {
198
198
// cached runtime is subset and active, means it is also active in current runtime
199
199
true
200
- } else if cached. runtime . is_superset ( runtime) && ! * cached_active {
200
+ } else if ! * cached_active && cached. runtime . is_superset ( runtime) {
201
201
// cached runtime is superset and inactive, means it is also inactive in current runtime
202
202
false
203
203
} else {
@@ -267,11 +267,9 @@ impl ModuleConcatenationPlugin {
267
267
statistics. cache_hit += 1 ;
268
268
incomings. clone ( )
269
269
} else {
270
- let module = module_graph
271
- . module_by_identifier ( module_id)
272
- . expect ( "should have module" ) ;
273
270
let module_readable_identifier = get_cached_readable_identifier (
274
- module,
271
+ module_id,
272
+ & module_graph,
275
273
& compilation. module_static_cache_artifact ,
276
274
& compilation. options . context ,
277
275
) ;
@@ -324,14 +322,29 @@ impl ModuleConcatenationPlugin {
324
322
return Some ( problem) ;
325
323
}
326
324
327
- let NoRuntimeModuleCache { incomings, .. } = module_cache
325
+ let NoRuntimeModuleCache {
326
+ incomings,
327
+ active_incomings,
328
+ runtime : cached_module_runtime,
329
+ ..
330
+ } = module_cache
328
331
. get ( module_id)
329
332
. expect ( "should have module cache" ) ;
330
333
331
334
if let Some ( incoming_connections_from_non_modules) = incomings. get ( & None ) {
332
- let has_active_non_modules_connections = incoming_connections_from_non_modules
333
- . iter ( )
334
- . any ( |connection| connection. is_active ( & module_graph, runtime, module_graph_cache) ) ;
335
+ let has_active_non_modules_connections =
336
+ incoming_connections_from_non_modules
337
+ . iter ( )
338
+ . any ( |connection| {
339
+ is_connection_active_in_runtime (
340
+ connection,
341
+ runtime,
342
+ active_incomings,
343
+ cached_module_runtime,
344
+ & module_graph,
345
+ module_graph_cache,
346
+ )
347
+ } ) ;
335
348
336
349
// TODO: ADD module connection explanations
337
350
if has_active_non_modules_connections {
@@ -366,23 +379,36 @@ impl ModuleConcatenationPlugin {
366
379
continue ;
367
380
}
368
381
369
- let mut origin_runtime = RuntimeSpec :: default ( ) ;
370
- for r in chunk_graph. get_module_runtimes_iter ( * origin_module, chunk_by_ukey) {
371
- origin_runtime. extend ( r) ;
372
- }
373
-
374
382
let is_intersect = if let Some ( runtime) = runtime {
375
- runtime. intersection ( & origin_runtime) . count ( ) > 0
383
+ if let Some ( origin_runtime) = module_cache. get ( origin_module) . map ( |m| & m. runtime ) {
384
+ runtime. intersection ( origin_runtime) . count ( ) > 0
385
+ } else {
386
+ let mut origin_runtime = RuntimeSpec :: default ( ) ;
387
+ for r in chunk_graph. get_module_runtimes_iter ( * origin_module, chunk_by_ukey) {
388
+ origin_runtime. extend ( r) ;
389
+ }
390
+ runtime. intersection ( & origin_runtime) . count ( ) > 0
391
+ }
376
392
} else {
377
393
false
378
394
} ;
395
+
379
396
if !is_intersect {
380
397
continue ;
381
398
}
382
399
383
400
let active_connections: Vec < _ > = connections
384
401
. iter ( )
385
- . filter ( |& connection| connection. is_active ( & module_graph, runtime, module_graph_cache) )
402
+ . filter ( |& connection| {
403
+ is_connection_active_in_runtime (
404
+ connection,
405
+ runtime,
406
+ active_incomings,
407
+ cached_module_runtime,
408
+ & module_graph,
409
+ module_graph_cache,
410
+ )
411
+ } )
386
412
. collect ( ) ;
387
413
388
414
if !active_connections. is_empty ( ) {
@@ -410,11 +436,9 @@ impl ModuleConcatenationPlugin {
410
436
let mut names: Vec < _ > = other_chunk_modules
411
437
. into_iter ( )
412
438
. map ( |mid| {
413
- let m = module_graph
414
- . module_by_identifier ( mid)
415
- . expect ( "should have module" ) ;
416
439
get_cached_readable_identifier (
417
- m,
440
+ mid,
441
+ & module_graph,
418
442
& compilation. module_static_cache_artifact ,
419
443
& compilation. options . context ,
420
444
)
@@ -454,11 +478,9 @@ impl ModuleConcatenationPlugin {
454
478
let names: Vec < _ > = non_esm_connections
455
479
. iter ( )
456
480
. map ( |( origin_module, connections) | {
457
- let module = module_graph
458
- . module_by_identifier ( origin_module)
459
- . expect ( "should have module" ) ;
460
481
let readable_identifier = get_cached_readable_identifier (
461
- module,
482
+ origin_module,
483
+ & module_graph,
462
484
& compilation. module_static_cache_artifact ,
463
485
& compilation. options . context ,
464
486
) ;
@@ -533,11 +555,9 @@ impl ModuleConcatenationPlugin {
533
555
other_runtime_connections
534
556
. iter( )
535
557
. map( |( origin_module, runtime_condition) | {
536
- let module = module_graph
537
- . module_by_identifier( origin_module)
538
- . expect( "should have module" ) ;
539
558
let readable_identifier = get_cached_readable_identifier(
540
- module,
559
+ origin_module,
560
+ & module_graph,
541
561
& compilation. module_static_cache_artifact,
542
562
& compilation. options. context,
543
563
) ;
@@ -637,7 +657,8 @@ impl ModuleConcatenationPlugin {
637
657
let root_module_ctxt = RootModuleContext {
638
658
id : root_module_id,
639
659
readable_identifier : get_cached_readable_identifier (
640
- box_module,
660
+ & root_module_id,
661
+ & module_graph,
641
662
& compilation. module_static_cache_artifact ,
642
663
& compilation. options . context ,
643
664
) ,
@@ -681,7 +702,8 @@ impl ModuleConcatenationPlugin {
681
702
Some ( compilation) ,
682
703
) ,
683
704
shorten_id : get_cached_readable_identifier (
684
- module,
705
+ id,
706
+ & module_graph,
685
707
& compilation. module_static_cache_artifact ,
686
708
& compilation. options . context ,
687
709
) ,
@@ -1005,8 +1027,12 @@ impl ModuleConcatenationPlugin {
1005
1027
runtime. extend ( r) ;
1006
1028
}
1007
1029
1008
- let _ =
1009
- get_cached_readable_identifier ( module, module_static_cache_artifact, compilation_context) ;
1030
+ let _ = get_cached_readable_identifier (
1031
+ module_id,
1032
+ & module_graph,
1033
+ module_static_cache_artifact,
1034
+ compilation_context,
1035
+ ) ;
1010
1036
1011
1037
let connections = module
1012
1038
. get_dependencies ( )
@@ -1035,13 +1061,21 @@ impl ModuleConcatenationPlugin {
1035
1061
. collect :: < Vec < _ > > ( ) ;
1036
1062
1037
1063
let incomings = module_graph. get_incoming_connections_by_origin_module ( module_id) ;
1064
+ let mut active_incomings = HashMap :: default ( ) ;
1065
+ for connection in incomings. values ( ) . flatten ( ) {
1066
+ active_incomings. insert (
1067
+ connection. dependency_id ,
1068
+ connection. is_active ( & module_graph, Some ( & runtime) , module_graph_cache) ,
1069
+ ) ;
1070
+ }
1038
1071
(
1039
1072
* module_id,
1040
1073
NoRuntimeModuleCache {
1041
1074
runtime,
1042
1075
provided_names,
1043
1076
connections,
1044
1077
incomings,
1078
+ active_incomings,
1045
1079
} ,
1046
1080
)
1047
1081
} )
@@ -1344,6 +1378,7 @@ pub struct NoRuntimeModuleCache {
1344
1378
provided_names : bool ,
1345
1379
connections : Vec < ( ModuleGraphConnection , ( bool , bool ) ) > ,
1346
1380
incomings : HashMap < Option < ModuleIdentifier > , Vec < ModuleGraphConnection > > ,
1381
+ active_incomings : HashMap < DependencyId , bool > ,
1347
1382
}
1348
1383
1349
1384
async fn create_concatenated_module (
@@ -1361,7 +1396,8 @@ async fn create_concatenated_module(
1361
1396
let root_module_ctxt = RootModuleContext {
1362
1397
id : root_module_id,
1363
1398
readable_identifier : get_cached_readable_identifier (
1364
- box_module,
1399
+ & root_module_id,
1400
+ & module_graph,
1365
1401
& compilation. module_static_cache_artifact ,
1366
1402
& compilation. options . context ,
1367
1403
) ,
@@ -1405,7 +1441,8 @@ async fn create_concatenated_module(
1405
1441
Some ( compilation) ,
1406
1442
) ,
1407
1443
shorten_id : get_cached_readable_identifier (
1408
- module,
1444
+ id,
1445
+ & module_graph,
1409
1446
& compilation. module_static_cache_artifact ,
1410
1447
& compilation. options . context ,
1411
1448
) ,
@@ -1665,3 +1702,31 @@ fn add_concatenated_module(
1665
1702
module_graph. add_module ( new_module. boxed ( ) ) ;
1666
1703
compilation. chunk_graph = chunk_graph;
1667
1704
}
1705
+
1706
+ fn is_connection_active_in_runtime (
1707
+ connection : & ModuleGraphConnection ,
1708
+ runtime : Option < & RuntimeSpec > ,
1709
+ cached_active_incomings : & HashMap < DependencyId , bool > ,
1710
+ cached_runtime : & RuntimeSpec ,
1711
+ mg : & ModuleGraph ,
1712
+ mg_cache : & ModuleGraphCacheArtifact ,
1713
+ ) -> bool {
1714
+ if let ( Some ( cached_active) , Some ( runtime) ) = (
1715
+ cached_active_incomings. get ( & connection. dependency_id ) ,
1716
+ runtime,
1717
+ ) {
1718
+ if runtime == cached_runtime {
1719
+ return * cached_active;
1720
+ }
1721
+
1722
+ if * cached_active && cached_runtime. is_subset ( runtime) {
1723
+ return true ;
1724
+ }
1725
+
1726
+ if !* cached_active && cached_runtime. is_superset ( runtime) {
1727
+ return false ;
1728
+ }
1729
+ }
1730
+
1731
+ connection. is_active ( mg, runtime, mg_cache)
1732
+ }
0 commit comments