Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk committed Nov 24, 2023
1 parent e7dde5a commit baaa670
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 33 deletions.
2 changes: 1 addition & 1 deletion crates/rspack_core/src/dependency/runtime_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ pub fn async_module_factory(
) -> String {
let block = compilation
.module_graph
.block_by_id(&block_id)
.block_by_id(block_id)
.expect("should have block");
let dep = block.get_dependencies()[0];
let ensure_chunk = block_promise(Some(block_id), runtime_requirements, compilation);
Expand Down
5 changes: 2 additions & 3 deletions crates/rspack_core/src/mf/sharing/provide_shared_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,8 @@ impl Module for ProvideSharedModule {
.insert(RuntimeGlobals::INITIALIZE_SHARING);
let init = format!(
"register({}, {}, {}{})",
serde_json::to_string(&self.name)
.expect("ProvideSharedModule name should able to json to_string"),
serde_json::to_string(&self.version.to_string()).unwrap_or("0".to_string()),
serde_json::to_string(&self.name).expect("ProvideSharedModule name should able to json to_string"),
serde_json::to_string(&self.version.to_string()).expect("ProvideVersion::Version should able to json to_string in ProvideSharedModule::code_generation"),
if self.eager {
sync_module_factory(
&self.get_dependencies()[0],
Expand Down
43 changes: 20 additions & 23 deletions crates/rspack_core/src/mf/sharing/provide_shared_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl fmt::Display for ProvideVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ProvideVersion::Version(v) => write!(f, "{}", v),
ProvideVersion::False => write!(f, "false"),
ProvideVersion::False => write!(f, "0"),
}
}
}
Expand All @@ -80,6 +80,7 @@ impl ProvideSharedPlugin {
}
}

#[allow(clippy::too_many_arguments)]
pub async fn provide_shared_module(
&self,
key: &str,
Expand All @@ -101,27 +102,25 @@ impl ProvideSharedPlugin {
eager,
},
);
} else {
if let Some(description) = &resource_data.resource_description {
if let Some(description) = description.json().as_object()
&& let Some(version) = description.get("version")
&& let Some(version) = version.as_str()
{
self.resolved_provide_map.write().await.insert(
resource.to_string(),
VersionedProvideOptions {
share_key: share_key.to_string(),
share_scope: share_scope.to_string(),
version: ProvideVersion::Version(version.to_string()),
eager,
},
);
} else {
return Err(Error::InternalError(InternalError::new(format!("{error_header} No version in description file (usually package.json). Add version to description file {}, or manually specify version in shared config. shared module {key} -> {resource}", description.path().display()), Severity::Warn)));
}
} else if let Some(description) = &resource_data.resource_description {
if let Some(description) = description.json().as_object()
&& let Some(version) = description.get("version")
&& let Some(version) = version.as_str()
{
self.resolved_provide_map.write().await.insert(
resource.to_string(),
VersionedProvideOptions {
share_key: share_key.to_string(),
share_scope: share_scope.to_string(),
version: ProvideVersion::Version(version.to_string()),
eager,
},
);
} else {
return Err(Error::InternalError(InternalError::new(format!("{error_header} No description file (usually package.json) found. Add description file with name and version, or manually specify version in shared config. shared module {key} -> {resource}"), Severity::Warn)));
return Err(Error::InternalError(InternalError::new(format!("{error_header} No version in description file (usually package.json). Add version to description file {}, or manually specify version in shared config. shared module {key} -> {resource}", description.path().display()), Severity::Warn)));
}
} else {
return Err(Error::InternalError(InternalError::new(format!("{error_header} No description file (usually package.json) found. Add description file with name and version, or manually specify version in shared config. shared module {key} -> {resource}"), Severity::Warn)));
}
Ok(())
}
Expand All @@ -138,9 +137,7 @@ impl Plugin for ProvideSharedPlugin {
let mut match_provides = self.match_provides.write().await;
let mut prefix_match_provides = self.prefix_match_provides.write().await;
for (request, config) in &self.provides {
if RELATIVE_REQUEST.is_match(&request) {
resolved_provide_map.insert(request.to_string(), config.to_versioned());
} else if ABSOLUTE_REQUEST.is_match(&request) {
if RELATIVE_REQUEST.is_match(request) || ABSOLUTE_REQUEST.is_match(request) {
resolved_provide_map.insert(request.to_string(), config.to_versioned());
} else if request.ends_with('/') {
prefix_match_provides.insert(request.to_string(), config.clone());
Expand Down
3 changes: 2 additions & 1 deletion crates/rspack_core/src/mf/sharing/share_runtime_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ var initPerScope = function(name, register, initExternal) {{
{init_per_scope_body}
}}
}};
{initialize_sharing} = function(name, initScope) {{ return {initialize_sharing_fn}({{ name: name, initScope: initScope, initPerScope: initPerScope, initTokens: initTokens, initPromises: initPromises }}); }};
{initialize_sharing} = function(name, initScope) {{ return {initialize_sharing_fn}({{ name: name, initScope: initScope, initPerScope: initPerScope, uniqueName: {unique_name}, initTokens: initTokens, initPromises: initPromises }}); }};
"#,
share_scope_map = RuntimeGlobals::SHARE_SCOPE_MAP,
init_per_scope_body = init_per_scope_body,
unique_name = serde_json::to_string(&compilation.options.output.unique_name).expect("uniqueName should able to json to_string"),
initialize_sharing = RuntimeGlobals::INITIALIZE_SHARING,
initialize_sharing_fn = "__webpack_require__.MF.initializeSharing"
))
Expand Down
4 changes: 2 additions & 2 deletions crates/rspack_core/src/plugin/plugin_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ impl PluginDriver {
plugin.name()
);
if let Some(module) = plugin
.normal_module_factory_create_module(PluginContext::new(), &args)
.normal_module_factory_create_module(PluginContext::new(), args)
.await?
{
return Ok(Some(module));
Expand All @@ -349,7 +349,7 @@ impl PluginDriver {
for plugin in &self.plugins {
tracing::trace!("running normal_module_factory_module:{}", plugin.name());
module = plugin
.normal_module_factory_module(PluginContext::new(), module, &args)
.normal_module_factory_module(PluginContext::new(), module, args)
.await?;
}
Ok(module)
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack/src/sharing/initializeSharing.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if (__webpack_require__.MF) {
var warn = function (msg) {
if (typeof console !== "undefined" && console.warn) console.warn(msg);
};
var uniqueName = "app";
var uniqueName = data.uniqueName;
var register = function (name, version, factory, eager) {
var versions = (scope[name] = scope[name] || {});
var activeVersion = versions[version];
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit baaa670

Please sign in to comment.