Skip to content

Commit f210dea

Browse files
authored
Avoid filename conflict (vercel/turborepo#3673)
We need to make sure that `.json` and `.json.js` doesn't end up with the same name.
1 parent ff902a1 commit f210dea

File tree

19 files changed

+30
-25
lines changed

19 files changed

+30
-25
lines changed

crates/turbopack-core/src/chunk/dev.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ impl ChunkingContext for DevChunkingContext {
123123
} else {
124124
clean(&path_vc.to_string().await?)
125125
};
126-
if name.ends_with(extension) {
126+
let removed_extension = name.ends_with(extension);
127+
if removed_extension {
127128
name.truncate(name.len() - extension.len());
128129
}
129130

@@ -148,9 +149,13 @@ impl ChunkingContext for DevChunkingContext {
148149
let truncated_hash = &hash[..5];
149150
name = format!("{}_{}", truncated_hash, &name[i..]);
150151
}
151-
if !name.ends_with(extension) {
152-
name += extension;
152+
// We need to make sure that `.json` and `.json.js` doesn't end up with the same
153+
// name. So when we add an extra extension when want to mark that with a "._"
154+
// suffix.
155+
if !removed_extension {
156+
name += "._";
153157
}
158+
name += extension;
154159
let mut root_path = self.chunk_root_path;
155160
#[allow(clippy::single_match, reason = "future extensions")]
156161
match extension {

crates/turbopack-tests/tests/snapshot/css/css/output/8697f_foo_style.module.css.js renamed to crates/turbopack-tests/tests/snapshot/css/css/output/8697f_foo_style.module.css._.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/turbopack-tests/tests/snapshot/imports/dynamic/output/79fb1_turbopack-tests_tests_snapshot_imports_dynamic_input_vercel.mjs_manifest-chunk.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"[project]/crates/turbopack-tests/tests/snapshot/imports/dynamic/input/vercel.mjs/manifest-chunk.js": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => {
44

55
const chunks = [
6-
"output/crates_turbopack-tests_tests_snapshot_imports_dynamic_input_vercel.mjs.js",
6+
"output/crates_turbopack-tests_tests_snapshot_imports_dynamic_input_vercel.mjs._.js",
77
];
88

99
__turbopack_export_value__(Promise.all(chunks.map(__turbopack_load__)));
Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)