Skip to content

Commit 04c9a04

Browse files
committed
fix: use regex to replace
1 parent 03f7f9f commit 04c9a04

File tree

1 file changed

+7
-6
lines changed
  • crates/rspack_plugin_next_flight_client_entry/src

1 file changed

+7
-6
lines changed

crates/rspack_plugin_next_flight_client_entry/src/lib.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use get_module_build_info::get_module_build_info;
2424
use is_metadata_route::is_metadata_route;
2525
use itertools::Itertools;
2626
use loader_util::{get_actions_from_build_info, is_client_component_entry_module, is_css_mod};
27+
use regex::Regex;
2728
use rspack_collections::Identifiable;
2829
use rspack_core::{
2930
rspack_sources::{RawSource, SourceExt},
@@ -645,7 +646,7 @@ impl FlightClientEntryPlugin {
645646
modules.sort_unstable_by(|a, b| {
646647
let a_is_css = REGEX_CSS.is_match(&a.0);
647648
let b_is_css = REGEX_CSS.is_match(&b.0);
648-
match ((a_is_css, b_is_css)) {
649+
match (a_is_css, b_is_css) {
649650
(false, true) => Ordering::Less,
650651
(true, false) => Ordering::Greater,
651652
(_, _) => a.0.cmp(&b.0),
@@ -1020,13 +1021,13 @@ impl FlightClientEntryPlugin {
10201021
} else {
10211022
entry_request.to_string_lossy().to_string()
10221023
};
1024+
let re1 = Regex::new(r"\.[^.\\/]+$").unwrap();
1025+
let re2 = Regex::new(r"^src[\\/]").unwrap();
1026+
let replaced_path = &re1.replace_all(&relative_request, "");
1027+
let replaced_path = re2.replace_all(&replaced_path, "");
10231028

10241029
// Replace file suffix as `.js` will be added.
1025-
let mut bundle_path = normalize_path_sep(
1026-
&relative_request
1027-
.replace(r"\.[^.\\/]+$", "")
1028-
.replace(r"^src[\\/]", ""),
1029-
);
1030+
let mut bundle_path = normalize_path_sep(&replaced_path);
10301031

10311032
// For metadata routes, the entry name can be used as the bundle path,
10321033
// as it has been normalized already.

0 commit comments

Comments
 (0)