Skip to content

Commit

Permalink
feat: give an specific error for matched alias not found
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin committed Sep 3, 2024
1 parent f4c3ef5 commit 59b1a68
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ pub enum ResolveError {
#[error("Cannot find module '{0}'")]
NotFound(/* specifier */ String),

/// Matched alias value not found
#[error("Cannot find module '{0}' for matched aliased key '{1}'")]
MatchedAliasNotFound(/* specifier */ String, /* alias key */ String),

/// Tsconfig not found
#[error("Tsconfig not found {0}")]
TsconfigNotFound(PathBuf),
Expand Down
9 changes: 7 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,10 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
}
}
if should_stop {
return Err(ResolveError::NotFound(specifier.to_string()));
return Err(ResolveError::MatchedAliasNotFound(
specifier.to_string(),
alias_key.to_string(),
));
}
}
Ok(None)
Expand Down Expand Up @@ -1011,7 +1014,9 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
*should_stop = true;
ctx.with_fully_specified(false);
return match self.require(cached_path, new_specifier.as_ref(), ctx) {
Err(ResolveError::NotFound(_)) => Ok(None),
Err(ResolveError::NotFound(_) | ResolveError::MatchedAliasNotFound(_, _)) => {
Ok(None)
}
Ok(path) => return Ok(Some(path)),
Err(err) => return Err(err),
};
Expand Down
5 changes: 4 additions & 1 deletion src/tests/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,10 @@ fn all_alias_values_are_not_found() {
..ResolveOptions::default()
});
let resolution = resolver.resolve(&f, "m1/a.js");
assert_eq!(resolution, Err(ResolveError::NotFound("m1/a.js".to_string())));
assert_eq!(
resolution,
Err(ResolveError::MatchedAliasNotFound("m1/a.js".to_string(), "m1".to_string(),))
);
}

#[test]
Expand Down

0 comments on commit 59b1a68

Please sign in to comment.