Skip to content

Commit 6409e64

Browse files
committed
fix(turbopack): fix browser chunk_path
1 parent 9fff8f3 commit 6409e64

File tree

2 files changed

+9
-28
lines changed

2 files changed

+9
-28
lines changed

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

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,8 @@ impl ChunkingContext for BrowserChunkingContext {
431431

432432
let chunk_root = self.chunk_root_path;
433433

434-
let import_name = ident_to_output_filename(ident, *self.root_path, extension.clone())
434+
let output_name = ident
435+
.output_name(*self.root_path, extension.clone())
435436
.owned()
436437
.await?;
437438

@@ -440,7 +441,7 @@ impl ChunkingContext for BrowserChunkingContext {
440441
let ident = ident.await?;
441442
let query = QString::from(ident.query.await?.as_str());
442443

443-
let name = query.get("name").unwrap_or(import_name.as_str());
444+
let name = query.get("name").unwrap_or(output_name.as_str());
444445

445446
let evaluate = stream::iter(&ident.modifiers)
446447
.any(async |m| m.await.is_ok_and(|m| m.contains("evaluate")))
@@ -481,7 +482,7 @@ impl ChunkingContext for BrowserChunkingContext {
481482
None => name.to_string(),
482483
}
483484
}
484-
None => import_name.to_string(),
485+
None => output_name.to_string(),
485486
};
486487

487488
if !filename.ends_with(extension.as_str()) {
@@ -767,26 +768,6 @@ impl ChunkingContext for BrowserChunkingContext {
767768
}
768769
}
769770

770-
#[turbo_tasks::function]
771-
pub async fn ident_to_output_filename(
772-
ident: Vc<AssetIdent>,
773-
context_path: Vc<FileSystemPath>,
774-
expected_extension: RcStr,
775-
) -> Result<Vc<RcStr>> {
776-
let ident = &*ident.await?;
777-
let path = &*ident.path.await?;
778-
let mut name = if let Some(inner) = context_path.await?.get_path_to(path) {
779-
clean_separators(inner)
780-
} else {
781-
clean_separators(&ident.path.to_string().await?)
782-
};
783-
let removed_extension = name.ends_with(&*expected_extension);
784-
if removed_extension {
785-
name.truncate(name.len() - expected_extension.len());
786-
}
787-
Ok(Vc::cell(name.into()))
788-
}
789-
790771
pub fn clean_separators(s: &str) -> String {
791772
static SEPARATOR_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r".*[/#?]").unwrap());
792773
SEPARATOR_REGEX.replace_all(s, "").to_string()

turbopack/crates/turbopack-core/src/ident.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,10 @@ impl AssetIdent {
358358
// We need to make sure that `.json` and `.json.js` doesn't end up with the same
359359
// name. So when we add an extra extension when want to mark that with a "._"
360360
// suffix.
361-
if !removed_extension {
362-
name += "._";
363-
}
364-
name += &expected_extension;
361+
// if !removed_extension {
362+
// name += "._";
363+
// }
364+
// name += &expected_extension;
365365
Ok(Vc::cell(name.into()))
366366
}
367367
}
@@ -372,5 +372,5 @@ fn clean_separators(s: &str) -> String {
372372
}
373373

374374
fn clean_additional_extensions(s: &str) -> String {
375-
s.replace('.', "_")
375+
s.replace('.', "_").replace("[root-of-the-server]", "")
376376
}

0 commit comments

Comments
 (0)