Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: align source name conflict handling #6993

Merged
merged 10 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Sort module_to_source_name before handling conflict
  • Loading branch information
CPunisher committed Jul 1, 2024
commit 56079067e88e1e618cee08e2ab1322173ba3daed
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/rspack_plugin_devtool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ async-trait = { workspace = true }
dashmap = { workspace = true }
derivative = { workspace = true }
futures = { workspace = true }
itertools = { workspace = true }
once_cell = { workspace = true }
pathdiff = { workspace = true }
rayon = { workspace = true }
Expand Down
19 changes: 17 additions & 2 deletions crates/rspack_plugin_devtool/src/source_map_dev_tool_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{borrow::Cow, path::Path};

use derivative::Derivative;
use futures::future::{join_all, BoxFuture};
use itertools::Itertools;
use once_cell::sync::Lazy;
use pathdiff::diff_paths;
use rayon::prelude::*;
Expand Down Expand Up @@ -216,7 +217,7 @@ impl SourceMapDevToolPlugin {
.into_iter()
.collect::<HashMap<_, _>>();
SyMind marked this conversation as resolved.
Show resolved Hide resolved

let module_source_names = source_map_modules.values().collect::<HashSet<_>>();
let module_source_names = source_map_modules.values().collect::<Vec<_>>();
let mut module_to_source_name = match &self.module_filename_template {
ModuleFilenameTemplate::String(s) => module_source_names
.into_par_iter()
Expand Down Expand Up @@ -256,7 +257,21 @@ impl SourceMapDevToolPlugin {
};

let mut used_names_set = HashSet::<String>::default();
for (module_or_source, source_name) in module_to_source_name.iter_mut() {
for (module_or_source, source_name) in
module_to_source_name
.iter_mut()
.sorted_by(|(key_a, _), (key_b, _)| {
let ident_a = match key_a {
ModuleOrSource::Module(identifier) => identifier,
ModuleOrSource::Source(source) => source.as_str(),
};
let ident_b = match key_b {
ModuleOrSource::Module(identifier) => identifier,
ModuleOrSource::Source(source) => source.as_str(),
};
ident_a.len().cmp(&ident_b.len())
})
{
let mut has_name = used_names_set.contains(source_name);
if !has_name {
used_names_set.insert(source_name.clone());
Expand Down