use std::{
fmt::Debug,
path::{Path, PathBuf},
sync::Arc,
};
use crate::{Ctx, PackageJson, ResolveError, ResolveOptions, TsConfig};
#[allow(clippy::missing_errors_doc)] pub trait Cache: Sized {
type Cp: CachedPath + Clone;
type Pj: PackageJson;
type Tc: TsConfig + Debug;
fn clear(&self);
fn value(&self, path: &Path) -> Self::Cp;
fn canonicalize(&self, path: &Self::Cp) -> Result<PathBuf, ResolveError>;
fn is_file(&self, path: &Self::Cp, ctx: &mut Ctx) -> bool;
fn is_dir(&self, path: &Self::Cp, ctx: &mut Ctx) -> bool;
#[allow(clippy::type_complexity)]
fn get_package_json(
&self,
path: &Self::Cp,
options: &ResolveOptions,
ctx: &mut Ctx,
) -> Result<Option<(Self::Cp, Arc<Self::Pj>)>, ResolveError>;
fn get_tsconfig<F: FnOnce(&mut Self::Tc) -> Result<(), ResolveError>>(
&self,
root: bool,
path: &Path,
callback: F,
) -> Result<Arc<Self::Tc>, ResolveError>;
}
#[allow(clippy::missing_errors_doc)] pub trait CachedPath: Sized {
fn path(&self) -> &Path;
fn to_path_buf(&self) -> PathBuf;
fn parent(&self) -> Option<&Self>;
fn module_directory<C: Cache<Cp = Self>>(
&self,
module_name: &str,
cache: &C,
ctx: &mut Ctx,
) -> Option<Self>;
fn cached_node_modules<C: Cache<Cp = Self>>(&self, cache: &C, ctx: &mut Ctx) -> Option<Self>;
#[allow(clippy::type_complexity)]
fn find_package_json<C: Cache<Cp = Self>>(
&self,
options: &ResolveOptions,
cache: &C,
ctx: &mut Ctx,
) -> Result<Option<(Self, Arc<C::Pj>)>, ResolveError>;
#[must_use]
fn add_extension<C: Cache<Cp = Self>>(&self, ext: &str, cache: &C) -> Self;
#[must_use]
fn replace_extension<C: Cache<Cp = Self>>(&self, ext: &str, cache: &C) -> Self;
#[must_use]
fn normalize_with<C: Cache<Cp = Self>>(&self, subpath: impl AsRef<Path>, cache: &C) -> Self;
#[must_use]
fn normalize_root<C: Cache<Cp = Self>>(&self, _cache: &C) -> Self;
}