Skip to content

Commit c869d6a

Browse files
authored
Merge branch 'main' into feat/manifest-builtin
2 parents a509e75 + 5b54e20 commit c869d6a

File tree

68 files changed

+326
-502
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+326
-502
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ regex-syntax = { version = "0.8.5", default-features = false, features =
8383
regress = { version = "0.10.4", default-features = false, features = ["pattern"] }
8484
ropey = { version = "1.6.1", default-features = false }
8585
rspack_resolver = { features = ["package_json_raw_json_api", "yarn_pnp"], version = "0.6.4", default-features = false }
86-
rspack_sources = { version = "=0.4.12", default-features = false }
86+
rspack_sources = { version = "=0.4.13", default-features = false }
8787
rustc-hash = { version = "2.1.0", default-features = false }
8888
ryu-js = { version = "1.0.2", default-features = false }
8989
scopeguard = { version = "1.2.0", default-features = false }

crates/rspack/tests/basic.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ mod tests {
1919
assert!(errors.is_empty());
2020

2121
let asset = &compiler.compilation.assets().get("main.js").unwrap();
22-
assert_eq!(asset.source.as_ref().unwrap().source(), "console.log(123);");
22+
assert_eq!(
23+
asset.source.as_ref().unwrap().source().into_string_lossy(),
24+
"console.log(123);"
25+
);
2326
})
2427
.await;
2528
}
@@ -42,7 +45,7 @@ mod tests {
4245

4346
let asset = &compiler.compilation.assets().get("main.js").unwrap();
4447
assert_eq!(
45-
asset.source.as_ref().unwrap().source(),
48+
asset.source.as_ref().unwrap().source().into_string_lossy(),
4649
"console.log(123);\n//# sourceMappingURL=main.js.map"
4750
);
4851
assert!(compiler.compilation.assets().get("main.js.map").is_some());

crates/rspack_binding_api/src/codegen_result.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ impl From<&CodeGenerationResult> for JsCodegenerationResult {
2121
.inner
2222
.as_ref()
2323
.iter()
24-
.map(|(source_type, source)| (source_type.to_string(), source.source().to_string()))
25-
.collect(),
24+
.map(|(source_type, source)| {
25+
(
26+
source_type.to_string(),
27+
source.source().into_string_lossy().into_owned(),
28+
)
29+
})
30+
.collect::<HashMap<String, String>>(),
2631
}
2732
}
2833
}

crates/rspack_binding_api/src/raw_options/raw_builtins/raw_copy.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use napi::{
55
bindgen_prelude::{Buffer, FnArgs, Promise},
66
};
77
use napi_derive::napi;
8-
use rspack_core::rspack_sources::RawSource;
8+
use rspack_core::rspack_sources::{RawBufferSource, RawStringSource, SourceExt};
99
use rspack_napi::threadsafe_function::ThreadsafeFunction;
1010
use rspack_plugin_copy::{
1111
CopyGlobOptions, CopyPattern, CopyRspackPluginOptions, Info, Related, ToOption, ToType,
@@ -207,8 +207,8 @@ impl From<RawCopyPattern> for CopyPattern {
207207
f.call_with_promise((input.into(), absolute_filename.to_owned()).into())
208208
.await
209209
.map(|input| match input {
210-
Either::A(s) => RawSource::from(s),
211-
Either::B(b) => RawSource::from(Vec::<u8>::from(b)),
210+
Either::A(s) => RawStringSource::from(s).boxed(),
211+
Either::B(b) => RawBufferSource::from(Vec::<u8>::from(b)).boxed(),
212212
})
213213
})
214214
})

crates/rspack_binding_api/src/source.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use std::{hash::Hash, sync::Arc};
22

33
use napi_derive::napi;
44
use rspack_core::rspack_sources::{
5-
BoxSource, CachedSource, ConcatSource, MapOptions, OriginalSource, RawBufferSource, RawSource,
6-
RawStringSource, ReplaceSource, Source, SourceExt, SourceMap, SourceMapSource,
5+
BoxSource, CachedSource, ConcatSource, MapOptions, OriginalSource, RawBufferSource,
6+
RawStringSource, ReplaceSource, Source, SourceExt, SourceMap, SourceMapSource, SourceValue,
77
WithoutOriginalOptions,
88
};
99
use rspack_napi::napi::bindgen_prelude::*;
@@ -66,20 +66,19 @@ impl TryFrom<&dyn Source> for JsSourceToJs {
6666
type Error = napi::Error;
6767

6868
fn try_from(value: &dyn Source) -> Result<Self> {
69-
if let Some(raw_buffer_source) = value.as_any().downcast_ref::<RawBufferSource>() {
70-
let bytes = raw_buffer_source.buffer().to_vec();
71-
return Ok(JsSourceToJs {
72-
source: Either::B(Buffer::from(bytes)),
69+
match value.source() {
70+
SourceValue::String(string) => {
71+
let map: Option<String> = to_webpack_map(value)?;
72+
Ok(JsSourceToJs {
73+
source: Either::A(string.into_owned()),
74+
map,
75+
})
76+
}
77+
SourceValue::Buffer(bytes) => Ok(JsSourceToJs {
78+
source: Either::B(Buffer::from(bytes.to_vec())),
7379
map: None,
74-
});
80+
}),
7581
}
76-
77-
let string = value.source();
78-
let map: Option<String> = to_webpack_map(value)?;
79-
Ok(JsSourceToJs {
80-
source: Either::A(string.into_owned()),
81-
map,
82-
})
8382
}
8483
}
8584

crates/rspack_binding_api/src/stats.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use napi_derive::napi;
99
use rspack_collections::IdentifierMap;
1010
use rspack_core::{
1111
EntrypointsStatsOption, ExtendedStatsOptions, Stats, StatsChunk, StatsModule, StatsUsedExports,
12-
rspack_sources::{RawBufferSource, RawSource, Source},
12+
rspack_sources::{RawBufferSource, Source, SourceValue},
1313
};
1414
use rspack_error::Severity;
1515
use rspack_napi::napi::{
@@ -569,16 +569,9 @@ impl<'a> TryFrom<StatsModule<'a>> for JsStatsModule<'a> {
569569
type Error = napi::Error;
570570

571571
fn try_from(stats: StatsModule<'a>) -> std::result::Result<Self, Self::Error> {
572-
let source = stats.source.map(|source| {
573-
if let Some(raw_source) = source.as_any().downcast_ref::<RawBufferSource>() {
574-
return JsStatsModuleSource::B(Buffer::from(raw_source.buffer().to_vec()));
575-
}
576-
if let Some(raw_source) = source.as_any().downcast_ref::<RawSource>()
577-
&& raw_source.is_buffer()
578-
{
579-
return JsStatsModuleSource::B(Buffer::from(raw_source.buffer().to_vec()));
580-
}
581-
JsStatsModuleSource::A(CowStrWrapper::new(source.source()))
572+
let source = stats.source.map(|source| match source.source() {
573+
SourceValue::String(string) => JsStatsModuleSource::A(CowStrWrapper::new(string)),
574+
SourceValue::Buffer(bytes) => JsStatsModuleSource::B(Buffer::from(bytes.to_vec())),
582575
});
583576

584577
let mut sizes = stats

crates/rspack_core/src/compilation/make/graph_updater/repair/factorize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl Task<TaskContext> for FactorizeTask {
9898
if let Some(s) = self.original_module_source {
9999
let has_source_code = e.src.is_some();
100100
if !has_source_code {
101-
e.src = Some(s.source().to_string());
101+
e.src = Some(s.source().into_string_lossy().into_owned());
102102
}
103103
}
104104
// Bail out if `options.bail` set to `true`,

crates/rspack_core/src/concatenated_module.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2242,7 +2242,7 @@ impl ConcatenatedModule {
22422242
"{}",
22432243
self.readable_identifier(&compilation.options.context),
22442244
))),
2245-
source_code.to_string(),
2245+
source_code.into_string_lossy().into_owned(),
22462246
);
22472247
let comments = SwcComments::default();
22482248
let mut module_info = concatenation_scope.current_module;

crates/rspack_core/src/init_fragment.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,9 @@ impl InitFragmentKey {
140140
| InitFragmentKey::ModuleExternal(_)
141141
| InitFragmentKey::ModuleDecorator(_)
142142
| InitFragmentKey::CommonJsExports(_)
143+
| InitFragmentKey::ESMCompatibility
143144
| InitFragmentKey::Const(_) => first(fragments),
144-
InitFragmentKey::ESMCompatibility | InitFragmentKey::Unique(_) => {
145+
InitFragmentKey::Unique(_) => {
145146
debug_assert!(fragments.len() == 1, "fragment = {self:?}");
146147
first(fragments)
147148
}

0 commit comments

Comments
 (0)