Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mf): add version check warning for sharing #5116

Merged
merged 4 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions crates/rspack_core/src/compiler/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ impl WorkerTask for FactorizeTask {
})
.await
{
Ok(res) => {
let (result, diagnostics) = res.split_into_parts();

Ok((result, diagnostics)) => {
if let Some(current_profile) = &factorize_task_result.current_profile {
current_profile.mark_factory_end();
}
Expand Down
85 changes: 57 additions & 28 deletions crates/rspack_core/src/context_module_factory.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;
use std::sync::{Arc, Mutex};

use rspack_error::{IntoTWithDiagnosticArray, Result, TWithDiagnosticArray};
use rspack_error::{Diagnosable, Diagnostic, Result};
use tracing::instrument;

use crate::{
Expand All @@ -14,6 +14,7 @@ use crate::{
pub struct ContextModuleFactory {
plugin_driver: SharedPluginDriver,
cache: Arc<Cache>,
diagnostics: Mutex<Vec<Diagnostic>>,
}

#[async_trait::async_trait]
Expand All @@ -22,11 +23,19 @@ impl ModuleFactory for ContextModuleFactory {
async fn create(
&self,
mut data: ModuleFactoryCreateData,
) -> Result<TWithDiagnosticArray<ModuleFactoryResult>> {
) -> Result<(ModuleFactoryResult, Vec<Diagnostic>)> {
let take_diagnostic = || {
self
.diagnostics
.lock()
.expect("should lock diagnostics")
.drain(..)
.collect::<Vec<_>>()
};
if let Ok(Some(before_resolve_result)) = self.before_resolve(&mut data).await {
return Ok(before_resolve_result);
return Ok((before_resolve_result, take_diagnostic()));
}
Ok(self.resolve(data).await?)
Ok((self.resolve(data).await?, take_diagnostic()))
}
}

Expand All @@ -35,13 +44,14 @@ impl ContextModuleFactory {
Self {
plugin_driver,
cache,
diagnostics: Default::default(),
}
}

async fn before_resolve(
&self,
data: &mut ModuleFactoryCreateData,
) -> Result<Option<TWithDiagnosticArray<ModuleFactoryResult>>> {
) -> Result<Option<ModuleFactoryResult>> {
let dependency = data
.dependency
.as_context_dependency_mut()
Expand All @@ -66,19 +76,14 @@ impl ContextModuleFactory {
format!("Failed to resolve {specifier}"),
)
.boxed();
return Ok(Some(
ModuleFactoryResult::new(missing_module).with_empty_diagnostic(),
));
return Ok(Some(ModuleFactoryResult::new(missing_module)));
}
data.context = before_resolve_args.context.into();
dependency.set_request(before_resolve_args.request);
Ok(None)
}

async fn resolve(
&self,
data: ModuleFactoryCreateData,
) -> Result<TWithDiagnosticArray<ModuleFactoryResult>> {
async fn resolve(&self, data: ModuleFactoryCreateData) -> Result<ModuleFactoryResult> {
let dependency = data
.dependency
.as_context_dependency()
Expand Down Expand Up @@ -134,7 +139,7 @@ impl ContextModuleFactory {
Default::default(),
)
.boxed();
return Ok(ModuleFactoryResult::new(raw_module).with_empty_diagnostic());
return Ok(ModuleFactoryResult::new(raw_module));
}
Err(ResolveError(runtime_error, internal_error)) => {
let ident = format!("{}{specifier}", data.context);
Expand All @@ -146,23 +151,47 @@ impl ContextModuleFactory {
runtime_error,
)
.boxed();
self.add_diagnostic(internal_error.into());

return Ok(
ModuleFactoryResult::new(missing_module).with_diagnostic(vec![internal_error.into()]),
);
return Ok(ModuleFactoryResult::new(missing_module));
}
};

Ok(
ModuleFactoryResult {
module,
file_dependencies,
missing_dependencies,
context_dependencies,
factory_meta,
from_cache,
}
.with_empty_diagnostic(),
)
Ok(ModuleFactoryResult {
module,
file_dependencies,
missing_dependencies,
context_dependencies,
factory_meta,
from_cache,
})
}
}

impl Diagnosable for ContextModuleFactory {
fn add_diagnostic(&self, diagnostic: Diagnostic) {
self
.diagnostics
.lock()
.expect("should be able to lock diagnostics")
.push(diagnostic);
}

fn add_diagnostics(&self, mut diagnostics: Vec<Diagnostic>) {
self
.diagnostics
.lock()
.expect("should be able to lock diagnostics")
.append(&mut diagnostics);
}

fn clone_diagnostics(&self) -> Vec<Diagnostic> {
self
.diagnostics
.lock()
.expect("should be able to lock diagnostics")
.iter()
.cloned()
.collect()
}
}
16 changes: 6 additions & 10 deletions crates/rspack_core/src/ignore_error_module_factory.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::sync::Arc;

use rspack_error::IntoTWithDiagnosticArray;
use rspack_error::Result;
use rspack_error::TWithDiagnosticArray;
use rspack_error::{impl_empty_diagnosable_trait, Diagnostic, Result};

use crate::{ModuleFactory, ModuleFactoryCreateData, ModuleFactoryResult, NormalModuleFactory};

Expand All @@ -16,12 +14,10 @@ impl ModuleFactory for IgnoreErrorModuleFactory {
async fn create(
&self,
data: ModuleFactoryCreateData,
) -> Result<TWithDiagnosticArray<ModuleFactoryResult>> {
let (factory_result, _) = self
.normal_module_factory
.create(data)
.await?
.split_into_parts();
Ok(factory_result.with_diagnostic(vec![]))
) -> Result<(ModuleFactoryResult, Vec<Diagnostic>)> {
let (factory_result, _) = self.normal_module_factory.create(data).await?;
Ok((factory_result, vec![]))
}
}

impl_empty_diagnosable_trait!(IgnoreErrorModuleFactory);
6 changes: 3 additions & 3 deletions crates/rspack_core/src/module_factory.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{fmt::Debug, path::PathBuf};

use rspack_error::{Result, TWithDiagnosticArray};
use rspack_error::{Diagnosable, Diagnostic, Result};
use rustc_hash::FxHashSet as HashSet;

use crate::{BoxDependency, BoxModule, Context, FactoryMeta, ModuleIdentifier, Resolve};
Expand Down Expand Up @@ -80,9 +80,9 @@ impl ModuleFactoryResult {
}

#[async_trait::async_trait]
pub trait ModuleFactory: Debug + Sync + Send {
pub trait ModuleFactory: Debug + Sync + Send + Diagnosable {
async fn create(
&self,
data: ModuleFactoryCreateData,
) -> Result<TWithDiagnosticArray<ModuleFactoryResult>>;
) -> Result<(ModuleFactoryResult, Vec<Diagnostic>)>;
}
Loading
Loading