From bfb5f769cf275e6620540475e3118b50e885a6ed Mon Sep 17 00:00:00 2001 From: jerrykingxyz Date: Fri, 11 Oct 2024 15:06:35 +0800 Subject: [PATCH] refactor: remove connection id --- .../src/build_chunk_graph/code_splitter.rs | 52 +-- .../src/chunk_graph/chunk_graph_chunk.rs | 2 +- .../src/chunk_graph/chunk_graph_module.rs | 2 +- .../src/compiler/make/cutout/fix_issuers.rs | 2 +- .../make/cutout/has_module_graph_change.rs | 2 +- .../src/compiler/make/cutout/mod.rs | 5 +- .../src/compiler/make/repair/add.rs | 2 +- .../src/compiler/module_executor/ctrl.rs | 4 +- crates/rspack_core/src/concatenated_module.rs | 22 +- crates/rspack_core/src/exports_info.rs | 41 +- .../src/module_graph/connection.rs | 81 ++-- crates/rspack_core/src/module_graph/mod.rs | 416 ++++++------------ crates/rspack_core/src/module_graph/module.rs | 41 +- crates/rspack_core/src/normal_module.rs | 10 +- crates/rspack_core/src/stats/mod.rs | 8 +- .../rspack_core/src/unaffected_cache/mod.rs | 11 +- .../common_js_export_require_dependency.rs | 4 +- ...ny_export_imported_specifier_dependency.rs | 14 +- .../esm/harmony_import_dependency.rs | 5 +- .../harmony_import_specifier_dependency.rs | 4 +- .../src/dependency/esm/provide_dependency.rs | 2 +- .../src/dependency/is_included_dependency.rs | 2 +- .../plugin/flag_dependency_usage_plugin.rs | 4 +- .../src/plugin/module_concatenation_plugin.rs | 16 +- .../src/plugin/side_effects_flag_plugin.rs | 59 ++- .../src/modern_module_library_plugin.rs | 13 +- .../StatsTestCases.basictest.js.snap | 13 - 27 files changed, 292 insertions(+), 545 deletions(-) diff --git a/crates/rspack_core/src/build_chunk_graph/code_splitter.rs b/crates/rspack_core/src/build_chunk_graph/code_splitter.rs index c9728aac33b..da2551265fd 100644 --- a/crates/rspack_core/src/build_chunk_graph/code_splitter.rs +++ b/crates/rspack_core/src/build_chunk_graph/code_splitter.rs @@ -16,11 +16,11 @@ use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet, FxHasher}; use crate::dependencies_block::AsyncDependenciesToInitialChunkError; use crate::{ - add_connection_states, assign_depth, assign_depths, get_entry_runtime, merge_runtime, - AsyncDependenciesBlockIdentifier, ChunkGroup, ChunkGroupKind, ChunkGroupOptions, ChunkGroupUkey, - ChunkLoading, ChunkUkey, Compilation, ConnectionId, ConnectionState, DependenciesBlock, - DependencyLocation, EntryDependency, EntryRuntime, GroupOptions, Logger, ModuleDependency, - ModuleGraph, ModuleIdentifier, RuntimeSpec, SyntheticDependencyLocation, + assign_depth, assign_depths, get_entry_runtime, merge_runtime, AsyncDependenciesBlockIdentifier, + ChunkGroup, ChunkGroupKind, ChunkGroupOptions, ChunkGroupUkey, ChunkLoading, ChunkUkey, + Compilation, ConnectionState, DependenciesBlock, DependencyId, DependencyLocation, + EntryDependency, EntryRuntime, GroupOptions, Logger, ModuleDependency, ModuleGraph, + ModuleIdentifier, RuntimeSpec, SyntheticDependencyLocation, }; type IndexMap = RawIndexMap>; @@ -39,7 +39,7 @@ pub struct ChunkGroupInfo { pub available_modules_to_be_merged: Vec, pub skipped_items: IdentifierIndexSet, - pub skipped_module_connections: IndexSet<(ModuleIdentifier, Vec)>, + pub skipped_module_connections: IndexSet<(ModuleIdentifier, Vec)>, // set of children chunk groups, that will be revisited when available_modules shrink pub children: UkeyIndexSet, // set of chunk groups that are the source for min_available_modules @@ -152,7 +152,7 @@ type BlockModulesRuntimeMap = IndexMap< OptionalRuntimeSpec, IndexMap< DependenciesBlockIdentifier, - Vec<(ModuleIdentifier, ConnectionState, Vec)>, + Vec<(ModuleIdentifier, ConnectionState, Vec)>, >, >; @@ -278,24 +278,24 @@ fn add_chunk_in_group( } fn get_active_state_of_connections( - connections: &[ConnectionId], + connections: &[DependencyId], runtime: Option<&RuntimeSpec>, module_graph: &ModuleGraph, ) -> ConnectionState { let mut iter = connections.iter(); let id = iter.next().expect("should have connection"); let mut merged = module_graph - .connection_by_connection_id(id) + .connection_by_dependency_id(id) .expect("should have connection") - .get_active_state(module_graph, runtime); + .active_state(module_graph, runtime); if merged.is_true() { return merged; } for c in iter { let c = module_graph - .connection_by_connection_id(c) + .connection_by_dependency_id(c) .expect("should have connection"); - merged = add_connection_states(merged, c.get_active_state(module_graph, runtime)); + merged = merged + c.active_state(module_graph, runtime); if merged.is_true() { return merged; } @@ -1467,7 +1467,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on &mut self, module: DependenciesBlockIdentifier, runtime: Option<&RuntimeSpec>, - ) -> Vec<(ModuleIdentifier, ConnectionState, Vec)> { + ) -> Vec<(ModuleIdentifier, ConnectionState, Vec)> { if let Some(modules) = self .block_modules_runtime_map .get::(&runtime.cloned().into()) @@ -1500,34 +1500,24 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on let sorted_connections = module_graph .get_ordered_connections(&module) - .expect("should have module") - .into_iter() - .map(|conn_id| { - let conn = module_graph - .connection_by_connection_id(conn_id) - .expect("should have connection"); - - let dep = module_graph - .dependency_by_id(&conn.dependency_id) - .expect("should have dependency"); - - (dep, conn_id) - }); + .expect("should have module"); // keep the dependency order sorted by span let mut connection_map: IndexMap< (DependenciesBlockIdentifier, ModuleIdentifier), - Vec, + Vec, > = IndexMap::default(); - for (dep, connection_id) in sorted_connections { + for dep_id in sorted_connections { + let dep = module_graph + .dependency_by_id(dep_id) + .expect("should have dep"); if dep.as_module_dependency().is_none() && dep.as_context_dependency().is_none() { continue; } if matches!(dep.as_module_dependency().map(|d| d.weak()), Some(true)) { continue; } - let dep_id = dep.id(); // Dependency created but no module is available. // This could happen when module factorization is failed, but `options.bail` set to `false` let module_graph = self.compilation.get_module_graph(); @@ -1542,8 +1532,8 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on }; connection_map .entry((block_id, *module_identifier)) - .and_modify(|e| e.push(*connection_id)) - .or_insert_with(|| vec![*connection_id]); + .and_modify(|e| e.push(*dep_id)) + .or_insert_with(|| vec![*dep_id]); } for ((block_id, module_identifier), connections) in connection_map { diff --git a/crates/rspack_core/src/chunk_graph/chunk_graph_chunk.rs b/crates/rspack_core/src/chunk_graph/chunk_graph_chunk.rs index b71f1d2df39..4ebf68e0a5a 100644 --- a/crates/rspack_core/src/chunk_graph/chunk_graph_chunk.rs +++ b/crates/rspack_core/src/chunk_graph/chunk_graph_chunk.rs @@ -515,7 +515,7 @@ impl ChunkGraph { ) { for connection in module_graph.get_outgoing_connections(&module) { // https://github.com/webpack/webpack/blob/1f99ad6367f2b8a6ef17cce0e058f7a67fb7db18/lib/ChunkGraph.js#L290 - let active_state = connection.get_active_state(module_graph, None); + let active_state = connection.active_state(module_graph, None); match active_state { crate::ConnectionState::Bool(false) => { continue; diff --git a/crates/rspack_core/src/chunk_graph/chunk_graph_module.rs b/crates/rspack_core/src/chunk_graph/chunk_graph_module.rs index 650571d0808..6a81b6e2bff 100644 --- a/crates/rspack_core/src/chunk_graph/chunk_graph_module.rs +++ b/crates/rspack_core/src/chunk_graph/chunk_graph_module.rs @@ -192,7 +192,7 @@ impl ChunkGraph { if visited_modules.contains(module_identifier) { continue; } - if connection.get_active_state(&mg, runtime).is_false() { + if connection.active_state(&mg, runtime).is_false() { continue; } visited_modules.insert(*module_identifier); diff --git a/crates/rspack_core/src/compiler/make/cutout/fix_issuers.rs b/crates/rspack_core/src/compiler/make/cutout/fix_issuers.rs index 9dab42c52d6..7a7cb2d6e7c 100644 --- a/crates/rspack_core/src/compiler/make/cutout/fix_issuers.rs +++ b/crates/rspack_core/src/compiler/make/cutout/fix_issuers.rs @@ -20,7 +20,7 @@ impl FixIssuers { .expect("should have module graph module"); self .origin_module_issuers - .insert(*module_identifier, mgm.get_issuer().clone()); + .insert(*module_identifier, mgm.issuer().clone()); } pub fn fix_artifact(self, artifact: &mut MakeArtifact) { diff --git a/crates/rspack_core/src/compiler/make/cutout/has_module_graph_change.rs b/crates/rspack_core/src/compiler/make/cutout/has_module_graph_change.rs index be57185cafe..463971b1577 100644 --- a/crates/rspack_core/src/compiler/make/cutout/has_module_graph_change.rs +++ b/crates/rspack_core/src/compiler/make/cutout/has_module_graph_change.rs @@ -28,7 +28,7 @@ impl ModuleDeps { .dependency_by_id(dep_id) .expect("should have dependency"); - let Some(conn) = module_graph.connection_by_dependency(dep_id) else { + let Some(conn) = module_graph.connection_by_dependency_id(dep_id) else { continue; }; let identifier = conn.module_identifier(); diff --git a/crates/rspack_core/src/compiler/make/cutout/mod.rs b/crates/rspack_core/src/compiler/make/cutout/mod.rs index cb0d3d05ff1..0bc1070eceb 100644 --- a/crates/rspack_core/src/compiler/make/cutout/mod.rs +++ b/crates/rspack_core/src/compiler/make/cutout/mod.rs @@ -132,12 +132,11 @@ impl Cutout { let mut module_graph = artifact.get_module_graph_mut(); for dep_id in remove_entry_deps { // connection may have been deleted by revoke module - if let Some(con) = module_graph.connection_by_dependency(&dep_id) { + if let Some(con) = module_graph.connection_by_dependency_id(&dep_id) { self .clean_isolated_module .add_need_check_module(*con.module_identifier()); - let con_id = con.id; - module_graph.revoke_connection(&con_id, true); + module_graph.revoke_connection(&dep_id, true); } force_build_deps.remove(&(dep_id, None)); } diff --git a/crates/rspack_core/src/compiler/make/repair/add.rs b/crates/rspack_core/src/compiler/make/repair/add.rs index 8d98c3af939..530ffd83a76 100644 --- a/crates/rspack_core/src/compiler/make/repair/add.rs +++ b/crates/rspack_core/src/compiler/make/repair/add.rs @@ -29,7 +29,7 @@ impl Task for AddTask { if self.module.as_self_module().is_some() { let issuer = self .module_graph_module - .get_issuer() + .issuer() .identifier() .expect("self module should have issuer"); diff --git a/crates/rspack_core/src/compiler/module_executor/ctrl.rs b/crates/rspack_core/src/compiler/module_executor/ctrl.rs index 65ad175eb62..d52fd8fd61e 100644 --- a/crates/rspack_core/src/compiler/module_executor/ctrl.rs +++ b/crates/rspack_core/src/compiler/module_executor/ctrl.rs @@ -259,9 +259,9 @@ impl Task for FinishModuleTask { .expect("should have mgm"); let mut original_module_identifiers = HashSet::default(); - for connection_id in mgm.incoming_connections() { + for dep_id in mgm.incoming_connections() { let connection = module_graph - .connection_by_connection_id(connection_id) + .connection_by_dependency_id(dep_id) .expect("should have connection"); if let Some(original_module_identifier) = &connection.original_module_identifier { // skip self reference diff --git a/crates/rspack_core/src/concatenated_module.rs b/crates/rspack_core/src/concatenated_module.rs index 942f1307705..3f754c118a3 100644 --- a/crates/rspack_core/src/concatenated_module.rs +++ b/crates/rspack_core/src/concatenated_module.rs @@ -39,13 +39,12 @@ use crate::{ subtract_runtime_condition, to_identifier, AsyncDependenciesBlockIdentifier, BoxDependency, BuildContext, BuildInfo, BuildMeta, BuildMetaDefaultObject, BuildMetaExportsType, BuildResult, ChunkInitFragments, CodeGenerationDataTopLevelDeclarations, CodeGenerationExportsFinalNames, - CodeGenerationResult, Compilation, ConcatenatedModuleIdent, ConcatenationScope, ConnectionId, - ConnectionState, Context, DependenciesBlock, DependencyId, DependencyTemplate, DependencyType, - ErrorSpan, ExportInfo, ExportInfoProvided, ExportsArgument, ExportsType, FactoryMeta, - IdentCollector, LibIdentOptions, Module, ModuleDependency, ModuleGraph, ModuleGraphConnection, - ModuleIdentifier, ModuleLayer, ModuleType, Resolve, RuntimeCondition, RuntimeGlobals, - RuntimeSpec, SourceType, SpanExt, Template, UsageState, UsedName, DEFAULT_EXPORT, - NAMESPACE_OBJECT_EXPORT, + CodeGenerationResult, Compilation, ConcatenatedModuleIdent, ConcatenationScope, ConnectionState, + Context, DependenciesBlock, DependencyId, DependencyTemplate, DependencyType, ErrorSpan, + ExportInfo, ExportInfoProvided, ExportsArgument, ExportsType, FactoryMeta, IdentCollector, + LibIdentOptions, Module, ModuleDependency, ModuleGraph, ModuleGraphConnection, ModuleIdentifier, + ModuleLayer, ModuleType, Resolve, RuntimeCondition, RuntimeGlobals, RuntimeSpec, SourceType, + SpanExt, Template, UsageState, UsedName, DEFAULT_EXPORT, NAMESPACE_OBJECT_EXPORT, }; type ExportsDefinitionArgs = Vec<(String, String)>; @@ -140,14 +139,14 @@ struct ConcatenationEntryConcatenated { #[derive(Debug)] struct ConcatenationEntryExternal { - connection: ConnectionId, + dependency: DependencyId, runtime_condition: RuntimeCondition, } impl ConcatenationEntryExternal { pub fn module(&self, mg: &ModuleGraph) -> ModuleIdentifier { let con = mg - .connection_by_connection_id(&self.connection) + .connection_by_dependency_id(&self.dependency) .expect("should have connection"); *con.module_identifier() } @@ -1580,11 +1579,8 @@ impl ConcatenatedModule { merge_runtime_condition(&last.runtime_condition, &runtime_condition, runtime); return; } - let con_id = mg - .connection_id_by_dependency_id(&con.dependency_id) - .expect("should have dep id"); list.push(ConcatenationEntry::External(ConcatenationEntryExternal { - connection: *con_id, + dependency: con.dependency_id, runtime_condition, })); } diff --git a/crates/rspack_core/src/exports_info.rs b/crates/rspack_core/src/exports_info.rs index 376898992a1..213ceaf1a6f 100644 --- a/crates/rspack_core/src/exports_info.rs +++ b/crates/rspack_core/src/exports_info.rs @@ -795,7 +795,7 @@ pub fn string_of_used_name(used: Option<&UsedName>) -> String { #[derive(Debug, Clone, Hash)] pub struct ExportInfoTargetValue { - connection: Option, + dependency: Option, export: Option>, priority: u8, } @@ -1085,7 +1085,7 @@ impl ExportInfo { &self, mg: &mut ModuleGraph, key: Option, - connection_inner_dep_id: Option, + dependency: Option, export_name: Option<&Nullable>>, priority: Option, ) -> bool { @@ -1100,7 +1100,7 @@ impl ExportInfo { info.target.insert( key, ExportInfoTargetValue { - connection: connection_inner_dep_id, + dependency, export: export_name.cloned(), priority: normalized_priority, }, @@ -1109,27 +1109,27 @@ impl ExportInfo { return true; } let Some(old_target) = info.target.get_mut(&key) else { - if connection_inner_dep_id.is_none() { + if dependency.is_none() { return false; } info.target.insert( key, ExportInfoTargetValue { - connection: connection_inner_dep_id, + dependency, export: export_name.cloned(), priority: normalized_priority, }, ); return true; }; - if old_target.connection != connection_inner_dep_id + if old_target.dependency != dependency || old_target.priority != normalized_priority || old_target.export.as_ref() != export_name { old_target.export = export_name.cloned(); old_target.priority = normalized_priority; - old_target.connection = connection_inner_dep_id; + old_target.dependency = dependency; return true; } @@ -1168,7 +1168,7 @@ impl ExportInfo { let max_target = self.get_max_target(mg); let mut values = max_target.values().map(|item| UnResolvedExportInfoTarget { - connection: item.connection, + dependency: item.dependency, export: item.export.clone(), }); @@ -1307,14 +1307,14 @@ impl ExportInfo { .values() .next() .expect("should have export info target"); // refer https://github.com/webpack/webpack/blob/ac7e531436b0d47cd88451f497cdfd0dad41535d/lib/ExportsInfo.js#L1388-L1394 - if original_target.connection.as_ref() == Some(&target.connection) + if original_target.dependency.as_ref() == Some(&target.dependency) || original_target.export == target.export { return None; } let export_info_mut = self.as_export_info_mut(mg); export_info_mut.target.clear(); - let updated_connection = update_original_connection(&target, mg); + let updated_dependency_id = update_original_connection(&target, mg); // shadowning `export_info_mut` to reduce `&mut ModuleGraph` borrow life time, since // `update_original_connection` also needs `&mut ModuleGraph` @@ -1322,7 +1322,7 @@ impl ExportInfo { export_info_mut.target.insert( None, ExportInfoTargetValue { - connection: updated_connection, + dependency: updated_dependency_id, export: target.export.clone(), priority: 0, }, @@ -1440,8 +1440,8 @@ impl ExportInfo { }; let mut target = FindTargetRetValue { module: *raw_target - .connection - .and_then(|dep_id| mg.connection_by_dependency(&dep_id)) + .dependency + .and_then(|dep_id| mg.connection_by_dependency_id(&dep_id)) .expect("should have connection") .module_identifier(), export: raw_target.export.clone(), @@ -1590,7 +1590,7 @@ pub struct ResolvedExportInfoTarget { pub module: ModuleIdentifier, pub export: Option>, /// using dependency id to retrieve Connection - pub connection: DependencyId, + pub dependency: DependencyId, } #[derive(Clone, Debug)] @@ -1616,7 +1616,7 @@ impl UsageKey { #[derive(Debug, Clone)] struct UnResolvedExportInfoTarget { - connection: Option, + dependency: Option, export: Option>, } @@ -1658,7 +1658,7 @@ impl ExportInfoData { ( k, ExportInfoTargetValue { - connection: v.connection, + dependency: v.dependency, export: match v.export { Some(vec) => Some(vec), None => Some(vec![name @@ -1708,13 +1708,12 @@ fn resolve_target( if let Some(input_target) = input_target { let mut target = ResolvedExportInfoTarget { module: *input_target - .connection - .as_ref() - .and_then(|dep_id| mg.connection_by_dependency(dep_id)) + .dependency + .and_then(|dep_id| mg.connection_by_dependency_id(&dep_id)) .expect("should have connection") .module_identifier(), export: input_target.export, - connection: input_target.connection.expect("should have connection"), + dependency: input_target.dependency.expect("should have dependency"), }; if target.export.is_none() { return Some(ResolvedExportInfoTargetWithCircular::Target(target)); @@ -1751,7 +1750,7 @@ fn resolve_target( } } else { target.module = t.module; - target.connection = t.connection; + target.dependency = t.dependency; target.export = if let Some(mut exports) = t.export { exports.extend_from_slice(&target_exports[1..]); Some(exports) diff --git a/crates/rspack_core/src/module_graph/connection.rs b/crates/rspack_core/src/module_graph/connection.rs index 7aa040b825d..c86fca4c3a2 100644 --- a/crates/rspack_core/src/module_graph/connection.rs +++ b/crates/rspack_core/src/module_graph/connection.rs @@ -1,41 +1,10 @@ use std::hash::Hash; -use std::sync::atomic::AtomicU32; -use std::sync::atomic::Ordering::Relaxed; use crate::{DependencyId, ModuleGraph, ModuleIdentifier, RuntimeSpec}; -pub static CONNECTION_ID: AtomicU32 = AtomicU32::new(0); - -#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq, Ord, PartialOrd)] -pub struct ConnectionId(u32); - -impl ConnectionId { - pub fn new() -> Self { - Self(CONNECTION_ID.fetch_add(1, Relaxed)) - } -} - -impl Default for ConnectionId { - fn default() -> Self { - Self::new() - } -} -impl std::ops::Deref for ConnectionId { - type Target = u32; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} -impl From for ConnectionId { - fn from(id: u32) -> Self { - Self(id) - } -} - #[derive(Debug, Clone, Eq)] pub struct ModuleGraphConnection { - pub id: ConnectionId, + pub dependency_id: DependencyId, /// The referencing module identifier pub original_module_identifier: Option, pub resolved_original_module_identifier: Option, @@ -43,37 +12,34 @@ pub struct ModuleGraphConnection { /// The referenced module identifier module_identifier: ModuleIdentifier, - /// The referencing dependency id - pub dependency_id: DependencyId, pub active: bool, pub conditional: bool, } impl Hash for ModuleGraphConnection { fn hash(&self, state: &mut H) { - self.id.hash(state); + self.dependency_id.hash(state); } } impl PartialEq for ModuleGraphConnection { fn eq(&self, other: &Self) -> bool { - self.id == other.id + self.dependency_id == other.dependency_id } } impl ModuleGraphConnection { pub fn new( - original_module_identifier: Option, dependency_id: DependencyId, + original_module_identifier: Option, module_identifier: ModuleIdentifier, active: bool, conditional: bool, ) -> Self { Self { - id: ConnectionId::new(), + dependency_id, original_module_identifier, module_identifier, - dependency_id, active, conditional, resolved_original_module_identifier: original_module_identifier, @@ -105,7 +71,7 @@ impl ModuleGraphConnection { module_graph.get_condition_state(self, runtime).is_true() } - pub fn get_active_state( + pub fn active_state( &self, module_graph: &ModuleGraph, runtime: Option<&RuntimeSpec>, @@ -148,21 +114,24 @@ impl ConnectionState { } } -pub fn add_connection_states(a: ConnectionState, b: ConnectionState) -> ConnectionState { - if matches!(a, ConnectionState::Bool(true)) || matches!(b, ConnectionState::Bool(true)) { - return ConnectionState::Bool(true); - } - if matches!(a, ConnectionState::Bool(false)) { - return b; - } - if matches!(b, ConnectionState::Bool(false)) { - return a; - } - if matches!(a, ConnectionState::TransitiveOnly) { - return b; - } - if matches!(b, ConnectionState::TransitiveOnly) { - return a; +impl std::ops::Add for ConnectionState { + type Output = Self; + fn add(self, other: Self) -> Self::Output { + if matches!(self, ConnectionState::Bool(true)) || matches!(other, ConnectionState::Bool(true)) { + return ConnectionState::Bool(true); + } + if matches!(self, ConnectionState::Bool(false)) { + return other; + } + if matches!(other, ConnectionState::Bool(false)) { + return self; + } + if matches!(self, ConnectionState::TransitiveOnly) { + return other; + } + if matches!(other, ConnectionState::TransitiveOnly) { + return self; + } + self } - a } diff --git a/crates/rspack_core/src/module_graph/mod.rs b/crates/rspack_core/src/module_graph/mod.rs index fab1573ed5f..f435426c83a 100644 --- a/crates/rspack_core/src/module_graph/mod.rs +++ b/crates/rspack_core/src/module_graph/mod.rs @@ -17,7 +17,7 @@ pub use connection::*; use crate::{ BoxDependency, BoxModule, BuildDependency, DependencyCondition, DependencyId, ExportInfo, - ExportInfoData, ExportsInfo, ExportsInfoData, ModuleIdentifier, ModuleProfile, + ExportInfoData, ExportsInfo, ExportsInfoData, ModuleIdentifier, }; // TODO Here request can be used Atom @@ -50,61 +50,8 @@ pub struct ModuleGraphPartial { /// ModuleGraphModule indexed by `ModuleIdentifier`. module_graph_modules: IdentifierMap>, - /// ModuleGraphConnection indexed by `ConnectionId`. - connections: HashMap>, - - /// Dependency_id to module_identifier it generates. - /// - /// If we want to get child module of parent module, we should - /// find in this hashmap using the dependency id of parent module. - /// - /// # Example - /// - /// ```ignore - /// let child_module_identifier = parent_module - /// .get_dependencies() - /// .iter() - /// .map(|dependency_id| { - /// module_graph_partial - /// .dependency_id_to_module_identifier - /// .get(dependency_id) - /// .unwrap() - /// .unwrap() - /// }) - /// .collect::>(); - /// ``` - dependency_id_to_module_identifier: HashMap>, - - /// Dependency_id to Connection_id. - /// - /// There is a one-to-one correspondence between connections and dependencies. - /// - /// # Example - /// - /// get connection from dependency - /// - /// ```ignore - /// let connection_id = module_graph_partial - /// .dependency_id_to_connection_id - /// .get(&dependency.id); - /// let connection = module_graph_partial - /// .connections - /// .get(connection_id) - /// .unwrap() - /// .unwrap(); - /// ``` - /// - /// get dependency from connection - /// - /// ```ignore - /// let dependency_id = &connection.dependency_id; - /// let dependency = module_graph_partial - /// .dependencies - /// .get(dependency_id) - /// .unwrap() - /// .unwrap(); - /// ``` - dependency_id_to_connection_id: HashMap>, + /// ModuleGraphConnection indexed by `DependencyId`. + connections: HashMap>, /// Dependency_id to parent module identifier and parent block /// @@ -129,7 +76,7 @@ pub struct ModuleGraphPartial { // Module's ExportsInfo is also a part of ModuleGraph exports_info_map: UkeyMap, export_info_map: UkeyMap, - connection_to_condition: HashMap, + connection_to_condition: HashMap, dep_meta_map: HashMap, } @@ -248,9 +195,9 @@ impl<'a> ModuleGraph<'a> { .incoming_connections(); let mut map: HashMap, Vec> = HashMap::default(); - for connection_id in connections { + for dep_id in connections { let con = self - .connection_by_connection_id(connection_id) + .connection_by_dependency_id(dep_id) .expect("should have connection"); match map.entry(con.original_module_identifier) { Entry::Occupied(mut occ) => { @@ -269,47 +216,38 @@ impl<'a> ModuleGraph<'a> { /// force will completely remove dependency, and you will not regenerate it from dependency_id pub fn revoke_connection( &mut self, - connection_id: &ConnectionId, + dep_id: &DependencyId, force: bool, ) -> Option { - let connection = self.connection_by_connection_id(connection_id)?; + let connection = self.connection_by_dependency_id(dep_id)?; let module_identifier = *connection.module_identifier(); let original_module_identifier = connection.original_module_identifier; - let dependency_id = connection.dependency_id; let Some(active_partial) = &mut self.active else { panic!("should have active partial"); }; - active_partial.connections.insert(*connection_id, None); + active_partial.connections.insert(*dep_id, None); if force { - active_partial.dependencies.insert(dependency_id, None); + active_partial.dependencies.insert(*dep_id, None); active_partial .dependency_id_to_parents - .insert(dependency_id, None); + .insert(*dep_id, None); } - // remove dependency - active_partial - .dependency_id_to_connection_id - .insert(dependency_id, None); - active_partial - .dependency_id_to_module_identifier - .insert(dependency_id, None); - // remove outgoing from original module graph module if let Some(original_module_identifier) = &original_module_identifier { if let Some(mgm) = self.module_graph_module_by_identifier_mut(original_module_identifier) { - mgm.remove_outgoing_connection(connection_id); + mgm.remove_outgoing_connection(dep_id); // Because of mgm.dependencies is set when original module build success // it does not need to remove dependency in mgm.dependencies. } } // remove incoming from module graph module if let Some(mgm) = self.module_graph_module_by_identifier_mut(&module_identifier) { - mgm.remove_incoming_connection(connection_id); + mgm.remove_incoming_connection(dep_id); } - Some((dependency_id, original_module_identifier)) + Some((*dep_id, original_module_identifier)) } pub fn revoke_module(&mut self, module_id: &ModuleIdentifier) -> Vec { @@ -408,96 +346,80 @@ impl<'a> ModuleGraph<'a> { return; } + // Outgoing connections let outgoing_connections = self .module_graph_module_by_identifier(old_module) .expect("should have mgm") .outgoing_connections() .clone(); - // Outgoing connections - // avoid violating rustc borrow rules - let mut add_outgoing_connection = vec![]; - let mut delete_outgoing_connection = vec![]; - for connection_id in outgoing_connections { - let connection = match self.connection_by_connection_id(&connection_id) { - Some(con) => con, - // removed - None => continue, - }; + let mut affected_outgoing_connection = vec![]; + for dep_id in outgoing_connections { + let connection = self + .connection_by_dependency_id(&dep_id) + .expect("should have connection"); let dependency = self - .dependency_by_id(&connection.dependency_id) + .dependency_by_id(&dep_id) .expect("should have dependency"); if filter_connection(connection, dependency) { let connection = self - .connection_by_connection_id_mut(&connection_id) + .connection_by_dependency_id_mut(&dep_id) .expect("should have connection"); connection.original_module_identifier = Some(*new_module); - add_outgoing_connection.push(connection_id); - delete_outgoing_connection.push(connection_id); + affected_outgoing_connection.push(dep_id); } } - let new_mgm = self - .module_graph_module_by_identifier_mut(new_module) - .expect("should have mgm"); - for c in add_outgoing_connection { - new_mgm.add_outgoing_connection(c); - } - let old_mgm = self .module_graph_module_by_identifier_mut(old_module) .expect("should have mgm"); - for c in delete_outgoing_connection { - old_mgm.remove_outgoing_connection(&c); + for dep_id in &affected_outgoing_connection { + old_mgm.remove_outgoing_connection(dep_id); } - let old_mgm = self - .module_graph_module_by_identifier(old_module) + let new_mgm = self + .module_graph_module_by_identifier_mut(new_module) .expect("should have mgm"); + for dep_id in affected_outgoing_connection { + new_mgm.add_outgoing_connection(dep_id); + } - // Outgoing connections - // avoid violating rustc borrow rules - let mut add_incoming_connection = vec![]; - let mut delete_incoming_connection = vec![]; - for connection_id in old_mgm.incoming_connections().clone() { - let connection = match self.connection_by_connection_id(&connection_id) { - Some(con) => con, - None => continue, - }; + // Incoming connections + let incoming_connections = self + .module_graph_module_by_identifier(old_module) + .expect("should have mgm") + .incoming_connections() + .clone(); + let mut affected_incoming_connection = vec![]; + for dep_id in incoming_connections { + let connection = self + .connection_by_dependency_id(&dep_id) + .expect("should have connection"); let dependency = self - .dependency_by_id(&connection.dependency_id) + .dependency_by_id(&dep_id) .expect("should have dependency"); // the inactive connection should not be updated if filter_connection(connection, dependency) && (connection.conditional || connection.active) { let connection = self - .connection_by_connection_id_mut(&connection_id) + .connection_by_dependency_id_mut(&dep_id) .expect("should have connection"); - let dep_id = connection.dependency_id; connection.set_module_identifier(*new_module); - - let Some(active_partial) = &mut self.active else { - panic!("should have active partial"); - }; - active_partial - .dependency_id_to_module_identifier - .insert(dep_id, Some(*new_module)); - add_incoming_connection.push(connection_id); - delete_incoming_connection.push(connection_id); + affected_incoming_connection.push(dep_id); } } - let new_mgm = self - .module_graph_module_by_identifier_mut(new_module) + let old_mgm = self + .module_graph_module_by_identifier_mut(old_module) .expect("should have mgm"); - for c in add_incoming_connection { - new_mgm.add_incoming_connection(c); + for dep_id in &affected_incoming_connection { + old_mgm.remove_incoming_connection(dep_id); } - let old_mgm = self - .module_graph_module_by_identifier_mut(old_module) + let new_mgm = self + .module_graph_module_by_identifier_mut(new_module) .expect("should have mgm"); - for c in delete_incoming_connection { - old_mgm.remove_incoming_connection(&c); + for dep_id in affected_incoming_connection { + new_mgm.add_incoming_connection(dep_id); } } @@ -507,7 +429,7 @@ impl<'a> ModuleGraph<'a> { new_module: &ModuleIdentifier, filter_connection: F, ) where - F: Fn(&ModuleGraphConnection, &ModuleGraph) -> bool, + F: Fn(&ModuleGraphConnection, &BoxDependency) -> bool, { if old_module == new_module { return; @@ -516,44 +438,33 @@ impl<'a> ModuleGraph<'a> { let old_mgm_connections = self .module_graph_module_by_identifier(old_module) .expect("should have mgm") - .get_outgoing_connections_unordered() + .outgoing_connections() .clone(); // Outgoing connections - for connection_id in old_mgm_connections { + let mut affected_outgoing_connections = vec![]; + for dep_id in old_mgm_connections { let connection = self - .connection_by_connection_id(&connection_id) - .expect("should have connection") - .clone(); - if filter_connection(&connection, &*self) { - let new_connection_id = self.clone_module_graph_connection( - &connection, - Some(*new_module), - *connection.module_identifier(), - ); - let new_mgm = self - .module_graph_module_by_identifier_mut(new_module) - .expect("should have mgm"); - new_mgm.add_outgoing_connection(new_connection_id); + .connection_by_dependency_id(&dep_id) + .expect("should have connection"); + let dep = self + .dependency_by_id(&dep_id) + .expect("should have dependency"); + if filter_connection(connection, dep) { + let con = self + .connection_by_dependency_id_mut(&dep_id) + .expect("should have connection"); + con.original_module_identifier = Some(*new_module); + affected_outgoing_connections.push(dep_id); } } - } - fn clone_module_graph_connection( - &mut self, - old_con: &ModuleGraphConnection, - original_module_identifier: Option, - module_identifier: ModuleIdentifier, - ) -> ConnectionId { - let new_connection_id = ConnectionId::new(); - let mut new_connection = old_con.clone(); - new_connection.id = new_connection_id; - new_connection.original_module_identifier = original_module_identifier; - new_connection.set_module_identifier(module_identifier); - - let old_condition = self.loop_partials(|p| p.connection_to_condition.get(&old_con.id)); - self.add_connection(new_connection, old_condition.cloned()); - new_connection_id + let new_mgm = self + .module_graph_module_by_identifier_mut(new_module) + .expect("should have mgm"); + for dep_id in affected_outgoing_connections { + new_mgm.add_outgoing_connection(dep_id); + } } pub fn get_depth(&self, module_id: &ModuleIdentifier) -> Option { @@ -723,16 +634,18 @@ impl<'a> ModuleGraph<'a> { .and_then(|module_identifier| self.module_graph_module_by_identifier(module_identifier)) } - pub fn module_identifier_by_dependency_id(&self, id: &DependencyId) -> Option<&ModuleIdentifier> { + pub fn module_identifier_by_dependency_id( + &self, + dep_id: &DependencyId, + ) -> Option<&ModuleIdentifier> { self - .loop_partials(|p| p.dependency_id_to_module_identifier.get(id))? + .loop_partials(|p| p.connections.get(dep_id))? .as_ref() + .map(|con| con.module_identifier()) } - pub fn get_module_by_dependency_id(&self, dependency_id: &DependencyId) -> Option<&BoxModule> { - if let Some(Some(ref module_id)) = - self.loop_partials(|p| p.dependency_id_to_module_identifier.get(dependency_id)) - { + pub fn get_module_by_dependency_id(&self, dep_id: &DependencyId) -> Option<&BoxModule> { + if let Some(module_id) = self.module_identifier_by_dependency_id(dep_id) { self.loop_partials(|p| p.modules.get(module_id))?.as_ref() } else { None @@ -744,7 +657,10 @@ impl<'a> ModuleGraph<'a> { connection: ModuleGraphConnection, condition: Option, ) { - if self.connection_by_connection_id(&connection.id).is_some() { + if self + .connection_by_dependency_id(&connection.dependency_id) + .is_some() + { return; } @@ -755,22 +671,17 @@ impl<'a> ModuleGraph<'a> { if let Some(condition) = condition { active_partial .connection_to_condition - .insert(connection.id, condition); + .insert(connection.dependency_id, condition); } - active_partial.dependency_id_to_module_identifier.insert( - connection.dependency_id, - Some(*connection.module_identifier()), - ); - let module_id = *connection.module_identifier(); let origin_module_id = connection.original_module_identifier; - let connection_id = connection.id; + let dependency_id = connection.dependency_id; // add to connections list active_partial .connections - .insert(connection.id, Some(connection)); + .insert(connection.dependency_id, Some(connection)); // set to module incoming connection { @@ -782,14 +693,14 @@ impl<'a> ModuleGraph<'a> { ) }); - mgm.add_incoming_connection(connection_id); + mgm.add_incoming_connection(dependency_id); } // set to origin module outgoing connection if let Some(identifier) = origin_module_id && let Some(original_mgm) = self.module_graph_module_by_identifier_mut(&identifier) { - original_mgm.add_outgoing_connection(connection_id); + original_mgm.add_outgoing_connection(dependency_id); }; } @@ -808,13 +719,6 @@ impl<'a> ModuleGraph<'a> { let condition = dependency .as_module_dependency() .and_then(|dep| dep.get_condition()); - let Some(active_partial) = &mut self.active else { - panic!("should have active partial"); - }; - active_partial - .dependency_id_to_module_identifier - .insert(dependency_id, Some(module_identifier)); - if !is_module_dependency { return Ok(()); } @@ -822,15 +726,12 @@ impl<'a> ModuleGraph<'a> { let active = !matches!(condition, Some(DependencyCondition::False)); let conditional = condition.is_some(); let new_connection = ModuleGraphConnection::new( - original_module_identifier, dependency_id, + original_module_identifier, module_identifier, active, conditional, ); - active_partial - .dependency_id_to_connection_id - .insert(new_connection.dependency_id, Some(new_connection.id)); self.add_connection(new_connection, condition); Ok(()) @@ -855,11 +756,6 @@ impl<'a> ModuleGraph<'a> { } } - pub fn connection_id_by_dependency_id(&self, dep_id: &DependencyId) -> Option<&ConnectionId> { - self - .loop_partials(|p| p.dependency_id_to_connection_id.get(dep_id))? - .as_ref() - } /// Uniquely identify a module graph module by its module's identifier and return the aliased reference pub fn module_graph_module_by_identifier( &self, @@ -893,55 +789,41 @@ impl<'a> ModuleGraph<'a> { exports_info.get_export_info(self, export_name) } - /// Uniquely identify a connection by a given dependency - pub fn connection_by_dependency( - &self, - dependency_id: &DependencyId, - ) -> Option<&ModuleGraphConnection> { - if let Some(connection_id) = self.connection_id_by_dependency_id(dependency_id) { - self - .loop_partials(|p| p.connections.get(connection_id))? - .as_ref() - } else { - None - } - } - pub(crate) fn get_ordered_connections( &self, module_identifier: &ModuleIdentifier, - ) -> Option> { + ) -> Option> { self .module_graph_module_by_identifier(module_identifier) .map(|m| { m.all_dependencies .iter() - .filter_map(|dep_id| self.connection_id_by_dependency_id(dep_id)) + .filter(|dep_id| self.connection_by_dependency_id(dep_id).is_some()) .collect() }) } - pub fn connection_by_connection_id( + pub fn connection_by_dependency_id( &self, - connection_id: &ConnectionId, + dependency_id: &DependencyId, ) -> Option<&ModuleGraphConnection> { self - .loop_partials(|p| p.connections.get(connection_id))? + .loop_partials(|p| p.connections.get(dependency_id))? .as_ref() } - pub fn connection_by_connection_id_mut( + pub fn connection_by_dependency_id_mut( &mut self, - connection_id: &ConnectionId, + dependency_id: &DependencyId, ) -> Option<&mut ModuleGraphConnection> { self .loop_partials_mut( - |p| p.connections.contains_key(connection_id), + |p| p.connections.contains_key(dependency_id), |p, search_result| { - p.connections.insert(*connection_id, search_result); + p.connections.insert(*dependency_id, search_result); }, - |p| p.connections.get(connection_id).cloned(), - |p| p.connections.get_mut(connection_id), + |p| p.connections.get(dependency_id).cloned(), + |p| p.connections.get_mut(dependency_id), )? .as_mut() } @@ -961,7 +843,7 @@ impl<'a> ModuleGraph<'a> { pub fn get_issuer(&self, module_id: &ModuleIdentifier) -> Option<&BoxModule> { self .module_graph_module_by_identifier(module_id) - .and_then(|mgm| mgm.get_issuer().get_module(self)) + .and_then(|mgm| mgm.issuer().get_module(self)) } pub fn is_optional(&self, module_id: &ModuleIdentifier) -> bool { @@ -1011,7 +893,7 @@ impl<'a> ModuleGraph<'a> { mgm .outgoing_connections() .iter() - .filter_map(|id| self.connection_by_connection_id(id)) + .filter_map(|id| self.connection_by_dependency_id(id)) .collect() }) .unwrap_or_default() @@ -1027,18 +909,12 @@ impl<'a> ModuleGraph<'a> { mgm .incoming_connections() .iter() - .filter_map(|id| self.connection_by_connection_id(id)) + .filter_map(|id| self.connection_by_dependency_id(id)) .collect() }) .unwrap_or_default() } - pub fn get_profile(&self, module_id: &ModuleIdentifier) -> Option<&ModuleProfile> { - self - .module_graph_module_by_identifier(module_id) - .and_then(|mgm| mgm.get_profile()) - } - pub fn get_module_hash(&self, module_id: &ModuleIdentifier) -> Option<&RspackHashDigest> { self .module_by_identifier(module_id) @@ -1060,74 +936,28 @@ impl<'a> ModuleGraph<'a> { .insert(dep_id, DependencyExtraMeta { ids }); } - pub fn update_module( - &mut self, - dep_id: &DependencyId, - module_id: &ModuleIdentifier, - ) -> Option { - let connection_id = *self - .connection_id_by_dependency_id(dep_id) - .expect("should have connection id"); + pub fn update_module(&mut self, dep_id: &DependencyId, module_id: &ModuleIdentifier) -> bool { let connection = self - .connection_by_connection_id_mut(&connection_id) + .connection_by_dependency_id_mut(dep_id) .expect("should have connection"); - if connection.module_identifier() == module_id { - return None; + let old_module_identifier = *connection.module_identifier(); + if &old_module_identifier == module_id { + return false; } - // clone connection - let mut new_connection = connection.clone(); - new_connection.id = ConnectionId::new(); - let new_connection_id = new_connection.id; - - let old_connection_id = connection.id; - let old_connection_dependency_id = connection.dependency_id; - - // modify old connection - connection.set_active(false); - - // copy condition - let condition = self - .loop_partials(|p| p.connection_to_condition.get(&old_connection_id)) - .cloned(); - - new_connection.set_module_identifier(*module_id); - let Some(active_partial) = &mut self.active else { - panic!("should have active partial"); - }; - active_partial - .dependency_id_to_module_identifier - .insert(new_connection.dependency_id, Some(*module_id)); - // add new connection - active_partial - .connections - .insert(new_connection_id, Some(new_connection.clone())); - - active_partial - .dependency_id_to_connection_id - .insert(old_connection_dependency_id, Some(new_connection_id)); - - if let Some(condition) = condition { - active_partial - .connection_to_condition - .insert(new_connection_id, condition); - } + connection.set_module_identifier(*module_id); + // remove dep_id from old module mgm incoming connection + let old_mgm = self + .module_graph_module_by_identifier_mut(&old_module_identifier) + .expect("should exist mgm"); + old_mgm.remove_incoming_connection(dep_id); - // add new connection to original_module outgoing connections - if let Some(ref original_module_identifier) = new_connection.original_module_identifier { - if let Some(mgm) = self.module_graph_module_by_identifier_mut(original_module_identifier) { - mgm.add_outgoing_connection(new_connection_id); - mgm.remove_outgoing_connection(&connection_id); - } - } - // add new connection to module incoming connections - if let Some(mgm) = - self.module_graph_module_by_identifier_mut(new_connection.module_identifier()) - { - mgm.add_incoming_connection(new_connection_id); - mgm.remove_incoming_connection(&connection_id); - } - Some(new_connection_id) + // add dep_id to updated module mgm incoming connection + let new_mgm = self + .module_graph_module_by_identifier_mut(module_id) + .expect("should exist mgm"); + new_mgm.add_incoming_connection(*dep_id); + true } pub fn get_exports_info(&self, module_identifier: &ModuleIdentifier) -> ExportsInfo { @@ -1237,7 +1067,7 @@ impl<'a> ModuleGraph<'a> { runtime: Option<&RuntimeSpec>, ) -> ConnectionState { let condition = self - .loop_partials(|p| p.connection_to_condition.get(&connection.id)) + .loop_partials(|p| p.connection_to_condition.get(&connection.dependency_id)) .expect("should have condition"); match condition { DependencyCondition::False => ConnectionState::Bool(false), diff --git a/crates/rspack_core/src/module_graph/module.rs b/crates/rspack_core/src/module_graph/module.rs index 8e981e45e80..ef8004fe826 100644 --- a/crates/rspack_core/src/module_graph/module.rs +++ b/crates/rspack_core/src/module_graph/module.rs @@ -1,16 +1,13 @@ use rustc_hash::FxHashSet as HashSet; use crate::ExportsInfo; -use crate::{ - module_graph::ConnectionId, ChunkGraph, DependencyId, ModuleIdentifier, ModuleIssuer, - ModuleProfile, -}; +use crate::{ChunkGraph, DependencyId, ModuleIdentifier, ModuleIssuer, ModuleProfile}; #[derive(Debug, Clone)] pub struct ModuleGraphModule { // edges from module to module - outgoing_connections: HashSet, - incoming_connections: HashSet, + outgoing_connections: HashSet, + incoming_connections: HashSet, issuer: ModuleIssuer, @@ -50,35 +47,27 @@ impl ModuleGraphModule { c.unwrap_or_else(|| panic!("{} module id not found", self.module_identifier)) } - pub fn add_incoming_connection(&mut self, connection_id: ConnectionId) { - self.incoming_connections.insert(connection_id); + pub fn add_incoming_connection(&mut self, dependency_id: DependencyId) { + self.incoming_connections.insert(dependency_id); } - pub fn remove_incoming_connection(&mut self, connection_id: &ConnectionId) { - self.incoming_connections.remove(connection_id); + pub fn remove_incoming_connection(&mut self, dependency_id: &DependencyId) { + self.incoming_connections.remove(dependency_id); } - pub fn add_outgoing_connection(&mut self, connection_id: ConnectionId) { - self.outgoing_connections.insert(connection_id); + pub fn add_outgoing_connection(&mut self, dependency_id: DependencyId) { + self.outgoing_connections.insert(dependency_id); } - pub fn remove_outgoing_connection(&mut self, connection_id: &ConnectionId) { - self.outgoing_connections.remove(connection_id); + pub fn remove_outgoing_connection(&mut self, dependency_id: &DependencyId) { + self.outgoing_connections.remove(dependency_id); } - pub fn incoming_connections(&self) -> &HashSet { + pub fn incoming_connections(&self) -> &HashSet { &self.incoming_connections } - pub fn outgoing_connections(&self) -> &HashSet { - &self.outgoing_connections - } - - pub fn get_incoming_connections_unordered(&self) -> &HashSet { - &self.incoming_connections - } - - pub fn get_outgoing_connections_unordered(&self) -> &HashSet { + pub fn outgoing_connections(&self) -> &HashSet { &self.outgoing_connections } @@ -86,7 +75,7 @@ impl ModuleGraphModule { self.profile = Some(profile); } - pub fn get_profile(&self) -> Option<&ModuleProfile> { + pub fn profile(&self) -> Option<&ModuleProfile> { self.profile.as_deref() } @@ -100,7 +89,7 @@ impl ModuleGraphModule { self.issuer = issuer; } - pub fn get_issuer(&self) -> &ModuleIssuer { + pub fn issuer(&self) -> &ModuleIssuer { &self.issuer } diff --git a/crates/rspack_core/src/normal_module.rs b/crates/rspack_core/src/normal_module.rs index b7510c1030c..f030f1a750c 100644 --- a/crates/rspack_core/src/normal_module.rs +++ b/crates/rspack_core/src/normal_module.rs @@ -28,10 +28,10 @@ use rustc_hash::FxHasher; use serde_json::json; use crate::{ - add_connection_states, contextify, diagnostics::ModuleBuildError, get_context, - impl_module_meta_info, module_update_hash, AsyncDependenciesBlockIdentifier, BoxLoader, - BoxModule, BuildContext, BuildInfo, BuildMeta, BuildResult, ChunkGraph, CodeGenerationResult, - Compilation, ConcatenationScope, ConnectionState, Context, DependenciesBlock, DependencyId, + contextify, diagnostics::ModuleBuildError, get_context, impl_module_meta_info, + module_update_hash, AsyncDependenciesBlockIdentifier, BoxLoader, BoxModule, BuildContext, + BuildInfo, BuildMeta, BuildResult, ChunkGraph, CodeGenerationResult, Compilation, + ConcatenationScope, ConnectionState, Context, DependenciesBlock, DependencyId, DependencyTemplate, FactoryMeta, GenerateContext, GeneratorOptions, LibIdentOptions, Module, ModuleDependency, ModuleGraph, ModuleIdentifier, ModuleLayer, ModuleType, OutputOptions, ParseContext, ParseResult, ParserAndGenerator, ParserOptions, Resolve, RspackLoaderRunnerPlugin, @@ -721,7 +721,7 @@ impl Module for NormalModule { module_chain.remove(&self.identifier()); return ConnectionState::Bool(true); } else if !matches!(state, ConnectionState::CircularConnection) { - current = add_connection_states(current, state); + current = current + state; } } } diff --git a/crates/rspack_core/src/stats/mod.rs b/crates/rspack_core/src/stats/mod.rs index c0b86206f85..11be76a4767 100644 --- a/crates/rspack_core/src/stats/mod.rs +++ b/crates/rspack_core/src/stats/mod.rs @@ -785,7 +785,7 @@ impl Stats<'_> { .filter(|d| d.module_identifier().is_some_and(|id| id == identifier)) .count() as u32; - let profile = if let Some(p) = mgm.get_profile() + let profile = if let Some(p) = mgm.profile() && let Some(factory) = p.factory.duration() && let Some(building) = p.building.duration() { @@ -857,11 +857,11 @@ impl Stats<'_> { if options.reasons { let mut reasons: Vec = mgm - .get_incoming_connections_unordered() + .incoming_connections() .iter() - .filter_map(|connection_id| { + .filter_map(|dep_id| { // the connection is removed - let connection = module_graph.connection_by_connection_id(connection_id)?; + let connection = module_graph.connection_by_dependency_id(dep_id)?; let (module_name, module_id) = connection .original_module_identifier .and_then(|i| module_graph.module_by_identifier(&i)) diff --git a/crates/rspack_core/src/unaffected_cache/mod.rs b/crates/rspack_core/src/unaffected_cache/mod.rs index 4212639236b..d962d863ea1 100644 --- a/crates/rspack_core/src/unaffected_cache/mod.rs +++ b/crates/rspack_core/src/unaffected_cache/mod.rs @@ -121,14 +121,11 @@ impl UnaffectedModuleCache { .hash .as_ref() .hash(&mut hasher); - for connection_id in module_graph + for dep_id in module_graph .get_ordered_connections(&module.identifier()) .expect("should have module") { - let connection = module_graph - .connection_by_connection_id(connection_id) - .expect("should have connection"); - connection.dependency_id.hash(&mut hasher); + dep_id.hash(&mut hasher); } hasher.finish() } @@ -151,9 +148,9 @@ impl UnaffectedModuleWithChunkGraphCache { .get_ordered_connections(&module_identifier) .expect("should have module") .into_iter() - .filter_map(|c| { + .filter_map(|dep_id| { let connection = module_graph - .connection_by_connection_id(c) + .connection_by_dependency_id(dep_id) .expect("should have connection"); chunk_graph.get_module_id(*connection.module_identifier()) }) diff --git a/crates/rspack_plugin_javascript/src/dependency/commonjs/common_js_export_require_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/commonjs/common_js_export_require_dependency.rs index 6e6e557d97e..7e19620edeb 100644 --- a/crates/rspack_plugin_javascript/src/dependency/commonjs/common_js_export_require_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/commonjs/common_js_export_require_dependency.rs @@ -179,7 +179,7 @@ impl Dependency for CommonJsExportRequireDependency { let Some(name) = self.names.first() else { unreachable!(); }; - let from = mg.connection_by_dependency(&self.id)?; + let from = mg.connection_by_dependency_id(&self.id)?; Some(ExportsSpec { exports: ExportsOfExportsSpec::Array(vec![ExportNameOrSpec::ExportSpec(ExportSpec { name: name.to_owned(), @@ -196,7 +196,7 @@ impl Dependency for CommonJsExportRequireDependency { ..Default::default() }) } else if self.names.is_empty() { - let from = mg.connection_by_dependency(&self.id)?; + let from = mg.connection_by_dependency_id(&self.id)?; if let Some(reexport_info) = self.get_star_reexports(mg, None, from.module_identifier()) { Some(ExportsSpec { exports: ExportsOfExportsSpec::Array( diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_imported_specifier_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_imported_specifier_dependency.rs index 5ccfc8e8967..e9e098faa4e 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_imported_specifier_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_imported_specifier_dependency.rs @@ -619,7 +619,7 @@ impl HarmonyExportImportedSpecifierDependency { )); let runtime_condition = if self.weak() { RuntimeCondition::Boolean(false) - } else if let Some(connection) = mg.connection_by_dependency(self.id()) { + } else if let Some(connection) = mg.connection_by_dependency_id(self.id()) { filter_runtime(ctxt.runtime, |r| connection.is_target_active(mg, r)) } else { RuntimeCondition::Boolean(true) @@ -1092,7 +1092,7 @@ impl Dependency for HarmonyExportImportedSpecifierDependency { ..Default::default() }), ExportModeType::ReexportDynamicDefault => { - let from = mg.connection_by_dependency(self.id()); + let from = mg.connection_by_dependency_id(self.id()); Some(ExportsSpec { exports: ExportsOfExportsSpec::Array(vec![ExportNameOrSpec::ExportSpec(ExportSpec { name: mode.name.unwrap_or_default(), @@ -1106,7 +1106,7 @@ impl Dependency for HarmonyExportImportedSpecifierDependency { }) } ExportModeType::ReexportNamedDefault => { - let from = mg.connection_by_dependency(self.id()); + let from = mg.connection_by_dependency_id(self.id()); Some(ExportsSpec { exports: ExportsOfExportsSpec::Array(vec![ExportNameOrSpec::ExportSpec(ExportSpec { name: mode.name.unwrap_or_default(), @@ -1120,7 +1120,7 @@ impl Dependency for HarmonyExportImportedSpecifierDependency { }) } ExportModeType::ReexportNamespaceObject => { - let from = mg.connection_by_dependency(self.id()); + let from = mg.connection_by_dependency_id(self.id()); Some(ExportsSpec { exports: ExportsOfExportsSpec::Array(vec![ExportNameOrSpec::ExportSpec(ExportSpec { name: mode.name.unwrap_or_default(), @@ -1134,7 +1134,7 @@ impl Dependency for HarmonyExportImportedSpecifierDependency { }) } ExportModeType::ReexportFakeNamespaceObject => { - let from = mg.connection_by_dependency(self.id()); + let from = mg.connection_by_dependency_id(self.id()); Some(ExportsSpec { exports: ExportsOfExportsSpec::Array(vec![ExportNameOrSpec::ExportSpec(ExportSpec { name: mode.name.unwrap_or_default(), @@ -1164,7 +1164,7 @@ impl Dependency for HarmonyExportImportedSpecifierDependency { ..Default::default() }), ExportModeType::NormalReexport => { - let from = mg.connection_by_dependency(self.id()); + let from = mg.connection_by_dependency_id(self.id()); Some(ExportsSpec { priority: Some(1), exports: ExportsOfExportsSpec::Array( @@ -1191,7 +1191,7 @@ impl Dependency for HarmonyExportImportedSpecifierDependency { }) } ExportModeType::DynamicReexport => { - let from = mg.connection_by_dependency(self.id()); + let from = mg.connection_by_dependency_id(self.id()); Some(ExportsSpec { exports: ExportsOfExportsSpec::True, from: from.cloned(), diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_dependency.rs index fc152a28c91..8973c829905 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_dependency.rs @@ -110,7 +110,7 @@ pub fn harmony_import_dependency_apply( } = code_generatable_context; // Only available when module factorization is successful. let module_graph = compilation.get_module_graph(); - let connection = module_graph.connection_by_dependency(module_dependency.id()); + let connection = module_graph.connection_by_dependency_id(module_dependency.id()); let is_target_active = if let Some(con) = connection { Some(con.is_target_active(&module_graph, *runtime)) } else { @@ -123,7 +123,8 @@ pub fn harmony_import_dependency_apply( let runtime_condition = if module_dependency.weak() { RuntimeCondition::Boolean(false) - } else if let Some(connection) = module_graph.connection_by_dependency(module_dependency.id()) { + } else if let Some(connection) = module_graph.connection_by_dependency_id(module_dependency.id()) + { filter_runtime(*runtime, |r| connection.is_target_active(&module_graph, r)) } else { RuntimeCondition::Boolean(true) diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_specifier_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_specifier_dependency.rs index 514a2ca87d4..871be0a8038 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_specifier_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_specifier_dependency.rs @@ -125,7 +125,7 @@ impl DependencyTemplate for HarmonyImportSpecifierDependency { let module_graph = compilation.get_module_graph(); // Only available when module factorization is successful. let reference_mgm = module_graph.module_graph_module_by_dependency_id(&self.id); - let connection = module_graph.connection_by_dependency(&self.id); + let connection = module_graph.connection_by_dependency_id(&self.id); let is_target_active = if let Some(con) = connection { con.is_target_active(&module_graph, *runtime) } else { @@ -152,7 +152,7 @@ impl DependencyTemplate for HarmonyImportSpecifierDependency { let import_var = compilation.get_import_var(&self.id); let export_expr = if let Some(scope) = concatenation_scope - && let Some(con) = module_graph.connection_by_dependency(&self.id) + && let Some(con) = module_graph.connection_by_dependency_id(&self.id) && scope.is_module_in_scope(con.module_identifier()) { if ids.is_empty() { diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/provide_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/provide_dependency.rs index 47a8fe48128..bc4e902e7d8 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/provide_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/provide_dependency.rs @@ -98,7 +98,7 @@ impl DependencyTemplate for ProvideDependency { .. } = code_generatable_context; let module_graph = compilation.get_module_graph(); - let Some(con) = module_graph.connection_by_dependency(&self.id) else { + let Some(con) = module_graph.connection_by_dependency_id(&self.id) else { // not find connection, maybe because it's not resolved in make phase, and `bail` is false return; }; diff --git a/crates/rspack_plugin_javascript/src/dependency/is_included_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/is_included_dependency.rs index f7d4ee96c28..dab030ccc22 100644 --- a/crates/rspack_plugin_javascript/src/dependency/is_included_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/is_included_dependency.rs @@ -67,7 +67,7 @@ impl DependencyTemplate for WebpackIsIncludedDependency { let included = compilation .get_module_graph() - .connection_by_dependency(&self.id) + .connection_by_dependency_id(&self.id) .map(|connection| { compilation .chunk_graph diff --git a/crates/rspack_plugin_javascript/src/plugin/flag_dependency_usage_plugin.rs b/crates/rspack_plugin_javascript/src/plugin/flag_dependency_usage_plugin.rs index ec2d39cb7d6..e430c18d83b 100644 --- a/crates/rspack_plugin_javascript/src/plugin/flag_dependency_usage_plugin.rs +++ b/crates/rspack_plugin_javascript/src/plugin/flag_dependency_usage_plugin.rs @@ -145,14 +145,14 @@ impl<'a> FlagDependencyUsagePluginProxy<'a> { } for dep_id in dep_id_list.into_iter() { let module_graph = self.compilation.get_module_graph(); - let connection = module_graph.connection_by_dependency(&dep_id); + let connection = module_graph.connection_by_dependency_id(&dep_id); let connection = if let Some(connection) = connection { connection } else { continue; }; - let active_state = connection.get_active_state(&module_graph, runtime.as_ref()); + let active_state = connection.active_state(&module_graph, runtime.as_ref()); match active_state { ConnectionState::Bool(false) => { diff --git a/crates/rspack_plugin_javascript/src/plugin/module_concatenation_plugin.rs b/crates/rspack_plugin_javascript/src/plugin/module_concatenation_plugin.rs index 5c73174fe10..89fe12730c9 100644 --- a/crates/rspack_plugin_javascript/src/plugin/module_concatenation_plugin.rs +++ b/crates/rspack_plugin_javascript/src/plugin/module_concatenation_plugin.rs @@ -166,7 +166,7 @@ impl ModuleConcatenationPlugin { if !is_harmony_import_like { continue; } - let Some(con) = mg.connection_by_dependency(d) else { + let Some(con) = mg.connection_by_dependency_id(d) else { continue; }; if !con.is_target_active(mg, runtime) { @@ -271,10 +271,7 @@ impl ModuleConcatenationPlugin { return Some(problem); } - let get_incoming_connections_by_origin_module = - module_graph.get_incoming_connections_by_origin_module(module_id); - - let incoming_connections = get_incoming_connections_by_origin_module; + let incoming_connections = module_graph.get_incoming_connections_by_origin_module(module_id); if let Some(incoming_connections_from_non_modules) = incoming_connections.get(&None) { let active_non_modules_connections = incoming_connections_from_non_modules @@ -663,12 +660,9 @@ impl ModuleConcatenationPlugin { if m == &root_module_id { continue; } - module_graph.copy_outgoing_module_connections(m, &new_module.id(), |c, mg| { - let dep = mg - .dependency_by_id(&c.dependency_id) - .expect("should have dependency"); - c.original_module_identifier.as_ref() == Some(m) - && !(is_harmony_dep_like(dep) && modules_set.contains(c.module_identifier())) + module_graph.copy_outgoing_module_connections(m, &new_module.id(), |con, dep| { + con.original_module_identifier.as_ref() == Some(m) + && !(is_harmony_dep_like(dep) && modules_set.contains(con.module_identifier())) }); // TODO: optimize asset module https://github.com/webpack/webpack/pull/15515/files for chunk_ukey in chunk_graph.get_module_chunks(root_module_id).clone() { diff --git a/crates/rspack_plugin_javascript/src/plugin/side_effects_flag_plugin.rs b/crates/rspack_plugin_javascript/src/plugin/side_effects_flag_plugin.rs index 3a46e3d5558..207883fb504 100644 --- a/crates/rspack_plugin_javascript/src/plugin/side_effects_flag_plugin.rs +++ b/crates/rspack_plugin_javascript/src/plugin/side_effects_flag_plugin.rs @@ -4,7 +4,7 @@ use std::sync::LazyLock; use rspack_collections::IdentifierMap; use rspack_collections::IdentifierSet; -use rspack_core::ConnectionId; +use rspack_core::DependencyId; use rspack_core::{ BoxModule, Compilation, CompilationOptimizeDependencies, ConnectionState, FactoryMeta, ModuleFactoryCreateData, ModuleGraph, ModuleIdentifier, NormalModuleCreateData, @@ -698,7 +698,7 @@ impl Plugin for SideEffectsFlagPlugin { fn optimize_incoming_connections( module_identifier: ModuleIdentifier, to_be_optimized: &mut IdentifierSet, - new_connections: &mut IdentifierMap>, + new_connections: &mut IdentifierMap>, compilation: &mut Compilation, ) { if !to_be_optimized.remove(&module_identifier) { @@ -717,9 +717,9 @@ fn optimize_incoming_connections( .module_graph_module_by_identifier(&module_identifier) .map(|mgm| mgm.incoming_connections().clone()) .unwrap_or_default(); - for &connection_id in &incoming_connections { + for &dep_id in &incoming_connections { optimize_incoming_connection( - connection_id, + dep_id, module_identifier, to_be_optimized, new_connections, @@ -728,9 +728,9 @@ fn optimize_incoming_connections( } // It is possible to add additional new connections when optimizing module's incoming connections while let Some(connections) = new_connections.remove(&module_identifier) { - for new_connection_id in connections { + for new_dep_id in connections { optimize_incoming_connection( - new_connection_id, + new_dep_id, module_identifier, to_be_optimized, new_connections, @@ -741,17 +741,17 @@ fn optimize_incoming_connections( } fn optimize_incoming_connection( - connection_id: ConnectionId, + dependency_id: DependencyId, module_identifier: ModuleIdentifier, to_be_optimized: &mut IdentifierSet, - new_connections: &mut IdentifierMap>, + new_connections: &mut IdentifierMap>, compilation: &mut Compilation, ) { let module_graph = compilation.get_module_graph(); let connection = module_graph - .connection_by_connection_id(&connection_id) + .connection_by_dependency_id(&dependency_id) .expect("should have connection"); - let Some(dep) = module_graph.dependency_by_id(&connection.dependency_id) else { + let Some(dep) = module_graph.dependency_by_id(&dependency_id) else { return; }; let is_reexport = dep @@ -771,7 +771,7 @@ fn optimize_incoming_connection( // See: https://github.com/webpack/webpack/pull/17595 optimize_incoming_connections(origin_module, to_be_optimized, new_connections, compilation); do_optimize_incoming_connection( - connection_id, + dependency_id, module_identifier, origin_module, new_connections, @@ -781,22 +781,18 @@ fn optimize_incoming_connection( #[tracing::instrument(skip_all, fields(origin = ?origin_module, module = ?module_identifier))] fn do_optimize_incoming_connection( - connection_id: ConnectionId, + dependency_id: DependencyId, module_identifier: ModuleIdentifier, origin_module: ModuleIdentifier, - new_connections: &mut IdentifierMap>, + new_connections: &mut IdentifierMap>, compilation: &mut Compilation, ) { if let Some(connections) = new_connections.get_mut(&module_identifier) { - connections.remove(&connection_id); + connections.remove(&dependency_id); } let mut module_graph = compilation.get_module_graph_mut(); - let connection = module_graph - .connection_by_connection_id(&connection_id) - .expect("should have connection"); - let dep_id = connection.dependency_id; let dep = module_graph - .dependency_by_id(&dep_id) + .dependency_by_id(&dependency_id) .expect("should have dep"); if let Some(name) = dep .downcast_ref::() @@ -813,9 +809,11 @@ fn do_optimize_incoming_connection( }), Arc::new( move |target: &ResolvedExportInfoTarget, mg: &mut ModuleGraph| { - mg.update_module(&dep_id, &target.module)?; + if !mg.update_module(&dependency_id, &target.module) { + return None; + } // TODO: Explain https://github.com/webpack/webpack/blob/ac7e531436b0d47cd88451f497cdfd0dad41535d/lib/optimize/SideEffectsFlagPlugin.js#L303-L306 - let ids = dep_id.get_ids(mg); + let ids = dependency_id.get_ids(mg); let processed_ids = target .export .as_ref() @@ -825,27 +823,24 @@ fn do_optimize_incoming_connection( ret }) .unwrap_or_else(|| ids.get(1..).unwrap_or_default().to_vec()); - dep_id.set_ids(processed_ids, mg); - Some(dep_id) + dependency_id.set_ids(processed_ids, mg); + Some(dependency_id) }, ), ); if let Some(ResolvedExportInfoTarget { - connection, module, .. + dependency, module, .. }) = target - && let Some(&connection_id) = compilation - .get_module_graph() - .connection_id_by_dependency_id(&connection) { new_connections .entry(module) .or_default() - .insert(connection_id); + .insert(dependency); }; return; } - let ids = dep_id.get_ids(&module_graph); + let ids = dependency_id.get_ids(&module_graph); if !ids.is_empty() { let cur_exports_info = module_graph.get_exports_info(&module_identifier); let export_info = cur_exports_info.get_export_info(&mut module_graph, &ids[0]); @@ -864,13 +859,13 @@ fn do_optimize_incoming_connection( let Some(target) = target else { return; }; - let Some(connection_id) = module_graph.update_module(&dep_id, &target.module) else { + if !module_graph.update_module(&dependency_id, &target.module) { return; }; new_connections .entry(target.module) .or_default() - .insert(connection_id); + .insert(dependency_id); // TODO: Explain https://github.com/webpack/webpack/blob/ac7e531436b0d47cd88451f497cdfd0dad41535d/lib/optimize/SideEffectsFlagPlugin.js#L303-L306 let processed_ids = target .export @@ -879,7 +874,7 @@ fn do_optimize_incoming_connection( item }) .unwrap_or_else(|| ids[1..].to_vec()); - dep_id.set_ids(processed_ids, &mut module_graph); + dependency_id.set_ids(processed_ids, &mut module_graph); } } diff --git a/crates/rspack_plugin_library/src/modern_module_library_plugin.rs b/crates/rspack_plugin_library/src/modern_module_library_plugin.rs index 3c73668fef6..0b2eaeac1a6 100644 --- a/crates/rspack_plugin_library/src/modern_module_library_plugin.rs +++ b/crates/rspack_plugin_library/src/modern_module_library_plugin.rs @@ -2,10 +2,11 @@ use std::hash::Hash; use rspack_core::rspack_sources::{ConcatSource, RawSource, SourceExt}; use rspack_core::{ - merge_runtime, to_identifier, ApplyContext, ChunkUkey, CodeGenerationExportsFinalNames, - Compilation, CompilationFinishModules, CompilationOptimizeChunkModules, CompilationParams, - CompilerCompilation, CompilerOptions, ConcatenatedModule, ConcatenatedModuleExportsDefinitions, - DependenciesBlock, Dependency, LibraryOptions, ModuleIdentifier, Plugin, PluginContext, + merge_runtime, to_identifier, ApplyContext, BoxDependency, ChunkUkey, + CodeGenerationExportsFinalNames, Compilation, CompilationFinishModules, + CompilationOptimizeChunkModules, CompilationParams, CompilerCompilation, CompilerOptions, + ConcatenatedModule, ConcatenatedModuleExportsDefinitions, DependenciesBlock, Dependency, + LibraryOptions, ModuleIdentifier, Plugin, PluginContext, }; use rspack_error::{error_bail, Result}; use rspack_hash::RspackHash; @@ -236,7 +237,7 @@ async fn finish_modules(&self, compilation: &mut Compilation) -> Result<()> { *block_id, block_dep.clone(), new_dep.clone(), - import_dep_connection.id, + import_dep_connection.dependency_id, )); } } @@ -249,7 +250,7 @@ async fn finish_modules(&self, compilation: &mut Compilation) -> Result<()> { let block = mg.block_by_id_mut(block_id).expect("should have block"); let dep_id = dep.id(); block.remove_dependency_id(*dep_id); - let boxed_dep = Box::new(new_dep.clone()) as Box; + let boxed_dep = Box::new(new_dep.clone()) as BoxDependency; block.add_dependency_id(*new_dep.id()); mg.add_dependency(boxed_dep); mg.revoke_connection(connection_id, true); diff --git a/tests/webpack-test/__snapshots__/StatsTestCases.basictest.js.snap b/tests/webpack-test/__snapshots__/StatsTestCases.basictest.js.snap index 9266ad00903..0bacc65eb95 100644 --- a/tests/webpack-test/__snapshots__/StatsTestCases.basictest.js.snap +++ b/tests/webpack-test/__snapshots__/StatsTestCases.basictest.js.snap @@ -1589,9 +1589,6 @@ cacheable modules 967 bytes ./components/src/index.js 84 bytes [orphan] [built] [module unused] esm import ./components ./foo.js - esm import specifier ./components ./foo.js - esm import specifier ./components ./main.js - esm import specifier ./components ./main.js esm import ./components ./main.js code generated modules 186 bytes [code generated] ./components/src/CompAB/CompA.js 89 bytes [built] [code generated] @@ -1606,8 +1603,6 @@ cacheable modules 967 bytes esm import specifier ./utils ./components/src/CompAB/CompA.js esm import ./utils ./components/src/CompAB/CompB.js esm import specifier ./utils ./components/src/CompAB/CompB.js - esm import ./utils ./components/src/CompAB/CompB.js - esm import specifier ./utils ./components/src/CompAB/CompB.js modules by path ./*.js 466 bytes ./main.js 144 bytes [orphan] [built] [no exports used] @@ -1634,7 +1629,6 @@ modules by path ./node_modules/pmodule/*.js 232 bytes [only some exports used: default] esm import pmodule ./index.js esm import specifier pmodule ./index.js - esm import specifier pmodule ./index.js ./node_modules/pmodule/c.js 28 bytes [orphan] [built] [only some exports used: z] esm import specifier pmodule ./index.js @@ -1644,18 +1638,12 @@ modules by path ./node_modules/pmodule/*.js 232 bytes [module unused] esm export ./a ./node_modules/pmodule/index.js esm export import specifier ./a ./node_modules/pmodule/index.js - esm export ./a ./node_modules/pmodule/index.js - esm export import specifier ./a ./node_modules/pmodule/index.js ./node_modules/pmodule/b.js 69 bytes [orphan] [built] [module unused] esm export ./b ./node_modules/pmodule/index.js esm export import specifier ./b ./node_modules/pmodule/index.js esm export import specifier ./b ./node_modules/pmodule/index.js esm export import specifier ./b ./node_modules/pmodule/index.js - esm export ./b ./node_modules/pmodule/index.js - esm export import specifier ./b ./node_modules/pmodule/index.js - esm export import specifier ./b ./node_modules/pmodule/index.js - esm export import specifier ./b ./node_modules/pmodule/index.js modules by path ./*.js 213 bytes ./index.js 55 bytes [orphan] [built] [no exports used] @@ -1668,7 +1656,6 @@ modules by path ./*.js 213 bytes | [only some exports used: default] | esm import pmodule ./index.js | esm import specifier pmodule ./index.js - | esm import specifier pmodule ./index.js | ./node_modules/pmodule/c.js 28 bytes [orphan] [built] | [only some exports used: z] | esm import specifier pmodule ./index.js