@@ -4,9 +4,9 @@ use rspack_collections::IdentifierMap;
44use rspack_core:: {
55 BoxDependency , ChunkUkey , CodeGenerationExportsFinalNames , Compilation ,
66 CompilationOptimizeChunkModules , CompilationParams , CompilerCompilation , CompilerFinishMake ,
7- ConcatenatedModule , ConcatenatedModuleExportsDefinitions , DependenciesBlock , Dependency ,
8- DependencyId , ExportsType , LibraryOptions , ModuleDependency , ModuleGraph , ModuleIdentifier ,
9- Plugin , PrefetchExportsInfoMode , RuntimeSpec , UsedNameItem ,
7+ ConcatenatedModule , ConcatenatedModuleExportsDefinitions , DependencyId , ExportsType ,
8+ LibraryOptions , ModuleGraph , ModuleIdentifier , Plugin , PrefetchExportsInfoMode , RuntimeSpec ,
9+ UsedNameItem ,
1010 rspack_sources:: { ConcatSource , RawStringSource , SourceExt } ,
1111 to_identifier,
1212} ;
@@ -16,82 +16,18 @@ use rspack_hook::{plugin, plugin_hook};
1616use rspack_plugin_javascript:: {
1717 ConcatConfiguration , JavascriptModulesChunkHash , JavascriptModulesRenderStartup , JsPlugin ,
1818 ModuleConcatenationPlugin , RenderSource ,
19- dependency:: {
20- ESMExportImportedSpecifierDependency , ESMImportSideEffectDependency , ImportDependency ,
21- } ,
19+ dependency:: { ESMExportImportedSpecifierDependency , ESMImportSideEffectDependency } ,
2220} ;
2321use rustc_hash:: FxHashSet as HashSet ;
2422
2523use super :: modern_module:: ModernModuleReexportStarExternalDependency ;
2624use crate :: {
27- modern_module:: {
28- ModernModuleImportDependency , ModernModuleImportDependencyTemplate ,
29- ModernModuleReexportStarExternalDependencyTemplate ,
30- } ,
25+ modern_module:: ModernModuleReexportStarExternalDependencyTemplate ,
3126 utils:: { COMMON_LIBRARY_NAME_MESSAGE , get_options_for_chunk} ,
3227} ;
3328
3429const PLUGIN_NAME : & str = "rspack.ModernModuleLibraryPlugin" ;
3530
36- /// Replaces ImportDependency instances with ModernModuleImportDependency for external modules.
37- /// This function iterates through all modules and their blocks to find ImportDependencies
38- /// that point to external modules, then creates ModernModuleImportDependency replacements.
39- pub fn replace_import_dependencies_for_external_modules (
40- compilation : & mut Compilation ,
41- ) -> Result < ( ) > {
42- let mg = compilation. get_module_graph ( ) ;
43- let mut deps_to_replace: Vec < BoxDependency > = Vec :: new ( ) ;
44-
45- for module in mg. modules ( ) . values ( ) {
46- for block_id in module. get_blocks ( ) {
47- let Some ( block) = mg. block_by_id ( block_id) else {
48- continue ;
49- } ;
50- for block_dep_id in block. get_dependencies ( ) {
51- let block_dep = mg. dependency_by_id ( block_dep_id) ;
52- if let Some ( block_dep) = block_dep
53- && let Some ( import_dependency) = block_dep. as_any ( ) . downcast_ref :: < ImportDependency > ( )
54- {
55- let import_dep_connection = mg. connection_by_dependency_id ( block_dep_id) ;
56- if let Some ( import_dep_connection) = import_dep_connection {
57- // Try find the connection with a import dependency pointing to an external module.
58- // If found, remove the connection and add a new import dependency to performs the external module ID replacement.
59- let import_module_id = import_dep_connection. module_identifier ( ) ;
60- let Some ( import_module) = mg. module_by_identifier ( import_module_id) else {
61- continue ;
62- } ;
63-
64- if let Some ( external_module) = import_module. as_external_module ( ) {
65- let new_dep = ModernModuleImportDependency :: new (
66- * block_dep. id ( ) ,
67- import_dependency. request ( ) . into ( ) ,
68- external_module. request . clone ( ) ,
69- external_module. external_type . clone ( ) ,
70- import_dependency. range ,
71- import_dependency. get_attributes ( ) . cloned ( ) ,
72- import_dependency. comments . clone ( ) ,
73- ) ;
74-
75- deps_to_replace. push ( Box :: new ( new_dep) ) ;
76- }
77- }
78- }
79- }
80- }
81- }
82-
83- let mut mg = compilation. get_module_graph_mut ( ) ;
84- for dep in deps_to_replace {
85- let dep_id = dep. id ( ) ;
86- // remove connection
87- mg. revoke_dependency ( dep_id, false ) ;
88- // overwrite dependency
89- mg. add_dependency ( dep) ;
90- }
91-
92- Ok ( ( ) )
93- }
94-
9531#[ plugin]
9632#[ derive( Debug , Default ) ]
9733pub struct ModernModuleLibraryPlugin ;
@@ -489,8 +425,6 @@ pub fn render_as_default_export_impl(exports: &[(String, Option<String>)]) -> St
489425
490426#[ plugin_hook( CompilerFinishMake for ModernModuleLibraryPlugin ) ]
491427async fn finish_make ( & self , compilation : & mut Compilation ) -> Result < ( ) > {
492- // Replace ImportDependency instances with ModernModuleImportDependency for external modules
493- replace_import_dependencies_for_external_modules ( compilation) ?;
494428 self . preserve_reexports_star ( compilation) ?;
495429
496430 Ok ( ( ) )
@@ -527,10 +461,6 @@ async fn compilation(
527461 hooks. render_startup . tap ( render_startup:: new ( self ) ) ;
528462 hooks. chunk_hash . tap ( js_chunk_hash:: new ( self ) ) ;
529463
530- compilation. set_dependency_template (
531- ModernModuleImportDependencyTemplate :: template_type ( ) ,
532- Arc :: new ( ModernModuleImportDependencyTemplate :: default ( ) ) ,
533- ) ;
534464 compilation. set_dependency_template (
535465 ModernModuleReexportStarExternalDependencyTemplate :: template_type ( ) ,
536466 Arc :: new ( ModernModuleReexportStarExternalDependencyTemplate :: default ( ) ) ,
0 commit comments