mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +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
|
let mut tsconfig_string = self
|
||||||
.fs
|
.fs
|
||||||
.read_to_string(&tsconfig_path)
|
.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 =
|
let mut tsconfig =
|
||||||
TsConfig::parse(&tsconfig_path, &mut tsconfig_string).map_err(|error| {
|
TsConfig::parse(&tsconfig_path, &mut tsconfig_string).map_err(|error| {
|
||||||
ResolveError::from_serde_json_error(tsconfig_path.to_path_buf(), &error)
|
ResolveError::from_serde_json_error(tsconfig_path.to_path_buf(), &error)
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,10 @@ pub enum ResolveError {
|
||||||
#[error("Path not found {0}")]
|
#[error("Path not found {0}")]
|
||||||
NotFound(PathBuf),
|
NotFound(PathBuf),
|
||||||
|
|
||||||
|
/// Tsconfig not found
|
||||||
|
#[error("Tsconfig not found {0}")]
|
||||||
|
TsconfigNotFound(PathBuf),
|
||||||
|
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
IOError(IOError),
|
IOError(IOError),
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -910,7 +910,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
|
||||||
ctx: &mut ResolveContext,
|
ctx: &mut ResolveContext,
|
||||||
) -> ResolveState {
|
) -> ResolveState {
|
||||||
let Some(tsconfig_path) = &self.options.tsconfig else { return Ok(None) };
|
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);
|
let paths = tsconfig.resolve(cached_path.path(), specifier);
|
||||||
for path in paths {
|
for path in paths {
|
||||||
let cached_path = self.cache.value(&path);
|
let cached_path = self.cache.value(&path);
|
||||||
|
|
@ -921,11 +921,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_tsconfig(
|
fn load_tsconfig(&self, path: &Path) -> Result<Arc<TsConfig>, ResolveError> {
|
||||||
&self,
|
|
||||||
path: &Path,
|
|
||||||
ctx: &mut ResolveContext,
|
|
||||||
) -> Result<Arc<TsConfig>, ResolveError> {
|
|
||||||
self.cache.tsconfig(path, |tsconfig| {
|
self.cache.tsconfig(path, |tsconfig| {
|
||||||
let directory = self.cache.value(tsconfig.directory());
|
let directory = self.cache.value(tsconfig.directory());
|
||||||
// Extend tsconfig
|
// Extend tsconfig
|
||||||
|
|
@ -935,10 +931,8 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
|
||||||
None => return Err(ResolveError::Specifier(SpecifierError::Empty)),
|
None => return Err(ResolveError::Specifier(SpecifierError::Empty)),
|
||||||
Some(b'/') => PathBuf::from(tsconfig_extend_specifier),
|
Some(b'/') => PathBuf::from(tsconfig_extend_specifier),
|
||||||
Some(b'.') => tsconfig.directory().normalize_with(tsconfig_extend_specifier),
|
Some(b'.') => tsconfig.directory().normalize_with(tsconfig_extend_specifier),
|
||||||
_ => {
|
_ => self
|
||||||
let mut new_ctx = ResolveContext::default();
|
.clone_with_options(ResolveOptions {
|
||||||
new_ctx.0.depth = ctx.depth + 1;
|
|
||||||
self.clone_with_options(ResolveOptions {
|
|
||||||
description_files: vec![],
|
description_files: vec![],
|
||||||
extensions: vec![],
|
extensions: vec![],
|
||||||
main_files: vec!["tsconfig.json".into()],
|
main_files: vec!["tsconfig.json".into()],
|
||||||
|
|
@ -947,15 +941,18 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
|
||||||
.load_package_self_or_node_modules(
|
.load_package_self_or_node_modules(
|
||||||
&directory,
|
&directory,
|
||||||
tsconfig_extend_specifier,
|
tsconfig_extend_specifier,
|
||||||
&mut new_ctx,
|
&mut ResolveContext::default(),
|
||||||
)?
|
)
|
||||||
.to_path_buf()
|
.map_err(|err| match err {
|
||||||
}
|
ResolveError::NotFound(path) => ResolveError::TsconfigNotFound(path),
|
||||||
|
_ => err,
|
||||||
|
})?
|
||||||
|
.to_path_buf(),
|
||||||
};
|
};
|
||||||
extended_tsconfig_paths.push(extended_tsconfig_path);
|
extended_tsconfig_paths.push(extended_tsconfig_path);
|
||||||
}
|
}
|
||||||
for extended_tsconfig_path in extended_tsconfig_paths {
|
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);
|
tsconfig.extend_tsconfig(&extended_tsconfig);
|
||||||
}
|
}
|
||||||
// Load project references
|
// Load project references
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue