Skip to content

Commit

Permalink
feat: integrate mf 1.5 runtime (#5063)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk committed Jan 2, 2024
1 parent 07b1803 commit 8050434
Show file tree
Hide file tree
Showing 143 changed files with 2,029 additions and 161 deletions.
10 changes: 6 additions & 4 deletions crates/rspack_core/src/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ impl Compilation {
let current_profile = self.options.profile.then(Box::<ModuleProfile>::default);
let dependency = dependencies[0].get_dependency(&self.module_graph).clone();
queue.add_task(FactorizeTask {
module_factory: self.get_dependency_factory(dependency.dependency_type()),
module_factory: self.get_dependency_factory(&dependency),
original_module_identifier,
issuer,
original_module_context,
Expand Down Expand Up @@ -1880,7 +1880,8 @@ impl Compilation {
.insert(dependency_type, module_factory);
}

pub fn get_dependency_factory(&self, dependency_type: &DependencyType) -> Arc<dyn ModuleFactory> {
pub fn get_dependency_factory(&self, dependency: &BoxDependency) -> Arc<dyn ModuleFactory> {
let dependency_type = dependency.dependency_type();
self
.dependency_factories
.get(&match dependency_type {
Expand All @@ -1890,8 +1891,9 @@ impl Compilation {
})
.unwrap_or_else(|| {
panic!(
"No module factory available for dependency type: {}",
dependency_type
"No module factory available for dependency type: {}, resourceIdentifier: {:?}",
dependency_type,
dependency.resource_identifier()
)
})
.clone()
Expand Down
2 changes: 2 additions & 0 deletions crates/rspack_core/src/dependency/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod module_dependency;
mod runtime_requirements_dependency;
mod runtime_template;
mod span;
mod static_exports_dependency;

use std::sync::Arc;

Expand All @@ -30,6 +31,7 @@ pub use module_dependency::*;
pub use runtime_requirements_dependency::RuntimeRequirementsDependency;
pub use runtime_template::*;
pub use span::SpanExt;
pub use static_exports_dependency::StaticExportsDependency;
use swc_core::ecma::atoms::JsWord;

use crate::{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use rspack_core::{
use swc_core::ecma::atoms::JsWord;

use crate::{
AsContextDependency, AsDependencyTemplate, AsModuleDependency, Dependency, DependencyId,
DependencyType, ExportNameOrSpec, ExportsOfExportsSpec, ModuleGraph,
DependencyType, ExportNameOrSpec, ExportsOfExportsSpec, ExportsSpec, ModuleGraph,
};
use swc_core::ecma::atoms::JsWord;

#[derive(Debug, Clone)]
pub struct StaticExportsDependency {
Expand Down Expand Up @@ -34,8 +35,8 @@ impl Dependency for StaticExportsDependency {
"StaticExportsDependency"
}

fn get_exports(&self, _mg: &ModuleGraph) -> Option<rspack_core::ExportsSpec> {
Some(rspack_core::ExportsSpec {
fn get_exports(&self, _mg: &ModuleGraph) -> Option<ExportsSpec> {
Some(ExportsSpec {
exports: ExportsOfExportsSpec::Array(
self
.exports
Expand Down
15 changes: 10 additions & 5 deletions crates/rspack_plugin_mf/src/container/container_entry_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use rspack_core::{
block_promise, module_raw, returning_function,
rspack_sources::{RawSource, Source, SourceExt},
throw_missing_module_error_block, AsyncDependenciesBlock, AsyncDependenciesBlockIdentifier,
BuildContext, BuildInfo, BuildMeta, BuildMetaExportsType, BuildResult, ChunkGroupOptions,
CodeGenerationResult, Compilation, Context, DependenciesBlock, DependencyId, GroupOptions,
LibIdentOptions, Module, ModuleDependency, ModuleIdentifier, ModuleType, RuntimeGlobals,
RuntimeSpec, SourceType,
BoxDependency, BuildContext, BuildInfo, BuildMeta, BuildMetaExportsType, BuildResult,
ChunkGroupOptions, CodeGenerationResult, Compilation, Context, DependenciesBlock, DependencyId,
GroupOptions, LibIdentOptions, Module, ModuleDependency, ModuleIdentifier, ModuleType,
RuntimeGlobals, RuntimeSpec, SourceType, StaticExportsDependency,
};
use rspack_error::{impl_empty_diagnosable_trait, Result};
use rspack_hash::RspackHash;
Expand Down Expand Up @@ -104,6 +104,7 @@ impl Module for ContainerEntryModule {
let hash = hasher.digest(&build_context.compiler_options.output.hash_digest);

let mut blocks = vec![];
let mut dependencies: Vec<BoxDependency> = vec![];
for (name, options) in &self.exposes {
let mut block = AsyncDependenciesBlock::new(self.identifier, name, None);
block.set_group_options(GroupOptions::ChunkGroup(
Expand All @@ -115,6 +116,10 @@ impl Module for ContainerEntryModule {
}
blocks.push(block);
}
dependencies.push(Box::new(StaticExportsDependency::new(
vec!["get".into(), "init".into()],
false,
)));

Ok(BuildResult {
build_info: BuildInfo {
Expand All @@ -126,7 +131,7 @@ impl Module for ContainerEntryModule {
exports_type: BuildMetaExportsType::Namespace,
..Default::default()
},
dependencies: vec![],
dependencies,
blocks,
..Default::default()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Dependency for ConsumeSharedFallbackDependency {
}

fn dependency_type(&self) -> &DependencyType {
&DependencyType::ProvideModuleForShared
&DependencyType::ConsumeSharedFallback
}

fn category(&self) -> &DependencyCategory {
Expand Down
Loading

0 comments on commit 8050434

Please sign in to comment.