Skip to content

Commit

Permalink
feat: resolve with hint
Browse files Browse the repository at this point in the history
  • Loading branch information
h-a-n-a committed Jan 2, 2024
1 parent 0553a3a commit 7701e89
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
12 changes: 9 additions & 3 deletions crates/rspack_core/src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@ pub async fn resolve(
let base_dir = base_dir.as_ref();

let resolver = plugin_driver.resolver_factory.get(dep);
let result = resolver
.resolve(base_dir, args.specifier)
.map_err(|error| error.into_resolve_error(&args));
let result = {
let result = resolver
.resolve(base_dir, args.specifier)
.map_err(|error| error.into_resolve_error(&args));
match result {
Ok(result) => Ok(result),
Err(err) => Err(err.await),
}
};

let (file_dependencies, missing_dependencies) = resolver.dependencies();
args.file_dependencies.extend(file_dependencies);
Expand Down
13 changes: 8 additions & 5 deletions crates/rspack_core/src/resolver/resolver_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ impl Resolver {
}

impl ResolveInnerError {
pub fn into_resolve_error(self, args: &ResolveArgs<'_>) -> Error {
pub async fn into_resolve_error(self, args: &ResolveArgs<'_>) -> Error {
match self {
Self::NodejsResolver(error) => map_nodejs_resolver_error(error, args),
Self::OxcResolver(error) => map_oxc_resolver_error(error, args),
Self::NodejsResolver(error) => map_nodejs_resolver_error(error, args).await,
Self::OxcResolver(error) => map_oxc_resolver_error(error, args).await,
}
}
}
Expand Down Expand Up @@ -363,7 +363,7 @@ fn to_oxc_resolver_options(
}
}

fn map_nodejs_resolver_error(error: nodejs_resolver::Error, args: &ResolveArgs<'_>) -> Error {
async fn map_nodejs_resolver_error(error: nodejs_resolver::Error, args: &ResolveArgs<'_>) -> Error {
match error {
nodejs_resolver::Error::Io(error) => DiagnosticError::from(error.boxed()).into(),
nodejs_resolver::Error::UnexpectedJson((json_path, error)) => {
Expand All @@ -382,7 +382,10 @@ fn map_nodejs_resolver_error(error: nodejs_resolver::Error, args: &ResolveArgs<'
}
}

fn map_oxc_resolver_error(error: oxc_resolver::ResolveError, args: &ResolveArgs<'_>) -> Error {
async fn map_oxc_resolver_error(
error: oxc_resolver::ResolveError,
args: &ResolveArgs<'_>,
) -> Error {
match error {
oxc_resolver::ResolveError::InvalidPackageTarget(specifier) => {
let message = format!(
Expand Down

0 comments on commit 7701e89

Please sign in to comment.