Skip to content

Commit 2a8d7f5

Browse files
authored
fix: special case for aliasing @/ (#348)
1 parent 0a4bf3c commit 2a8d7f5

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/lib.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,17 +1021,20 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
10211021
let new_specifier = if tail.is_empty() {
10221022
Cow::Borrowed(alias_value)
10231023
} else {
1024-
let alias_value = Path::new(alias_value).normalize();
1024+
let alias_path = Path::new(alias_value).normalize();
10251025
// Must not append anything to alias_value if it is a file.
1026-
let alias_value_cached_path = self.cache.value(&alias_value);
1027-
if alias_value_cached_path.is_file(&self.cache.fs, ctx) {
1026+
let cached_alias_path = self.cache.value(&alias_path);
1027+
if cached_alias_path.is_file(&self.cache.fs, ctx) {
10281028
return Ok(None);
10291029
}
1030-
10311030
// Remove the leading slash so the final path is concatenated.
10321031
let tail = tail.trim_start_matches(SLASH_START);
1033-
let normalized = alias_value_cached_path.normalize_with(tail, &self.cache);
1034-
Cow::Owned(normalized.path().to_string_lossy().to_string())
1032+
if tail.is_empty() {
1033+
Cow::Borrowed(alias_value)
1034+
} else {
1035+
let normalized = alias_path.normalize_with(tail);
1036+
Cow::Owned(normalized.to_string_lossy().to_string())
1037+
}
10351038
};
10361039

10371040
*should_stop = true;

src/tests/alias.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ fn alias() {
8282
("should resolve '#' alias 2", "#/index", "/c/dir/index"),
8383
("should resolve '@' alias 1", "@", "/c/dir/index"),
8484
("should resolve '@' alias 2", "@/index", "/c/dir/index"),
85+
("should resolve '@' alias 3", "@/", "/c/dir/index"),
8586
("should resolve a recursive aliased module 1", "recursive", "/recursive/dir/index"),
8687
("should resolve a recursive aliased module 2", "recursive/index", "/recursive/dir/index"),
8788
("should resolve a recursive aliased module 3", "recursive/dir", "/recursive/dir/index"),

0 commit comments

Comments
 (0)