Skip to content

Commit 7266264

Browse files
committed
fix(rolldown_plugin_vite_import_glob): keep common base on path segment boundary (#9070)
Related to vitejs/vite#22170 `get_common_base` used a byte-wise longest common prefix, which could cut in the middle of a path segment — e.g. for `.../pattern3` and `.../pattern4` it returned `.../pattern`, a non-existent directory that made `walkdir` find nothing. Track the last shared separator while walking, and when the walk reaches `max_len` without a byte mismatch, promote `i` itself if both paths are at a segment boundary there. The base now always lands on a component boundary. I will add a test case on Vite side.
1 parent 04c7c23 commit 7266264

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

  • crates/rolldown_plugin_vite_import_glob/src

crates/rolldown_plugin_vite_import_glob/src/utils.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,25 @@ impl GlobImportVisit<'_> {
350350
let max_len = end.min(bytes.len());
351351

352352
let mut i = 0;
353+
let mut last_slash = 0;
353354
while i < max_len && first[i] == bytes[i] {
355+
if first[i] == MAIN_SEPARATOR as u8 {
356+
last_slash = i;
357+
}
354358
i += 1;
355359
}
356360

357-
end = i;
361+
// If the walk finished at `max_len` (not a byte mismatch), `i` itself
362+
// may already be a deeper boundary than any separator we recorded —
363+
// e.g. when one path fully matched the other up to a segment split.
364+
if i == max_len
365+
&& (i == first.len() || first[i] == MAIN_SEPARATOR as u8)
366+
&& (i == bytes.len() || bytes[i] == MAIN_SEPARATOR as u8)
367+
{
368+
last_slash = i;
369+
}
370+
371+
end = last_slash;
358372
if end == 0 {
359373
break;
360374
}

0 commit comments

Comments
 (0)