Skip to content

Commit ebfdcbd

Browse files
committed
fix(turbopack): asset filename extension
1 parent 8eb8d66 commit ebfdcbd

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

turbopack/crates/turbo-tasks-fs/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,7 @@ impl FileSystemPath {
15711571
/// 1. The parent directory, if any;
15721572
/// 2. The file stem;
15731573
/// 3. The extension, if any.
1574-
fn split_file_stem_extension(&self) -> (Option<&str>, &str, Option<&str>) {
1574+
pub fn split_file_stem_extension(&self) -> (Option<&str>, &str, Option<&str>) {
15751575
let (path_before_extension, extension) = self.split_extension();
15761576

15771577
if let Some((parent, file_stem)) = path_before_extension.rsplit_once('/') {

turbopack/crates/turbopack-browser/src/chunking_context.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -771,18 +771,19 @@ impl ChunkingContext for BrowserChunkingContext {
771771
Some(filename_template) => {
772772
let mut filename = filename_template.to_string();
773773

774+
let (_, name, ext) = source_path.split_file_stem_extension();
775+
774776
if match_name_placeholder(&filename) {
775-
filename = replace_name_placeholder(&filename, basename);
777+
filename = replace_name_placeholder(&filename, name);
776778
}
777779

778780
if match_content_hash_placeholder(&filename) {
779781
filename = replace_content_hash_placeholder(&filename, &content_hash);
780782
};
781783

782-
if let Some(ext) = source_path.extension_ref() {
783-
if let Some((stem, _)) = filename.rsplit_once(".") {
784-
filename = stem.to_string();
785-
}
784+
if let Some(ext) = ext
785+
&& !filename.ends_with(ext)
786+
{
786787
filename = format!("{filename}.{ext}");
787788
}
788789

0 commit comments

Comments
 (0)