-
-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
158 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 70 additions & 3 deletions
73
crates/rspack_core/src/mf/container/container_reference_plugin.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("!") { | ||
for (key, config) in &self.options.remotes { | ||
Check failure on line 38 in crates/rspack_core/src/mf/container/container_reference_plugin.rs GitHub Actions / Rust check
|
||
// 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(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
crates/rspack_core/src/mf/container/remote_runtime_module.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
todo!() | ||
} | ||
|
||
fn attach(&mut self, chunk: ChunkUkey) { | ||
self.chunk = Some(chunk); | ||
} | ||
} | ||
|
||
impl_runtime_module!(RemoteRuntimeModule); |
46 changes: 46 additions & 0 deletions
46
crates/rspack_core/src/mf/container/remote_to_external_dependency.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |