Skip to content
Draft
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
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ cow-utils = { version = "0.1.3", default-features = false }

criterion = { package = "codspeed-criterion-compat", default-features = false, version = "4.7.0", features = ["async_tokio"] }

css-module-lexer = { version = "0.1.0", default-features = false }
css-module-lexer = { git = "https://github.com/intellild/css-module-lexer.git", rev = "0ae2137f78a0aabebf0c1ea076f936078e66892a", default-features = false }
dashmap = { version = "6.2.1", default-features = false }
derive_more = { version = "2.1.1", default-features = false }
dunce = { version = "1.0.5", default-features = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod execute;
mod module_tracker;
mod overwrite;

use rspack_collections::{Identifier, IdentifierDashMap, IdentifierDashSet};
use rspack_collections::{Identifier, IdentifierDashMap, IdentifierDashSet, IdentifierSet};
use rspack_error::Result;
use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet};
use tokio::{
Expand Down Expand Up @@ -45,6 +45,7 @@ pub struct ModuleExecutor {
module_assets: IdentifierDashMap<HashMap<String, CompilationAsset>>,
code_generated_modules: IdentifierDashSet,
pub executed_runtime_modules: IdentifierDashMap<ExecutedRuntimeModule>,
force_build_modules: IdentifierSet,
}

impl Default for ModuleExecutor {
Expand All @@ -58,16 +59,46 @@ impl Default for ModuleExecutor {
module_assets: Default::default(),
code_generated_modules: Default::default(),
executed_runtime_modules: Default::default(),
force_build_modules: Default::default(),
}
}
}

impl ModuleExecutor {
pub fn is_active(&self) -> bool {
self.event_sender.is_some()
}

pub fn force_rebuild_imports_from_origins(&mut self, origins: &IdentifierSet) {
if origins.is_empty() {
return;
}
let Some(make_artifact) = self.make_artifact.try_read() else {
return;
};
let module_graph = make_artifact.get_module_graph();
self.force_build_modules.extend(
self
.entries
.iter()
.filter(|(meta, _)| origins.contains(&meta.origin_module_identifier))
.filter_map(|(_, dep_id)| {
module_graph
.module_identifier_by_dependency_id(dep_id)
.copied()
}),
);
}

pub async fn before_build_module_graph(&mut self, compilation: &Compilation) -> Result<()> {
let mut make_artifact = self.make_artifact.steal();
let mut exports_info_artifact = self.exports_info_artifact.steal();
let mut params = Vec::with_capacity(5);
params.push(UpdateParam::CheckNeedBuild);
let force_build_modules = std::mem::take(&mut self.force_build_modules);
if !force_build_modules.is_empty() {
params.push(UpdateParam::ForceBuildModules(force_build_modules));
}
if !compilation.modified_files.is_empty() {
params.push(UpdateParam::ModifiedFiles(
compilation.modified_files.clone(),
Expand Down
17 changes: 17 additions & 0 deletions crates/rspack_core/src/compilation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,17 @@ impl Compilation {
exports_info_artifact: &mut ExportsInfoArtifact,
f: impl Fn(Vec<&BoxModule>) -> T,
) -> Result<T> {
let mut should_stop_module_executor = false;
if let Some(module_executor) = &mut self.module_executor
&& !module_executor.is_active()
{
let mut module_executor = std::mem::take(module_executor);
module_executor.force_rebuild_imports_from_origins(&module_identifiers);
module_executor.before_build_module_graph(self).await?;
self.module_executor = Some(module_executor);
should_stop_module_executor = true;
}

let artifact = self.build_module_graph_artifact.steal();

// https://github.com/webpack/webpack/blob/19ca74127f7668aaf60d59f4af8fcaee7924541a/lib/Compilation.js#L2462C21-L2462C25
Expand All @@ -1073,6 +1084,12 @@ impl Compilation {
*exports_info_artifact = updated_exports_info_artifact;
self.build_module_graph_artifact = artifact.into();

if should_stop_module_executor && let Some(module_executor) = &mut self.module_executor {
let mut module_executor = std::mem::take(module_executor);
module_executor.after_build_module_graph(self).await?;
self.module_executor = Some(module_executor);
}

let module_graph = self.get_module_graph();
Ok(f(module_identifiers
.into_iter()
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_core/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ pub struct MinifyError(pub Error);
impl From<MinifyError> for Error {
fn from(value: MinifyError) -> Error {
let mut error = rspack_error::error!("Chunk minification failed:");
error.severity = value.0.severity;
error.code = if value.0.is_warn() {
Some("ChunkMinificationWarning".into())
} else {
Expand Down
47 changes: 21 additions & 26 deletions crates/rspack_loader_lightningcss/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use cow_utils::CowUtils;
use derive_more::Debug;
pub use lightningcss;
use lightningcss::{
error::{ParserError, SelectorError},
printer::{PrinterOptions, PseudoClasses},
stylesheet::{MinifyOptions, ParserFlags, ParserOptions, StyleSheet},
targets::{Features, Targets},
Expand All @@ -21,7 +22,7 @@ use rspack_core::{
SourceMapSourceOptions, encode_mappings,
},
};
use rspack_error::{Result, ToStringResultToRspackResultExt};
use rspack_error::{Diagnostic, Result, ToStringResultToRspackResultExt};
use rspack_loader_runner::Identifier;
use tokio::sync::Mutex;

Expand Down Expand Up @@ -99,31 +100,25 @@ impl LightningCssLoader {
flags: parser_flags,
};
let stylesheet = StyleSheet::parse(&content_str, option.clone()).to_rspack_result()?;
// FIXME: Disable the warnings for now, cause it cause too much positive-negative warnings,
// enable when we have a better way to handle it.

// if let Some(warnings) = warnings {
// #[allow(clippy::unwrap_used)]
// let warnings = warnings.read().unwrap();
// for warning in warnings.iter() {
// if matches!(
// warning.kind,
// lightningcss::error::ParserError::SelectorError(
// lightningcss::error::SelectorError::UnsupportedPseudoClass(_)
// ) | lightningcss::error::ParserError::SelectorError(
// lightningcss::error::SelectorError::UnsupportedPseudoElement(_)
// )
// ) {
// // ignore parsing errors on pseudo class from lightningcss-loader
// // to allow pseudo class in CSS modules and Vue.
// continue;
// }
// loader_context.emit_diagnostic(Diagnostic::warn(
// "builtin:lightningcss-loader".to_string(),
// format!("LightningCSS parse warning: {}", warning),
// ));
// }
// }
if let Some(warnings) = warnings {
#[allow(clippy::unwrap_used)]
let warnings = warnings.read().unwrap();
for warning in warnings.iter() {
if matches!(
warning.kind,
ParserError::SelectorError(
SelectorError::UnsupportedPseudoClass(_) | SelectorError::UnsupportedPseudoElement(_)
)
) {
// Keep CSS modules and framework pseudo selectors usable.
continue;
}
loader_context.emit_diagnostic(Diagnostic::warn(
"builtin:lightningcss-loader".to_string(),
format!("LightningCSS parse warning: {warning}"),
));
}
}

let mut stylesheet = to_static(
stylesheet,
Expand Down
59 changes: 40 additions & 19 deletions crates/rspack_plugin_css/src/parser_and_generator/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,13 +772,13 @@ impl<'a, 'g> CssModuleGenerator<'a, 'g> {
for CssExport {
ident,
from,
id: _,
id,
orig_name: _,
} in elements
{
let part = match from {
None => self.render_local_css_export(ident),
Some(from_name) => self.render_standard_css_reexport(ident, from_name),
Some(from_name) => self.render_standard_css_reexport(ident, from_name, id.as_ref()),
};
push_joined(&mut content, &part, " + \" \" + ");
}
Expand All @@ -791,27 +791,48 @@ impl<'a, 'g> CssModuleGenerator<'a, 'g> {
json_stringify_str(&ident)
}

fn render_standard_css_reexport(&mut self, ident: &str, from_name: &str) -> String {
fn render_standard_css_reexport(
&mut self,
ident: &str,
from_name: &str,
id: Option<&DependencyId>,
) -> String {
let compilation = self.generate_context.compilation;
let module_graph = compilation.get_module_graph();
let from = self
.module
.get_dependencies()
.iter()
.find_map(|id| {
let dependency = module_graph.dependency_by_id(id);
let request = dependency_request(dependency);
if let Some(request) = request
&& request == from_name
{
return module_graph.module_graph_module_by_dependency_id(id);
}
None
let find_target_module =
|dep_id: &DependencyId| module_graph.get_module_by_dependency_id(dep_id);
let from = id
.and_then(find_target_module)
.or_else(|| {
self.module.get_dependencies().iter().find_map(|id| {
let dependency = module_graph.dependency_by_id(id);
let request = dependency_request(dependency);
if let Some(request) = request
&& request == from_name
{
return find_target_module(id);
}
None
})
})
.expect("should have css from module");
.unwrap_or_else(|| {
let dependency_requests = self
.module
.get_dependencies()
.iter()
.filter_map(|id| {
let dependency = module_graph.dependency_by_id(id);
dependency_request(dependency)
})
.collect::<Vec<_>>();
panic!(
"should have css from module: ident={ident}, from={from_name}, id={id:?}, dependency_requests={dependency_requests:?}"
);
});

let from_used_name = self.stringified_used_export_name(from.module_identifier, ident, true);
self.render_require_property_access(from.module_identifier, &from_used_name)
let from_identifier = from.identifier();
let from_used_name = self.stringified_used_export_name(from_identifier, ident, true);
self.render_require_property_access(from_identifier, &from_used_name)
}

fn render_concat_export_content<'b>(
Expand Down
Loading
Loading