From 7701e89e9d7a0faa20d701f9ad545eeb25aadd07 Mon Sep 17 00:00:00 2001 From: Hana Date: Tue, 2 Jan 2024 17:41:19 +0800 Subject: [PATCH] feat: resolve with hint --- crates/rspack_core/src/resolver/mod.rs | 12 +++++++++--- crates/rspack_core/src/resolver/resolver_impl.rs | 13 ++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/crates/rspack_core/src/resolver/mod.rs b/crates/rspack_core/src/resolver/mod.rs index d8bcde6e7fc3..720e254c74e8 100644 --- a/crates/rspack_core/src/resolver/mod.rs +++ b/crates/rspack_core/src/resolver/mod.rs @@ -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); diff --git a/crates/rspack_core/src/resolver/resolver_impl.rs b/crates/rspack_core/src/resolver/resolver_impl.rs index df24c9053b7d..afcbcd922ed0 100644 --- a/crates/rspack_core/src/resolver/resolver_impl.rs +++ b/crates/rspack_core/src/resolver/resolver_impl.rs @@ -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, } } } @@ -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)) => { @@ -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!(