From 3cb51037132aebe8a0b356d9afa9f93f65354412 Mon Sep 17 00:00:00 2001 From: JW Date: Wed, 10 Apr 2024 10:27:39 +0800 Subject: [PATCH] fix: keep imports in order --- .../src/plugin/rsc_client_entry_rspack_plugin.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/rspack_plugin_rsc/src/plugin/rsc_client_entry_rspack_plugin.rs b/crates/rspack_plugin_rsc/src/plugin/rsc_client_entry_rspack_plugin.rs index 10bba207514..89dfb92e8c1 100644 --- a/crates/rspack_plugin_rsc/src/plugin/rsc_client_entry_rspack_plugin.rs +++ b/crates/rspack_plugin_rsc/src/plugin/rsc_client_entry_rspack_plugin.rs @@ -2,6 +2,7 @@ use std::collections::{HashMap, HashSet}; use std::time::Instant; use async_trait::async_trait; +use indexmap::set::IndexSet; use rspack_core::rspack_sources::{RawSource, SourceExt}; use rspack_core::{ ApplyContext, AssetInfo, Compilation, CompilationAsset, CompilerOptions, Module, ModuleType, @@ -23,7 +24,7 @@ impl RSCClientEntryRspackPlugin { compilation: &Compilation, module: &Box, visited_modules: &mut HashSet, - collect_client_imports: &mut HashSet, + collect_client_imports: &mut IndexSet, ) { let data = module .as_normal_module() @@ -66,9 +67,9 @@ impl RSCClientEntryRspackPlugin { #[plugin_hook(AsyncSeries for RSCClientEntryRspackPlugin)] async fn finish_make(&self, compilation: &mut Compilation) -> Result<()> { let now = Instant::now(); - let mut client_imports: HashMap> = HashMap::new(); + let mut client_imports: HashMap> = HashMap::new(); for (name, entry) in &compilation.entries { - let mut collected_client_imports: HashSet = HashSet::new(); + let mut collected_client_imports: IndexSet = IndexSet::new(); let mut visited_modules: HashSet = HashSet::new(); let mg = compilation.get_module_graph(); let entry_module = mg @@ -80,16 +81,17 @@ async fn finish_make(&self, compilation: &mut Compilation) -> Result<()> { &mut visited_modules, &mut collected_client_imports, ); + collected_client_imports.sort(); client_imports.insert(String::from(name), collected_client_imports); } - // all other entries depend on this entry + // TODO: custom main entry name, all other entries depend on this entry let main_name = "server-entry"; let cc = client_imports.clone(); let main = cc.get(main_name).unwrap(); for (name, value) in client_imports.iter_mut() { if name != main_name { for import in main { - value.remove(import.as_str()); + value.shift_remove(import.as_str()); } } let content = to_string(&value);