Skip to content
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
14 changes: 8 additions & 6 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ regex-syntax = { version = "0.8.5", default-features = false, features =
regress = { version = "0.10.4", default-features = false, features = ["pattern"] }
ropey = { version = "1.6.1", default-features = false }
rspack_resolver = { features = ["package_json_raw_json_api", "yarn_pnp"], version = "0.6.4", default-features = false }
rspack_sources = { version = "=0.4.13", default-features = false }
rspack_sources = { version = "0.4.14", default-features = false }
rustc-hash = { version = "2.1.0", default-features = false }
ryu-js = { version = "1.0.2", default-features = false }
scopeguard = { version = "1.2.0", default-features = false }
Expand All @@ -99,6 +99,7 @@ sugar_path = { version = "1.2.0", default-features = false, features =
syn = { version = "2.0.95", default-features = false }
termcolor = { version = "1.4.1", default-features = false }
textwrap = { version = "0.16.1", default-features = false }
thread_local = { version = "1.1.9", default-features = false }
tokio = { version = "1.42.0", default-features = false, features = ["rt", "rt-multi-thread"] }
toml = { version = "0.8.19", default-features = false, features = ["parse", "display"] }
tracing = { version = "0.1.41", default-features = false, features = ["max_level_trace", "release_max_level_trace"] }
Expand Down
4 changes: 2 additions & 2 deletions crates/rspack_binding_api/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{hash::Hash, sync::Arc};

use napi_derive::napi;
use rspack_core::rspack_sources::{
BoxSource, CachedSource, ConcatSource, MapOptions, OriginalSource, RawBufferSource,
BoxSource, CachedSource, ConcatSource, MapOptions, ObjectPool, OriginalSource, RawBufferSource,
RawStringSource, ReplaceSource, Source, SourceExt, SourceMap, SourceMapSource, SourceValue,
WithoutOriginalOptions,
};
Expand Down Expand Up @@ -101,7 +101,7 @@ impl From<JsSourceToJs> for BoxSource {
}

fn to_webpack_map(source: &dyn Source) -> Result<Option<String>> {
let map = source.map(&MapOptions::default());
let map = source.map(&ObjectPool::default(), &MapOptions::default());

map.map(|m| m.to_json()).transpose().to_napi_result()
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use rkyv::{
};
use rspack_macros::enable_cacheable as cacheable;
use rspack_sources::{
BoxSource, RawBufferSource, Source, SourceExt, SourceMap, SourceMapSource, WithoutOriginalOptions,
BoxSource, ObjectPool, RawBufferSource, Source, SourceExt, SourceMap, SourceMapSource,
WithoutOriginalOptions,
};

use super::AsPreset;
Expand Down Expand Up @@ -42,7 +43,7 @@ where
field: &BoxSource,
serializer: &mut S,
) -> Result<Self::Resolver, SerializeError> {
let map = match field.map(&Default::default()) {
let map = match field.map(&ObjectPool::default(), &Default::default()) {
Some(map) => Some(
map
.to_json()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rspack_cacheable::{enable_cacheable as cacheable, from_bytes, to_bytes, with::AsPreset};
use rspack_sources::{BoxSource, RawBufferSource, RawStringSource, SourceExt};
use rspack_sources::{BoxSource, ObjectPool, RawBufferSource, RawStringSource, SourceExt};

#[cacheable]
#[derive(Debug)]
Expand All @@ -12,8 +12,8 @@ fn test_rspack_source() {
let new_data: Data = from_bytes(&bytes, &()).unwrap();
assert_eq!(data.0.buffer(), new_data.0.buffer());
assert_eq!(
data.0.map(&Default::default()),
new_data.0.map(&Default::default())
data.0.map(&ObjectPool::default(), &Default::default()),
new_data.0.map(&ObjectPool::default(), &Default::default())
);
}

Expand Down
4 changes: 2 additions & 2 deletions crates/rspack_core/src/utils/extract_source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,9 @@ pub async fn extract_source_map(
}

// Build the final SourceMap using setter methods - consume resolved_sources to avoid cloning
let (sources_vec, sources_content_vec): (Vec<String>, Vec<String>) = resolved_sources
let (sources_vec, sources_content_vec): (Vec<String>, Vec<Arc<str>>) = resolved_sources
.into_iter()
.map(|(url, content)| (url, content.unwrap_or_default()))
.map(|(url, content)| (url, Arc::from(content.unwrap_or_default())))
.unzip();

source_map.set_sources(sources_vec);
Expand Down
3 changes: 1 addition & 2 deletions crates/rspack_javascript_compiler/src/compiler/stringify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ impl JavaScriptCompiler {
.collect::<Vec<_>>(),
combined_source_map
.source_contents()
.flatten()
.map(ToString::to_string)
.map(|byte_str| Arc::from(byte_str.map(ToString::to_string).unwrap_or_default()))
.collect::<Vec<_>>(),
combined_source_map
.names()
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_loader_lightningcss/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl LightningCssLoader {
source_map
.get_sources_content()
.iter()
.map(ToString::to_string)
.map(|source_content| Arc::from(source_content.to_string()))
.collect::<Vec<_>>(),
source_map
.get_names()
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_plugin_devtool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ rspack_util = { workspace = true }
rustc-hash = { workspace = true }
simd-json = { workspace = true }
sugar_path = { workspace = true }
thread_local = { workspace = true }
tracing = { workspace = true }

[package.metadata.cargo-shear]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rspack_core::{
ChunkGraph, ChunkInitFragments, ChunkUkey, Compilation,
CompilationAdditionalModuleRuntimeRequirements, CompilationParams, CompilerCompilation, Filename,
Module, ModuleIdentifier, PathData, Plugin, RuntimeGlobals,
rspack_sources::{BoxSource, MapOptions, RawStringSource, Source, SourceExt},
rspack_sources::{BoxSource, MapOptions, ObjectPool, RawStringSource, Source, SourceExt},
};
use rspack_error::Result;
use rspack_hash::{RspackHash, RspackHashDigest};
Expand Down Expand Up @@ -107,7 +107,9 @@ async fn eval_source_map_devtool_plugin_render_module_content(
if let Some(cached_source) = self.cache.get(module_hash) {
render_source.source = cached_source.value().clone();
return Ok(());
} else if let Some(mut map) = origin_source.map(&MapOptions::new(self.columns)) {
} else if let Some(mut map) =
origin_source.map(&ObjectPool::default(), &MapOptions::new(self.columns))
{
let source = {
let source = origin_source.source().into_string_lossy();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ use rspack_collections::DatabaseItem;
use rspack_core::{
AssetInfo, Chunk, ChunkUkey, Compilation, CompilationAsset, CompilationProcessAssets, Filename,
Logger, ModuleIdentifier, PathData, Plugin,
rspack_sources::{ConcatSource, MapOptions, RawStringSource, Source, SourceExt},
rspack_sources::{ConcatSource, MapOptions, ObjectPool, RawStringSource, Source, SourceExt},
};
use rspack_error::{Result, ToStringResultToRspackResultExt, error};
use rspack_hash::RspackHash;
use rspack_hook::{plugin, plugin_hook};
use rspack_util::{asset_condition::AssetConditions, base64, identifier::make_paths_absolute};
use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet};
use sugar_path::SugarPath;
use thread_local::ThreadLocal;

use crate::{
ModuleFilenameTemplateFn, ModuleOrSource, generate_debug_id::generate_debug_id,
Expand Down Expand Up @@ -208,6 +209,7 @@ impl SourceMapDevToolPlugin {
let map_options = MapOptions::new(self.columns);
let need_match = self.test.is_some() || self.include.is_some() || self.exclude.is_some();

let tls: ThreadLocal<ObjectPool> = ThreadLocal::new();
let mut mapped_sources = raw_assets
.into_par_iter()
.filter_map(|(file, asset)| {
Expand All @@ -219,7 +221,8 @@ impl SourceMapDevToolPlugin {

if is_match {
asset.get_source().map(|source| {
let source_map = source.map(&map_options);
let object_pool = tls.get_or(ObjectPool::default);
let source_map = source.map(object_pool, &map_options);
(file, source, source_map)
})
} else {
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_plugin_lightning_css_minimizer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ parcel_sourcemap = { workspace = true }
rayon = { workspace = true }
regex = { workspace = true }
ropey = { workspace = true }
thread_local = { workspace = true }
tracing = { workspace = true }

rspack_core = { workspace = true }
Expand Down
11 changes: 8 additions & 3 deletions crates/rspack_plugin_lightning_css_minimizer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ use rspack_core::{
ChunkUkey, Compilation, CompilationChunkHash, CompilationProcessAssets, Plugin,
diagnostics::MinifyError,
rspack_sources::{
MapOptions, RawStringSource, SourceExt, SourceMap, SourceMapSource, SourceMapSourceOptions,
MapOptions, ObjectPool, RawStringSource, SourceExt, SourceMap, SourceMapSource,
SourceMapSourceOptions,
},
};
use rspack_error::{Diagnostic, Result, ToStringResultToRspackResultExt};
use rspack_hash::RspackHash;
use rspack_hook::{plugin, plugin_hook};
use rspack_util::asset_condition::AssetConditions;
use thread_local::ThreadLocal;

static CSS_ASSET_REGEXP: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"\.css(\?.*)?$").expect("Invalid RegExp"));
Expand Down Expand Up @@ -143,6 +145,8 @@ async fn process_assets(&self, compilation: &mut Compilation) -> Result<()> {
let options = &self.options;
let minimizer_options = &self.options.minimizer_options;
let all_warnings: RwLock<Vec<Diagnostic>> = Default::default();

let tls: ThreadLocal<ObjectPool> = ThreadLocal::new();
compilation
.assets_mut()
.par_iter_mut()
Expand All @@ -166,7 +170,8 @@ async fn process_assets(&self, compilation: &mut Compilation) -> Result<()> {

if let Some(original_source) = original.get_source() {
let input = original_source.source().into_string_lossy().into_owned();
let input_source_map = original_source.map(&MapOptions::default());
let object_pool = tls.get_or(ObjectPool::default);
let input_source_map = original_source.map(object_pool, &MapOptions::default());

let mut parser_flags = ParserFlags::empty();
parser_flags.set(
Expand Down Expand Up @@ -279,7 +284,7 @@ async fn process_assets(&self, compilation: &mut Compilation) -> Result<()> {
.to_rspack_result()?,
)
.expect("should be able to generate source-map"),
original_source: Some(input),
original_source: Some(Arc::from(input)),
inner_source_map: input_source_map,
remove_original_source: true,
})
Expand Down
3 changes: 2 additions & 1 deletion crates/rspack_plugin_rsdoctor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ rspack_paths = { workspace = true }
rspack_plugin_devtool = { workspace = true }
rspack_util = { workspace = true }
rustc-hash = { workspace = true }
thread_local = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }

[package.metadata.cargo-shear]
ignored = ["tracing"]

[lints.rust.unexpected_cfgs]
level = "warn"
check-cfg = ['cfg(allocative)']
level = "warn"
9 changes: 7 additions & 2 deletions crates/rspack_plugin_rsdoctor/src/module_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ use rayon::iter::{IntoParallelRefIterator, ParallelBridge, ParallelIterator};
use rspack_collections::{Identifier, IdentifierMap};
use rspack_core::{
BoxModule, ChunkGraph, Compilation, Context, DependencyId, DependencyType, Module, ModuleGraph,
ModuleIdsArtifact, rspack_sources::MapOptions,
ModuleIdsArtifact,
rspack_sources::{MapOptions, ObjectPool},
};
use rspack_paths::Utf8PathBuf;
use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet};
use thread_local::ThreadLocal;

use crate::{
ChunkUkey, ModuleKind, ModuleUkey, RsdoctorDependency, RsdoctorModule, RsdoctorModuleId,
Expand Down Expand Up @@ -125,6 +127,8 @@ pub fn collect_module_original_sources(
compilation: &Compilation,
) -> Vec<RsdoctorModuleOriginalSource> {
let ifs = compilation.input_filesystem.clone();

let tls: ThreadLocal<ObjectPool> = ThreadLocal::new();
modules
.par_iter()
.filter_map(|(module_id, module)| {
Expand All @@ -137,9 +141,10 @@ pub fn collect_module_original_sources(
};
let module_ukey = module_ukeys.get(module_id)?;
let resource = module.resource_resolved_data().resource().to_owned();
let object_pool = tls.get_or(ObjectPool::default);
let source = module
.source()
.and_then(|s| s.map(&MapOptions::default()))
.and_then(|s| s.map(object_pool, &MapOptions::default()))
.and_then(|s| {
let idx = s.sources().iter().position(|s| s.eq(&resource))?;
let source = s.sources_content().get(idx)?;
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_plugin_swc_js_minimizer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ swc_core = { workspace = true, features = [
"ecma_quote",
] }
swc_ecma_minifier = { workspace = true, features = ["concurrent"] }
thread_local = { workspace = true }
tracing = { workspace = true }
8 changes: 6 additions & 2 deletions crates/rspack_plugin_swc_js_minimizer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rspack_core::{
CompilerCompilation, Plugin,
diagnostics::MinifyError,
rspack_sources::{
ConcatSource, MapOptions, RawStringSource, Source, SourceExt, SourceMapSource,
ConcatSource, MapOptions, ObjectPool, RawStringSource, Source, SourceExt, SourceMapSource,
SourceMapSourceOptions,
},
};
Expand All @@ -33,6 +33,7 @@ pub use swc_ecma_minifier::option::{
MangleOptions,
terser::{TerserCompressorOptions, TerserEcmaVersion},
};
use thread_local::ThreadLocal;

const PLUGIN_NAME: &str = "rspack.SwcJsMinimizerRspackPlugin";

Expand Down Expand Up @@ -172,6 +173,8 @@ async fn process_assets(&self, compilation: &mut Compilation) -> Result<()> {
.unwrap_or_else(|_| panic!("`{condition}` is invalid extractComments condition"))
});
let enter_span = tracing::Span::current();

let tls: ThreadLocal<ObjectPool> = ThreadLocal::new();
compilation
.assets_mut()
.par_iter_mut()
Expand All @@ -190,7 +193,8 @@ async fn process_assets(&self, compilation: &mut Compilation) -> Result<()> {
let filename = filename.split('?').next().expect("Should have filename");
if let Some(original_source) = original.get_source() {
let input = original_source.source().into_string_lossy().into_owned();
let input_source_map = original_source.map(&MapOptions::default());
let object_pool = tls.get_or(ObjectPool::default);
let input_source_map = original_source.map(object_pool, &MapOptions::default());

let is_module = if let Some(module) = minimizer_options.module {
Some(module)
Expand Down
Loading
Loading