Skip to content

Commit

Permalink
chore: code styles
Browse files Browse the repository at this point in the history
  • Loading branch information
xusd320 committed Jan 21, 2025
1 parent ca5c7d5 commit 38dc51b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
12 changes: 6 additions & 6 deletions crates/mako/src/plugins/module_federation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::ast::file::Content;
use crate::build::analyze_deps::ResolvedDep;
use crate::compiler::{Args, Context};
use crate::config::module_federation::ModuleFederationConfig;
use crate::config::Config;
use crate::config::{CodeSplittingAdvancedOptions, Config};
use crate::generate::chunk::Chunk;
use crate::generate::chunk_graph::ChunkGraph;
use crate::module_graph::ModuleGraph;
Expand Down Expand Up @@ -54,11 +54,11 @@ impl Plugin for ModuleFederationPlugin {
&self,
content: &mut Content,
_path: &str,
_is_entry: bool,
is_entry: bool,
context: &Arc<Context>,
) -> Result<Option<Content>> {
// add container entry runtime dependency
if !_is_entry {
if !is_entry {
Ok(None)
} else {
match content {
Expand All @@ -79,9 +79,9 @@ impl Plugin for ModuleFederationPlugin {
Ok(vec![
self.get_federation_runtime_code(),
self.get_container_references_code(context),
self.get_provide_sharing_code(context),
self.get_consume_sharing_code(entry_chunk, context),
self.get_federation_exposes_library_code(),
self.get_consume_sharing_code(entry_chunk, context),
self.get_provide_sharing_code(context),
])
}

Expand Down Expand Up @@ -122,7 +122,7 @@ impl Plugin for ModuleFederationPlugin {

fn after_optimize_chunk_options(
&self,
optimize_chunk_options: &mut crate::config::CodeSplittingAdvancedOptions,
optimize_chunk_options: &mut CodeSplittingAdvancedOptions,
) -> Result<()> {
self.patch_code_splitting(optimize_chunk_options);
Ok(())
Expand Down
12 changes: 6 additions & 6 deletions crates/mako/src/plugins/module_federation/consume_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,13 @@ impl ModuleFederationPlugin {
);
let hash = md5_hash(&config_joined_str, 4);
return Ok(Some(ResolverResource::Shared(ConsumeSharedInfo {
name: source.to_string(),
version: resolver_resource.get_pkg_info().unwrap().version.unwrap(),
share_scope: shared_info.shared_scope.clone(),
eager: shared_info.eager,
singletion: shared_info.singleton,
required_version: shared_info.required_version.clone(),
strict_version: shared_info.strict_version,
module_id: format!(
"{}{}/{}/{}?{}",
FEDERATION_SHARED_REFERENCE_PREFIX,
Expand All @@ -175,9 +181,6 @@ impl ModuleFederationPlugin {
source,
hash
),
name: source.to_string(),
share_scope: shared_info.shared_scope.clone(),
version: resolver_resource.get_pkg_info().unwrap().version.unwrap(),
deps: AnalyzeDepsResult {
resolved_deps: vec![ResolvedDep {
resolver_resource,
Expand All @@ -191,9 +194,6 @@ impl ModuleFederationPlugin {
}],
missing_deps: HashMap::new(),
},
singletion: shared_info.singleton,
required_version: shared_info.required_version.clone(),
strict_version: shared_info.strict_version,
})));
}
Ok(None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl ModuleFederationPlugin {
let remote_info = id_to_external_and_name_mapping
.entry(m.id.id.as_str())
.or_default();

remote_info.push(&remote_module.share_scope);
remote_info.push(&remote_module.sub_path);
remote_info.push(&remote_module.external_reference_id);
Expand Down
5 changes: 5 additions & 0 deletions crates/mako/src/plugins/module_federation/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,22 +154,27 @@ fn extrac_chunk_assets(
acc.splice(..0, sync_deps);
acc
});

let all_sync_chunks = [sync_chunk_dependencies, sync_chunks].concat();
let all_async_chunks: Vec<ModuleId> = all_sync_chunks.iter().fold(vec![], |mut acc, cur| {
acc.extend(chunk_graph.installable_descendants_chunk(cur));
acc
});

let (sync_js_files, sync_css_files) = extract_assets(all_sync_chunks, &params.stats);

let (async_js_files, async_css_files) = extract_assets(all_async_chunks, &params.stats);

let async_js_files = async_js_files
.into_iter()
.filter(|f| !sync_js_files.contains(f))
.collect();

let async_css_files = async_css_files
.into_iter()
.filter(|f| !sync_js_files.contains(f))
.collect();

ManifestAssets {
js: ManifestAssetsItem {
sync: sync_js_files,
Expand Down

0 comments on commit 38dc51b

Please sign in to comment.