Skip to content

Commit

Permalink
fix: alias match request end with slash (#35)
Browse files Browse the repository at this point in the history
Co-authored-by: SoonIter <sooniter@gmail.com>
  • Loading branch information
SyMind and SoonIter authored Dec 13, 2024
1 parent 2189dd3 commit 58fc10e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -998,17 +998,21 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
let new_specifier = if tail.is_empty() {
Cow::Borrowed(alias_value)
} else {
let alias_value = Path::new(alias_value).normalize();
let alias_path = Path::new(alias_value).normalize();
// Must not append anything to alias_value if it is a file.
let alias_value_cached_path = self.cache.value(&alias_value);
let alias_value_cached_path = self.cache.value(&alias_path);
if alias_value_cached_path.is_file(&self.cache.fs, ctx) {
return Ok(None);
}

// Remove the leading slash so the final path is concatenated.
let tail = tail.trim_start_matches(SLASH_START);
let normalized = alias_value.normalize_with(tail);
Cow::Owned(normalized.to_string_lossy().to_string())
if tail.is_empty() {
Cow::Borrowed(alias_value)
} else {
let normalized = alias_path.normalize_with(tail);
Cow::Owned(normalized.to_string_lossy().to_string())
}
};

*should_stop = true;
Expand Down
1 change: 1 addition & 0 deletions src/tests/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ fn alias() {
("should resolve '#' alias 2", "#/index", "/c/dir/index"),
("should resolve '@' alias 1", "@", "/c/dir/index"),
("should resolve '@' alias 2", "@/index", "/c/dir/index"),
("should resolve '@' alias 3", "@/", "/c/dir/index"),
("should resolve a recursive aliased module 1", "recursive", "/recursive/dir/index"),
("should resolve a recursive aliased module 2", "recursive/index", "/recursive/dir/index"),
("should resolve a recursive aliased module 3", "recursive/dir", "/recursive/dir/index"),
Expand Down

0 comments on commit 58fc10e

Please sign in to comment.