diff --git a/crates/oxc_resolver/src/cache.rs b/crates/oxc_resolver/src/cache.rs index 9e01ce243..3d8659a16 100644 --- a/crates/oxc_resolver/src/cache.rs +++ b/crates/oxc_resolver/src/cache.rs @@ -74,7 +74,7 @@ impl Cache { let mut tsconfig_string = self .fs .read_to_string(&tsconfig_path) - .map_err(|_| ResolveError::NotFound(tsconfig_path.to_path_buf()))?; + .map_err(|_| ResolveError::TsconfigNotFound(tsconfig_path.to_path_buf()))?; let mut tsconfig = TsConfig::parse(&tsconfig_path, &mut tsconfig_string).map_err(|error| { ResolveError::from_serde_json_error(tsconfig_path.to_path_buf(), &error) diff --git a/crates/oxc_resolver/src/error.rs b/crates/oxc_resolver/src/error.rs index d85c09b6b..6dc108c61 100644 --- a/crates/oxc_resolver/src/error.rs +++ b/crates/oxc_resolver/src/error.rs @@ -22,6 +22,10 @@ pub enum ResolveError { #[error("Path not found {0}")] NotFound(PathBuf), + /// Tsconfig not found + #[error("Tsconfig not found {0}")] + TsconfigNotFound(PathBuf), + #[error("{0}")] IOError(IOError), diff --git a/crates/oxc_resolver/src/lib.rs b/crates/oxc_resolver/src/lib.rs index fe420da6b..1e73d4553 100644 --- a/crates/oxc_resolver/src/lib.rs +++ b/crates/oxc_resolver/src/lib.rs @@ -910,7 +910,7 @@ impl ResolverGeneric { ctx: &mut ResolveContext, ) -> ResolveState { let Some(tsconfig_path) = &self.options.tsconfig else { return Ok(None) }; - let tsconfig = self.load_tsconfig(tsconfig_path, ctx)?; + let tsconfig = self.load_tsconfig(tsconfig_path)?; let paths = tsconfig.resolve(cached_path.path(), specifier); for path in paths { let cached_path = self.cache.value(&path); @@ -921,11 +921,7 @@ impl ResolverGeneric { Ok(None) } - fn load_tsconfig( - &self, - path: &Path, - ctx: &mut ResolveContext, - ) -> Result, ResolveError> { + fn load_tsconfig(&self, path: &Path) -> Result, ResolveError> { self.cache.tsconfig(path, |tsconfig| { let directory = self.cache.value(tsconfig.directory()); // Extend tsconfig @@ -935,10 +931,8 @@ impl ResolverGeneric { None => return Err(ResolveError::Specifier(SpecifierError::Empty)), Some(b'/') => PathBuf::from(tsconfig_extend_specifier), Some(b'.') => tsconfig.directory().normalize_with(tsconfig_extend_specifier), - _ => { - let mut new_ctx = ResolveContext::default(); - new_ctx.0.depth = ctx.depth + 1; - self.clone_with_options(ResolveOptions { + _ => self + .clone_with_options(ResolveOptions { description_files: vec![], extensions: vec![], main_files: vec!["tsconfig.json".into()], @@ -947,15 +941,18 @@ impl ResolverGeneric { .load_package_self_or_node_modules( &directory, tsconfig_extend_specifier, - &mut new_ctx, - )? - .to_path_buf() - } + &mut ResolveContext::default(), + ) + .map_err(|err| match err { + ResolveError::NotFound(path) => ResolveError::TsconfigNotFound(path), + _ => err, + })? + .to_path_buf(), }; extended_tsconfig_paths.push(extended_tsconfig_path); } for extended_tsconfig_path in extended_tsconfig_paths { - let extended_tsconfig = self.load_tsconfig(&extended_tsconfig_path, ctx)?; + let extended_tsconfig = self.load_tsconfig(&extended_tsconfig_path)?; tsconfig.extend_tsconfig(&extended_tsconfig); } // Load project references