Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk committed Nov 22, 2023
1 parent 09d13af commit 73d151b
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 9 deletions.
3 changes: 3 additions & 0 deletions crates/rspack_core/src/dependency/dependency_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ pub enum DependencyType {
ContainerExposed,
/// container entry,
ContainerEntry,
/// remote to external,
RemoteToExternal,
Custom(Box<str>), // TODO it will increase large layout size
}

Expand Down Expand Up @@ -107,6 +109,7 @@ impl DependencyType {
DependencyType::ImportMetaContext => Cow::Borrowed("import.meta context"),
DependencyType::ContainerExposed => Cow::Borrowed("container exposed"),
DependencyType::ContainerEntry => Cow::Borrowed("container entry"),
DependencyType::RemoteToExternal => Cow::Borrowed("remote to external"),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ impl ModuleDependency for ContainerEntryDependency {
fn request(&self) -> &str {
&self.resource_identifier
}

fn user_request(&self) -> &str {
&self.resource_identifier
}

fn set_request(&mut self, _request: String) {}
}

impl AsContextDependency for ContainerEntryDependency {}
Expand Down
73 changes: 70 additions & 3 deletions crates/rspack_core/src/mf/container/container_reference_plugin.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,73 @@
use crate::Plugin;
use async_trait::async_trait;

use super::RemoteRuntimeModule;
use crate::{
AdditionalChunkRuntimeRequirementsArgs, ExternalType, FactorizeArgs, NormalModuleFactoryContext,
Plugin, PluginAdditionalChunkRuntimeRequirementsOutput, PluginContext, PluginFactorizeHookOutput,
RuntimeGlobals, RuntimeModuleExt,
};

#[derive(Debug)]
pub struct ContainerReferencePluginOptions {
pub remote_type: ExternalType,
pub remotes: Vec<(String, RemoteOptions)>,
pub share_scope: Option<String>,
}

#[derive(Debug)]
pub struct ContainerReferencePlugin;
pub struct RemoteOptions {
pub external: Vec<String>,
pub share_scope: String,
}

#[derive(Debug)]
pub struct ContainerReferencePlugin {
options: ContainerReferencePluginOptions,
}

#[async_trait]
impl Plugin for ContainerReferencePlugin {
async fn factorize(
&self,
_ctx: PluginContext,
args: FactorizeArgs<'_>,
_job_ctx: &mut NormalModuleFactoryContext,
) -> PluginFactorizeHookOutput {
let request = args.dependency.request();
if !request.contains("!") {

Check failure on line 37 in crates/rspack_core/src/mf/container/container_reference_plugin.rs

View workflow job for this annotation

GitHub Actions / Rust check

single-character string constant used as pattern
for (key, config) in &self.options.remotes {

Check failure on line 38 in crates/rspack_core/src/mf/container/container_reference_plugin.rs

View workflow job for this annotation

GitHub Actions / Rust check

unused variable: `key`

Check failure on line 38 in crates/rspack_core/src/mf/container/container_reference_plugin.rs

View workflow job for this annotation

GitHub Actions / Rust check

unused variable: `config`
// if request.starts_with(key)
}
}
Ok(None)
}

impl Plugin for ContainerReferencePlugin {}
fn runtime_requirements_in_tree(
&self,
_ctx: PluginContext,
args: &mut AdditionalChunkRuntimeRequirementsArgs,
) -> PluginAdditionalChunkRuntimeRequirementsOutput {
if args
.runtime_requirements
.contains(RuntimeGlobals::ENSURE_CHUNK_HANDLERS)
{
args.runtime_requirements.insert(RuntimeGlobals::MODULE);
args
.runtime_requirements
.insert(RuntimeGlobals::MODULE_FACTORIES_ADD_ONLY);
args
.runtime_requirements
.insert(RuntimeGlobals::HAS_OWN_PROPERTY);
args
.runtime_requirements
.insert(RuntimeGlobals::INITIALIZE_SHARING);
args
.runtime_requirements
.insert(RuntimeGlobals::SHARE_SCOPE_MAP);
args
.compilation
.add_runtime_module(args.chunk, RemoteRuntimeModule::default().boxed());
}
Ok(())
}
}
4 changes: 4 additions & 0 deletions crates/rspack_core/src/mf/container/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ mod container_entry_module_factory;
mod container_exposed_dependency;
mod container_plugin;
mod container_reference_plugin;
mod remote_runtime_module;
mod remote_to_external_dependency;

pub use container_entry_module_factory::ContainerEntryModuleFactory;
pub use container_plugin::{ContainerPlugin, ContainerPluginOptions, ExposeOptions};
pub use remote_runtime_module::RemoteRuntimeModule;
pub use remote_to_external_dependency::RemoteToExternalDependency;
35 changes: 35 additions & 0 deletions crates/rspack_core/src/mf/container/remote_runtime_module.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use rspack_identifier::Identifier;
use rspack_sources::BoxSource;

use crate::{impl_runtime_module, ChunkUkey, Compilation, RuntimeModule};

#[derive(Debug, Eq)]
pub struct RemoteRuntimeModule {
id: Identifier,
chunk: Option<ChunkUkey>,
}

impl Default for RemoteRuntimeModule {
fn default() -> Self {
Self {
id: Identifier::from("webpack/runtime/remotes_loading"),
chunk: None,
}
}
}

impl RuntimeModule for RemoteRuntimeModule {
fn name(&self) -> Identifier {
self.id
}

fn generate(&self, compilation: &Compilation) -> BoxSource {

Check failure on line 26 in crates/rspack_core/src/mf/container/remote_runtime_module.rs

View workflow job for this annotation

GitHub Actions / Rust check

unused variable: `compilation`
todo!()
}

fn attach(&mut self, chunk: ChunkUkey) {
self.chunk = Some(chunk);
}
}

impl_runtime_module!(RemoteRuntimeModule);
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use crate::{
AsContextDependency, AsDependencyTemplate, Dependency, DependencyCategory, DependencyId,
DependencyType, ModuleDependency,
};

#[derive(Debug, Clone)]
pub struct RemoteToExternalDependency {
id: DependencyId,
request: String,
}

impl RemoteToExternalDependency {
pub fn new(request: String) -> Self {
Self {
id: DependencyId::new(),
request,
}
}
}

impl Dependency for RemoteToExternalDependency {
fn dependency_debug_name(&self) -> &'static str {
"RemoteToExternalDependency"
}

fn id(&self) -> &DependencyId {
&self.id
}

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

fn category(&self) -> &DependencyCategory {
&DependencyCategory::Esm
}
}

impl ModuleDependency for RemoteToExternalDependency {
fn request(&self) -> &str {
&self.request
}
}

impl AsContextDependency for RemoteToExternalDependency {}
impl AsDependencyTemplate for RemoteToExternalDependency {}

0 comments on commit 73d151b

Please sign in to comment.