Skip to content

Commit c324c6f

Browse files
Merge main branch and fix chunk characteristics implementation
- Resolve conflicts with main branch changes - Update pnpm-lock.yaml to latest versions - Fixed API extractor issues
2 parents 4345cad + b4c248d commit c324c6f

File tree

60 files changed

+801
-538
lines changed

Some content is hidden

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

60 files changed

+801
-538
lines changed

.cargo/config.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ rustflags = [
4343
[target.'cfg(target_vendor = "apple")']
4444
rustflags = ["-C", "link-args=-Wl,-undefined,dynamic_lookup,-no_fixup_chains,-all_load"]
4545

46-
# To be able to run unit tests on Linux, support compilation to 'x86_64-unknown-linux-gnu'.
47-
[target.'cfg(target_os = "linux")']
48-
rustflags = ["-C", "link-args=-Wl,--warn-unresolved-symbols"]
49-
5046
# To be able to run unit tests on Windows, support compilation to 'x86_64-pc-windows-msvc'.
5147
# Use Hybrid CRT to reduce the size of the binary (Coming by default with Windows 10 and later versions).
5248
[target.'cfg(target_os = "windows")']

crates/node_binding/napi-binding.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,8 @@ export declare class JsModuleGraph {
404404
}
405405

406406
export declare class JsResolver {
407-
resolveSync(path: string, request: string): JsResourceData | false
408-
resolve(path: string, request: string, callback: (err: null | Error, req?: JsResourceData) => void): void
407+
resolveSync(path: string, request: string): string | undefined
408+
resolve(path: string, request: string, callback: (err: null | Error, req?: string) => void): void
409409
withOptions(raw?: RawResolveOptionsWithDependencyType | undefined | null): JsResolver
410410
}
411411

@@ -463,7 +463,7 @@ export declare class NativeWatchResult {
463463

464464
export declare class RawExternalItemFnCtx {
465465
data(): RawExternalItemFnCtxData
466-
getResolver(): JsResolver
466+
getResolve(options?: RawResolveOptionsWithDependencyType | undefined | null): (context: string, path: string, callback: (error?: Error, text?: string) => void) => void
467467
}
468468

469469
export declare class ReadonlyResourceData {
@@ -2598,6 +2598,7 @@ export interface RawSubresourceIntegrityPluginOptions {
25982598
}
25992599

26002600
export interface RawSwcJsMinimizerOptions {
2601+
ecma: any
26012602
compress: any
26022603
mangle: any
26032604
format: any

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub struct RawSwcJsMinimizerRspackPluginOptions {
3232
#[derive(Debug)]
3333
#[napi(object, object_to_js = false)]
3434
pub struct RawSwcJsMinimizerOptions {
35+
pub ecma: serde_json::Value,
3536
pub compress: serde_json::Value,
3637
pub mangle: serde_json::Value,
3738
pub format: serde_json::Value,
@@ -78,6 +79,11 @@ impl TryFrom<RawSwcJsMinimizerRspackPluginOptions> for PluginOptions {
7879
BoolOrDataConfig<rspack_plugin_swc_js_minimizer::MangleOptions>,
7980
>(value.minimizer_options.mangle)?
8081
.or(|| BoolOrDataConfig::from_bool(true));
82+
83+
let ecma = try_deserialize_into::<rspack_plugin_swc_js_minimizer::TerserEcmaVersion>(
84+
value.minimizer_options.ecma,
85+
)?;
86+
8187
Ok(Self {
8288
extract_comments: into_extract_comments(value.extract_comments),
8389
test: value.test.map(into_asset_conditions),
@@ -86,6 +92,7 @@ impl TryFrom<RawSwcJsMinimizerRspackPluginOptions> for PluginOptions {
8692
minimizer_options: MinimizerOptions {
8793
compress,
8894
mangle,
95+
ecma,
8996
format: try_deserialize_into(value.minimizer_options.format)?,
9097
module: value.minimizer_options.module,
9198
minify: value.minimizer_options.minify,

crates/rspack_binding_api/src/raw_options/raw_external.rs

Lines changed: 77 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
use std::{fmt::Debug, sync::Arc};
1+
use std::{fmt::Debug, path::Path, sync::Arc};
22

3-
use napi::bindgen_prelude::{Either4, Promise};
3+
use napi::{
4+
bindgen_prelude::{Either4, Function, FunctionCallContext, Promise},
5+
Either, Env,
6+
};
47
use napi_derive::napi;
58
use rspack_core::{
69
ExternalItem, ExternalItemFnCtx, ExternalItemFnResult, ExternalItemValue,
@@ -10,7 +13,10 @@ use rspack_napi::threadsafe_function::ThreadsafeFunction;
1013
use rspack_regex::RspackRegex;
1114
use rustc_hash::FxHashMap as HashMap;
1215

13-
use crate::JsResolver;
16+
use crate::{
17+
callbackify, normalize_raw_resolve_options_with_dependency_type, ErrorCode,
18+
RawResolveOptionsWithDependencyType, ResolveRequest,
19+
};
1420

1521
#[napi(object)]
1622
pub struct RawHttpExternalsRspackPluginOptions {
@@ -105,12 +111,74 @@ impl RawExternalItemFnCtx {
105111
}
106112
}
107113

108-
#[napi]
109-
pub fn get_resolver(&self) -> JsResolver {
110-
JsResolver::new(
111-
self.resolver_factory.clone(),
112-
self.resolve_options_with_dependency_type.clone(),
113-
)
114+
#[napi(
115+
ts_return_type = "(context: string, path: string, callback: (error?: Error, text?: string) => void) => void"
116+
)]
117+
pub fn get_resolve<'a>(
118+
&self,
119+
env: &'a Env,
120+
options: Option<RawResolveOptionsWithDependencyType>,
121+
) -> napi::Result<Function<'a, (String, String, Function<'static>), ()>> {
122+
let first = Arc::new(self.resolve_options_with_dependency_type.clone());
123+
let second = Arc::new(
124+
normalize_raw_resolve_options_with_dependency_type(options, first.resolve_to_context)
125+
.map_err(|e| napi::Error::from_reason(e.to_string()))?,
126+
);
127+
let resolver_factory = self.resolver_factory.clone();
128+
129+
let f: Function<(String, String, Function<'static>), ()> =
130+
env.create_function_from_closure("resolve", move |ctx: FunctionCallContext| {
131+
let context = ctx.get::<String>(0)?;
132+
let request = ctx.get::<String>(1)?;
133+
let callback = ctx.get::<Function<'static>>(2)?;
134+
135+
let first_clone = first.clone();
136+
let second_clone = second.clone();
137+
let resolver_factory = resolver_factory.clone();
138+
139+
callbackify(
140+
callback,
141+
async move {
142+
let merged_resolve_options = match second_clone.resolve_options.as_ref() {
143+
Some(second_resolve_options) => match first_clone.resolve_options.as_ref() {
144+
Some(resolve_options) => Some(Box::new(
145+
resolve_options
146+
.clone()
147+
.merge(*second_resolve_options.clone()),
148+
)),
149+
None => Some(second_resolve_options.clone()),
150+
},
151+
None => first_clone.resolve_options.clone(),
152+
};
153+
154+
let merged_options = ResolveOptionsWithDependencyType {
155+
resolve_options: merged_resolve_options,
156+
resolve_to_context: second_clone.resolve_to_context,
157+
dependency_category: second_clone.dependency_category,
158+
};
159+
let resolver = resolver_factory.get(merged_options);
160+
161+
match resolver.resolve(Path::new(&context), &request).await {
162+
Ok(rspack_core::ResolveResult::Resource(resource)) => {
163+
let resolve_request = ResolveRequest::from(resource);
164+
Ok(match serde_json::to_string(&resolve_request) {
165+
Ok(json) => Either::<String, ()>::A(json),
166+
Err(_) => Either::B(()),
167+
})
168+
}
169+
Ok(rspack_core::ResolveResult::Ignored) => Ok(Either::B(())),
170+
Err(err) => Err(napi::Error::new(
171+
ErrorCode::Napi(napi::Status::GenericFailure),
172+
format!("{err:?}"),
173+
)),
174+
}
175+
},
176+
None::<fn()>,
177+
)
178+
.map_err(|e| napi::Error::from_reason(e.reason.to_string()))
179+
})?;
180+
181+
Ok(f)
114182
}
115183
}
116184

crates/rspack_binding_api/src/resolver.rs

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,41 @@ use napi::{
55
Either,
66
};
77
use napi_derive::napi;
8-
use rspack_core::{ResolveOptionsWithDependencyType, Resolver, ResolverFactory, ResourceData};
8+
use rspack_core::{ResolveOptionsWithDependencyType, Resolver, ResolverFactory};
9+
use serde::Serialize;
910

1011
use crate::{
1112
callbackify,
1213
raw_resolve::{
1314
normalize_raw_resolve_options_with_dependency_type, RawResolveOptionsWithDependencyType,
1415
},
15-
ErrorCode, JsResourceData,
16+
ErrorCode,
1617
};
1718

19+
#[derive(Debug, Serialize)]
20+
#[serde(rename_all = "camelCase")]
21+
pub struct ResolveRequest {
22+
pub path: String,
23+
pub query: String,
24+
pub fragment: String,
25+
pub description_file_data: Option<serde_json::Value>,
26+
pub description_file_path: Option<String>,
27+
}
28+
29+
impl From<rspack_core::Resource> for ResolveRequest {
30+
fn from(value: rspack_core::Resource) -> Self {
31+
let (description_file_path, description_file_data) =
32+
value.description_data.map(|data| data.into_parts()).unzip();
33+
Self {
34+
path: value.path.to_string(),
35+
query: value.query,
36+
fragment: value.fragment,
37+
description_file_data: description_file_data.map(std::sync::Arc::unwrap_or_clone),
38+
description_file_path: description_file_path.map(|path| path.to_string_lossy().into_owned()),
39+
}
40+
}
41+
}
42+
1843
#[napi]
1944
#[derive(Debug)]
2045
pub struct JsResolver {
@@ -38,31 +63,21 @@ impl JsResolver {
3863
}
3964
#[napi]
4065
impl JsResolver {
41-
#[napi(ts_return_type = "JsResourceData | false")]
42-
pub fn resolve_sync(
43-
&self,
44-
path: String,
45-
request: String,
46-
) -> napi::Result<Either<JsResourceData, bool>> {
47-
block_on(self._resolve(path, request))
48-
}
49-
50-
async fn _resolve(
51-
&self,
52-
path: String,
53-
request: String,
54-
) -> napi::Result<Either<JsResourceData, bool>> {
55-
match self.resolver.resolve(Path::new(&path), &request).await {
56-
Ok(rspack_core::ResolveResult::Resource(resource)) => {
57-
Ok(Either::A(ResourceData::from(resource).into()))
66+
#[napi]
67+
pub fn resolve_sync(&self, path: String, request: String) -> napi::Result<Either<String, ()>> {
68+
block_on(async {
69+
match self.resolver.resolve(Path::new(&path), &request).await {
70+
Ok(rspack_core::ResolveResult::Resource(resource)) => {
71+
Ok(Either::A(resource.path.to_string()))
72+
}
73+
Ok(rspack_core::ResolveResult::Ignored) => Ok(Either::B(())),
74+
Err(err) => Err(napi::Error::from_reason(format!("{err:?}"))),
5875
}
59-
Ok(rspack_core::ResolveResult::Ignored) => Ok(Either::B(false)),
60-
Err(err) => Err(napi::Error::from_reason(format!("{err:?}"))),
61-
}
76+
})
6277
}
6378

6479
#[napi(
65-
ts_args_type = "path: string, request: string, callback: (err: null | Error, req?: JsResourceData) => void"
80+
ts_args_type = "path: string, request: string, callback: (err: null | Error, req?: string) => void"
6681
)]
6782
pub fn resolve(
6883
&self,
@@ -75,10 +90,14 @@ impl JsResolver {
7590
f,
7691
async move {
7792
match resolver.resolve(Path::new(&path), &request).await {
78-
Ok(rspack_core::ResolveResult::Resource(resource)) => Ok(
79-
Either::<JsResourceData, bool>::A(ResourceData::from(resource).into()),
80-
),
81-
Ok(rspack_core::ResolveResult::Ignored) => Ok(Either::B(false)),
93+
Ok(rspack_core::ResolveResult::Resource(resource)) => {
94+
let resolve_request = ResolveRequest::from(resource);
95+
Ok(match serde_json::to_string(&resolve_request) {
96+
Ok(json) => Either::<String, ()>::A(json),
97+
Err(_) => Either::B(()),
98+
})
99+
}
100+
Ok(rspack_core::ResolveResult::Ignored) => Ok(Either::B(())),
82101
Err(err) => Err(napi::Error::new(
83102
ErrorCode::Napi(napi::Status::GenericFailure),
84103
format!("{err:?}"),

crates/rspack_loader_swc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ serde = { workspace = true, features = ["derive"] }
3333
serde_json = { workspace = true }
3434
swc = { workspace = true, features = ["manual-tokio-runtime"] }
3535
swc_config = { workspace = true }
36-
swc_core = { workspace = true, features = ["base", "ecma_ast", "common", "ecma_preset_env"] }
36+
swc_core = { workspace = true, features = ["base", "ecma_ast", "common", "ecma_preset_env", "ecma_helpers_inline"] }
3737
tokio = { workspace = true }
3838
tracing = { workspace = true }
3939

crates/rspack_plugin_circular_dependencies/src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ impl CircularDependencyRspackPlugin {
268268
&self,
269269
module_map: &IdentifierMap<GraphModule>,
270270
cycle: &[ModuleIdentifier],
271+
compilation: &Compilation,
271272
) -> bool {
272273
for [module_id, target_id] in cycle.array_windows::<2>() {
273274
// If any dependency in the cycle is purely asynchronous, then it does not count as a runtime
@@ -276,9 +277,18 @@ impl CircularDependencyRspackPlugin {
276277
return true;
277278
}
278279

280+
let Some(module) = compilation
281+
.module_by_identifier(module_id)
282+
.and_then(|m| m.as_normal_module())
283+
else {
284+
continue;
285+
};
286+
279287
// Not all cycles are errors, so filter out any cycles containing
280288
// explicitly-ignored modules.
281-
if self.is_ignored_module(module_id) || self.is_ignored_connection(module_id, target_id) {
289+
if self.is_ignored_module(module.resource_resolved_data().resource.as_str())
290+
|| self.is_ignored_connection(module_id, target_id)
291+
{
282292
return true;
283293
}
284294
}
@@ -374,7 +384,7 @@ async fn optimize_modules(&self, compilation: &mut Compilation) -> Result<Option
374384
};
375385

376386
for cycle in detector.find_cycles_from(module_id) {
377-
if self.is_cycle_ignored(&module_map, &cycle) {
387+
if self.is_cycle_ignored(&module_map, &cycle, compilation) {
378388
self
379389
.handle_cycle_ignored(entrypoint_name.clone(), cycle, compilation)
380390
.await?

crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ pub struct JavaScriptParserAndGenerator {
4444
// TODO
4545
#[cacheable(with=Skip)]
4646
parser_plugins: Vec<BoxJavascriptParserPlugin>,
47-
// TODO
48-
#[cacheable(with=Skip)]
49-
parser_pre_plugins: Vec<BoxJavascriptParserPlugin>,
5047
}
5148

5249
impl std::fmt::Debug for JavaScriptParserAndGenerator {
@@ -63,10 +60,6 @@ impl JavaScriptParserAndGenerator {
6360
self.parser_plugins.push(parser_plugin);
6461
}
6562

66-
pub fn add_parser_pre_plugin(&mut self, parser_plugin: BoxJavascriptParserPlugin) {
67-
self.parser_pre_plugins.push(parser_plugin);
68-
}
69-
7063
fn source_block(
7164
&self,
7265
compilation: &Compilation,
@@ -144,7 +137,6 @@ impl ParserAndGenerator for JavaScriptParserAndGenerator {
144137
module_identifier,
145138
loaders,
146139
module_parser_options,
147-
additional_data,
148140
mut parse_meta,
149141
..
150142
} = parse_context;
@@ -269,8 +261,6 @@ impl ParserAndGenerator for JavaScriptParserAndGenerator {
269261
&mut semicolons,
270262
unresolved_mark,
271263
&mut self.parser_plugins,
272-
&mut self.parser_pre_plugins,
273-
additional_data,
274264
parse_meta,
275265
)
276266
}) {

crates/rspack_plugin_javascript/src/parser_plugin/common_js_exports_parse_plugin.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,6 @@ impl JavascriptParser<'_> {
224224
}
225225

226226
fn is_this_member_expr_start<E: ExprLike>(&self, expr: &E) -> bool {
227-
if self.enter_call != 0 {
228-
return false;
229-
}
230227
fn walk_each<E: ExprLike>(parser: &JavascriptParser, expr: &E) -> bool {
231228
if parser.is_top_level_this_expr(expr) {
232229
true

0 commit comments

Comments
 (0)