Skip to content
Open
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: 0 additions & 4 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion crates/rspack_binding_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ once_cell = { workspace = true }
rayon = { workspace = true }
regex = { workspace = true }
rspack_browser = { workspace = true, optional = true }
rspack_cacheable = { workspace = true }
rspack_ids = { workspace = true }
rspack_javascript_compiler = { workspace = true }
rspack_loader_lightningcss = { workspace = true }
Expand Down
15 changes: 0 additions & 15 deletions crates/rspack_binding_api/src/modules/normal_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,6 @@ impl NormalModule {
ReadonlyResourceDataWrapper::from(resource_resolved_data.clone()),
)?
});
let loaders = Object::from_raw(env.raw(), unsafe {
ToNapiValue::to_napi_value(
env.raw(),
module
.loaders()
.iter()
.map(JsLoaderItem::from)
.collect::<Vec<_>>(),
)?
});

#[js_function]
pub fn match_resource_getter(ctx: CallContext<'_>) -> napi::Result<Either<&str, ()>> {
Expand Down Expand Up @@ -115,11 +105,6 @@ impl NormalModule {
.with_utf8_name("resourceResolveData")?
.with_value(&resource_resolve_data),
);
properties.push(
napi::Property::new()
.with_utf8_name("loaders")?
.with_value(&loaders),
);
properties.push(
napi::Property::new()
.with_utf8_name("matchResource")?
Expand Down
8 changes: 1 addition & 7 deletions crates/rspack_binding_api/src/plugins/js_loader/resolver.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
use std::{borrow::Cow, sync::Arc};

use rspack_cacheable::{
cacheable, cacheable_dyn,
with::{AsOption, AsRefStr},
};
use rspack_collections::Identifier;
use rspack_core::{
BoxLoader, Context, Loader, ModuleRuleUseLoader, NormalModuleFactoryResolveLoader, ResolveResult,
Expand All @@ -15,14 +11,12 @@ use rspack_paths::Utf8Path;

use super::{JsLoaderRspackPlugin, JsLoaderRspackPluginInner};

#[cacheable]
#[derive(Debug)]
pub struct JsLoader(
pub Identifier,
/* LoaderType */ #[cacheable(with=AsOption<AsRefStr>)] pub Option<Cow<'static, str>>,
/* LoaderType */ pub Option<Cow<'static, str>>,
);

#[cacheable_dyn]
impl Loader<RunnerContext> for JsLoader {
fn identifier(&self) -> Identifier {
self.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use derive_more::Debug;
use rspack_error::Result;

use super::{TaskContext, build::BuildTask, lazy::ProcessUnlazyDependenciesTask};
use crate::{
BoxDependency, Module, ModuleIdentifier, ModuleProfile,
BoxDependency, BoxLoader, Module, ModuleIdentifier, ModuleProfile,
compilation::make::ForwardedIdSet,
module_graph::{ModuleGraph, ModuleGraphModule},
utils::task_loop::{Task, TaskResult, TaskType},
Expand All @@ -12,6 +13,8 @@ use crate::{
pub struct AddTask {
pub original_module_identifier: Option<ModuleIdentifier>,
pub module: Box<dyn Module>,
#[debug(skip)]
pub loaders: Vec<BoxLoader>,
pub module_graph_module: Box<ModuleGraphModule>,
pub dependencies: Vec<BoxDependency>,
pub current_profile: Option<ModuleProfile>,
Expand Down Expand Up @@ -112,6 +115,7 @@ impl Task<TaskContext> for AddTask {
compiler_id: context.compiler_id,
compilation_id: context.compilation_id,
module: self.module,
loaders: self.loaders,
current_profile: self.current_profile,
resolver_factory: context.resolver_factory.clone(),
compiler_options: context.compiler_options.clone(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use std::{collections::VecDeque, sync::Arc};

use derive_more::Debug;
use rspack_fs::ReadableFileSystem;
use rustc_hash::FxHashSet;

use super::{
TaskContext, lazy::ProcessUnlazyDependenciesTask, process_dependencies::ProcessDependenciesTask,
};
use crate::{
AsyncDependenciesBlock, BoxDependency, BuildContext, BuildResult, CompilationId, CompilerId,
CompilerOptions, DependencyParents, Module, ModuleProfile, ResolverFactory, SharedPluginDriver,
AsyncDependenciesBlock, BoxDependency, BoxLoader, BuildContext, BuildResult, CompilationId,
CompilerId, CompilerOptions, DependencyParents, Module, ModuleProfile, ResolverFactory,
SharedPluginDriver,
compilation::make::{ForwardedIdSet, HasLazyDependencies, LazyDependencies},
utils::{
ResourceId,
Expand All @@ -21,6 +23,8 @@ pub struct BuildTask {
pub compiler_id: CompilerId,
pub compilation_id: CompilationId,
pub module: Box<dyn Module>,
#[debug(skip)]
pub loaders: Vec<BoxLoader>,
pub current_profile: Option<ModuleProfile>,
pub resolver_factory: Arc<ResolverFactory>,
pub compiler_options: Arc<CompilerOptions>,
Expand All @@ -43,6 +47,7 @@ impl Task<TaskContext> for BuildTask {
plugin_driver,
mut current_profile,
mut module,
loaders,
fs,
forwarded_ids,
} = *self;
Expand All @@ -65,6 +70,7 @@ impl Task<TaskContext> for BuildTask {
resolver_factory: resolver_factory.clone(),
plugin_driver: plugin_driver.clone(),
fs: fs.clone(),
loaders,
},
None,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ impl Task<TaskContext> for FactorizeResultTask {
Ok(vec![Box::new(AddTask {
original_module_identifier,
module,
loaders: factory_result.loaders,
module_graph_module: Box::new(mgm),
dependencies,
current_profile,
Expand Down
4 changes: 1 addition & 3 deletions crates/rspack_core/src/context_module_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,7 @@ impl ContextModuleFactory {
data.add_missing_dependencies(missing_dependencies);
// data.add_context_dependencies(context_dependencies);

let module_factory_result = ModuleFactoryResult {
module: Some(module),
};
let module_factory_result = ModuleFactoryResult::new_with_module(module);
Ok((module_factory_result, context_module_options))
}

Expand Down
7 changes: 4 additions & 3 deletions crates/rspack_core/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet};
use serde::Serialize;

use crate::{
AsyncDependenciesBlock, BindingCell, BoxDependency, BoxDependencyTemplate, BoxModuleDependency,
ChunkGraph, ChunkUkey, CodeGenerationResult, CollectedTypeScriptInfo, Compilation,
CompilationAsset, CompilationId, CompilerId, CompilerOptions, ConcatenationScope,
AsyncDependenciesBlock, BindingCell, BoxDependency, BoxDependencyTemplate, BoxLoader,
BoxModuleDependency, ChunkGraph, ChunkUkey, CodeGenerationResult, CollectedTypeScriptInfo,
Compilation, CompilationAsset, CompilationId, CompilerId, CompilerOptions, ConcatenationScope,
ConnectionState, Context, ContextModule, DependenciesBlock, DependencyId, ExportProvided,
ExternalModule, ModuleGraph, ModuleGraphCacheArtifact, ModuleLayer, ModuleType, NormalModule,
PrefetchExportsInfoMode, RawModule, Resolve, ResolverFactory, RuntimeSpec, SelfModule,
Expand All @@ -45,6 +45,7 @@ pub struct BuildContext {
pub resolver_factory: Arc<ResolverFactory>,
pub plugin_driver: SharedPluginDriver,
pub fs: Arc<dyn ReadableFileSystem>,
pub loaders: Vec<BoxLoader>,
}

#[cacheable]
Expand Down
17 changes: 8 additions & 9 deletions crates/rspack_core/src/module_factory.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::{fmt::Debug, sync::Arc};
use std::sync::Arc;

use derive_more::Debug;
use rspack_error::{Diagnostic, Result};
use rspack_paths::{ArcPath, ArcPathSet};

use crate::{
BoxDependency, BoxModule, CompilationId, CompilerId, CompilerOptions, Context, ModuleIdentifier,
ModuleLayer, Resolve, ResolverFactory,
BoxDependency, BoxLoader, BoxModule, CompilationId, CompilerId, CompilerOptions, Context,
ModuleIdentifier, ModuleLayer, Resolve, ResolverFactory,
};

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -69,22 +70,20 @@ impl ModuleFactoryCreateData {
#[derive(Debug, Default)]
pub struct ModuleFactoryResult {
pub module: Option<BoxModule>,
#[debug(skip)]
pub loaders: Vec<BoxLoader>,
}

impl ModuleFactoryResult {
pub fn new_with_module(module: BoxModule) -> Self {
Self {
module: Some(module),
loaders: vec![],
}
}

pub fn module(mut self, module: Option<BoxModule>) -> Self {
self.module = module;
self
}
}

#[async_trait::async_trait]
pub trait ModuleFactory: Debug + Sync + Send {
pub trait ModuleFactory: std::fmt::Debug + Sync + Send {
Copy link
Preview

Copilot AI Sep 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The trait bound should use the standard Debug import instead of the fully qualified path std::fmt::Debug. Since derive_more::Debug is imported at the top, consider using just Debug for consistency with the rest of the codebase.

Suggested change
pub trait ModuleFactory: std::fmt::Debug + Sync + Send {
pub trait ModuleFactory: Debug + Sync + Send {

Copilot uses AI. Check for mistakes.

async fn create(&self, data: &mut ModuleFactoryCreateData) -> Result<ModuleFactoryResult>;
}
30 changes: 11 additions & 19 deletions crates/rspack_core/src/normal_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ use serde_json::json;
use tracing::{Instrument, info_span};

use crate::{
AsyncDependenciesBlockIdentifier, BoxDependencyTemplate, BoxLoader, BoxModule,
BoxModuleDependency, BuildContext, BuildInfo, BuildMeta, BuildResult, ChunkGraph,
CodeGenerationResult, Compilation, ConcatenationScope, ConnectionState, Context,
DependenciesBlock, DependencyId, FactoryMeta, GenerateContext, GeneratorOptions, LibIdentOptions,
Module, ModuleGraph, ModuleGraphCacheArtifact, ModuleIdentifier, ModuleLayer, ModuleType,
OutputOptions, ParseContext, ParseResult, ParserAndGenerator, ParserOptions, Resolve,
RspackLoaderRunnerPlugin, RunnerContext, RuntimeGlobals, RuntimeSpec, SourceType, contextify,
diagnostics::ModuleBuildError, get_context, impl_module_meta_info, module_update_hash,
AsyncDependenciesBlockIdentifier, BoxDependencyTemplate, BoxModule, BoxModuleDependency,
BuildContext, BuildInfo, BuildMeta, BuildResult, ChunkGraph, CodeGenerationResult, Compilation,
ConcatenationScope, ConnectionState, Context, DependenciesBlock, DependencyId, FactoryMeta,
GenerateContext, GeneratorOptions, LibIdentOptions, Module, ModuleGraph,
ModuleGraphCacheArtifact, ModuleIdentifier, ModuleLayer, ModuleType, OutputOptions, ParseContext,
ParseResult, ParserAndGenerator, ParserOptions, Resolve, RspackLoaderRunnerPlugin, RunnerContext,
RuntimeGlobals, RuntimeSpec, SourceType, contextify, diagnostics::ModuleBuildError, get_context,
impl_module_meta_info, module_update_hash,
};

#[cacheable]
Expand Down Expand Up @@ -121,8 +121,6 @@ pub struct NormalModule {
/// Resource data (path, query, fragment etc.)
resource_data: Arc<ResourceData>,
/// Loaders for the module
#[debug(skip)]
loaders: Vec<BoxLoader>,

/// Built source of this module (passed with loaders)
#[cacheable(with=AsOption<AsPreset>)]
Expand Down Expand Up @@ -180,7 +178,6 @@ impl NormalModule {
match_resource: Option<ResourceData>,
resource_data: Arc<ResourceData>,
resolve_options: Option<Arc<Resolve>>,
loaders: Vec<BoxLoader>,
context: Option<Context>,
) -> Self {
let module_type = module_type.into();
Expand All @@ -201,7 +198,6 @@ impl NormalModule {
match_resource,
resource_data,
resolve_options,
loaders,
source: None,
debug_id: DEBUG_ID.fetch_add(1, Ordering::Relaxed),

Expand Down Expand Up @@ -249,10 +245,6 @@ impl NormalModule {
&self.raw_request
}

pub fn loaders(&self) -> &[BoxLoader] {
&self.loaders
}

pub fn parser_and_generator(&self) -> &dyn ParserAndGenerator {
&*self.parser_and_generator
}
Expand Down Expand Up @@ -373,7 +365,7 @@ impl Module for NormalModule {
perfetto.process_name = format!("Rspack Build Detail"),
module.resource = self.resource_resolved_data().resource(),
module.identifier = self.identifier().as_str(),
module.loaders = ?self.loaders.iter().map(|l| l.identifier().as_str()).collect::<Vec<_>>())
loaders = ?build_context.loaders.iter().map(|l| l.identifier().as_str()).collect::<Vec<_>>())
)]
async fn build(
&mut self,
Expand Down Expand Up @@ -402,7 +394,7 @@ impl Module for NormalModule {
});

let (mut loader_result, err) = run_loaders(
self.loaders.clone(),
build_context.loaders.clone(),
self.resource_data.clone(),
Some(plugin.clone()),
RunnerContext {
Expand Down Expand Up @@ -538,7 +530,7 @@ impl Module for NormalModule {
module_layer: self.layer.as_ref(),
module_user_request: &self.user_request,
module_source_map_kind: *self.get_source_map_kind(),
loaders: &self.loaders,
loaders: &build_context.loaders,
resource_data: &self.resource_data,
compiler_options: &build_context.compiler_options,
additional_data: loader_result.additional_data,
Expand Down
6 changes: 4 additions & 2 deletions crates/rspack_core/src/normal_module_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,6 @@ impl NormalModuleFactory {
match_resource_data,
Arc::new(create_data.resource_resolve_data.clone()),
resolved_resolve_options,
loaders,
create_data.context.clone().map(|x| x.into()),
)
.boxed()
Expand All @@ -587,7 +586,10 @@ impl NormalModuleFactory {
data.add_file_dependencies(file_dependencies);
data.add_missing_dependencies(missing_dependencies);

Ok(Some(ModuleFactoryResult::new_with_module(module)))
Ok(Some(ModuleFactoryResult {
module: Some(module),
loaders,
}))
Comment on lines +589 to +592
Copy link
Preview

Copilot AI Sep 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This manual struct construction could be replaced with a more explicit constructor method. Consider adding a new_with_module_and_loaders method to ModuleFactoryResult for better API consistency.

Suggested change
Ok(Some(ModuleFactoryResult {
module: Some(module),
loaders,
}))
Ok(Some(ModuleFactoryResult::new_with_module_and_loaders(Some(module), loaders)))

Copilot uses AI. Check for mistakes.

}

async fn calculate_module_rules<'a>(
Expand Down
4 changes: 0 additions & 4 deletions crates/rspack_loader_lightningcss/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use lightningcss::{
targets::{Features, Targets},
traits::IntoOwned,
};
use rspack_cacheable::{cacheable, cacheable_dyn, with::Skip};
use rspack_core::{
Loader, LoaderContext, RunnerContext,
rspack_sources::{Mapping, OriginalLocation, SourceMap, encode_mappings},
Expand All @@ -30,12 +29,10 @@ pub const LIGHTNINGCSS_LOADER_IDENTIFIER: &str = "builtin:lightningcss-loader";

pub type LightningcssLoaderVisitor = Box<dyn Send + Fn(&mut StyleSheet<'static, 'static>)>;

#[cacheable]
#[derive(Debug)]
pub struct LightningCssLoader {
id: Identifier,
#[debug(skip)]
#[cacheable(with=Skip)]
visitors: Option<Mutex<Vec<LightningcssLoaderVisitor>>>,
config: Config,
}
Expand Down Expand Up @@ -258,7 +255,6 @@ impl LightningCssLoader {
}
}

#[cacheable_dyn]
#[async_trait::async_trait]
impl Loader<RunnerContext> for LightningCssLoader {
fn identifier(&self) -> rspack_loader_runner::Identifier {
Expand Down
1 change: 0 additions & 1 deletion crates/rspack_loader_preact_refresh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ version.workspace = true

[dependencies]
async-trait = { workspace = true }
rspack_cacheable = { workspace = true }
rspack_core = { workspace = true }
rspack_error = { workspace = true }
rspack_hook = { workspace = true }
Expand Down
Loading
Loading