mirror of
https://github.com/danbulant/oxc
synced 2026-05-21 13:18:59 +00:00
feat(resolver): add TsconfigNotFound error (#905)
This commit is contained in:
parent
814f71c15e
commit
b7a0b4f27f
3 changed files with 17 additions and 16 deletions
|
|
@ -74,7 +74,7 @@ impl<Fs: FileSystem> Cache<Fs> {
|
|||
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)
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
||||
|
|
|
|||
|
|
@ -910,7 +910,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
|
|||
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<Fs: FileSystem> ResolverGeneric<Fs> {
|
|||
Ok(None)
|
||||
}
|
||||
|
||||
fn load_tsconfig(
|
||||
&self,
|
||||
path: &Path,
|
||||
ctx: &mut ResolveContext,
|
||||
) -> Result<Arc<TsConfig>, ResolveError> {
|
||||
fn load_tsconfig(&self, path: &Path) -> Result<Arc<TsConfig>, ResolveError> {
|
||||
self.cache.tsconfig(path, |tsconfig| {
|
||||
let directory = self.cache.value(tsconfig.directory());
|
||||
// Extend tsconfig
|
||||
|
|
@ -935,10 +931,8 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
|
|||
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<Fs: FileSystem> ResolverGeneric<Fs> {
|
|||
.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
|
||||
|
|
|
|||
Loading…
Reference in a new issue