pub struct Resolver<'a> {
pub project_root: CachedPath,
pub extensions: Extensions<'a>,
pub index_file: &'a str,
pub entries: Fields,
pub flags: Flags,
pub include_node_modules: Cow<'a, IncludeNodeModules>,
pub conditions: ExportsCondition,
pub module_dir_resolver: Option<Arc<dyn Fn(&str, &Path) -> Result<PathBuf, ResolverError> + Send + Sync>>,
/* private fields */
}
Expand description
Implements the Node.js module resolution algorithm.
Fields§
§project_root: CachedPath
The root path of the project.
extensions: Extensions<'a>
A list of file extensions to try when resolving.
index_file: &'a str
A file name (without extension) for the index file of a directory.
entries: Fields
package.json entry fields to try.
flags: Flags
Resolution features to enable.
include_node_modules: Cow<'a, IncludeNodeModules>
Configures which node_modules should be resolved.
conditions: ExportsCondition
package.json “exports” conditions to enable.
module_dir_resolver: Option<Arc<dyn Fn(&str, &Path) -> Result<PathBuf, ResolverError> + Send + Sync>>
A custom module directory resolution function, e.g. Yarn PnP.
Implementations§
Source§impl<'a> Resolver<'a>
impl<'a> Resolver<'a>
Sourcepub fn node<C: Into<CacheCow<'a>>>(project_root: &Path, cache: C) -> Self
pub fn node<C: Into<CacheCow<'a>>>(project_root: &Path, cache: C) -> Self
Creates a resolver with Node.js CommonJS settings.
Sourcepub fn node_esm<C: Into<CacheCow<'a>>>(project_root: &Path, cache: C) -> Self
pub fn node_esm<C: Into<CacheCow<'a>>>(project_root: &Path, cache: C) -> Self
Creates a resolver with Node.js ESM settings.
Sourcepub fn parcel<C: Into<CacheCow<'a>>>(project_root: &Path, cache: C) -> Self
pub fn parcel<C: Into<CacheCow<'a>>>(project_root: &Path, cache: C) -> Self
Creates a resolver with Parcel settings.
Sourcepub fn resolve(
&self,
specifier: &str,
from: &Path,
specifier_type: SpecifierType,
) -> ResolveResult
pub fn resolve( &self, specifier: &str, from: &Path, specifier_type: SpecifierType, ) -> ResolveResult
Resolves a specifier relative to the given path, with default options.
Sourcepub fn resolve_with_options(
&self,
specifier: &str,
from: &Path,
specifier_type: SpecifierType,
options: ResolveOptions,
) -> ResolveResult
pub fn resolve_with_options( &self, specifier: &str, from: &Path, specifier_type: SpecifierType, options: ResolveOptions, ) -> ResolveResult
Resolves a specifier relative to the given path, with custom options.
Sourcepub fn resolve_with_invalidations(
&self,
specifier: &str,
from: &Path,
specifier_type: SpecifierType,
invalidations: &Invalidations,
options: ResolveOptions,
) -> Result<ResolutionAndQuery, ResolverError>
pub fn resolve_with_invalidations( &self, specifier: &str, from: &Path, specifier_type: SpecifierType, invalidations: &Invalidations, options: ResolveOptions, ) -> Result<ResolutionAndQuery, ResolverError>
Resolves a specifier with pre-existing Invalidations.
Sourcepub fn resolve_side_effects(
&self,
path: &Path,
invalidations: &Invalidations,
) -> Result<bool, ResolverError>
pub fn resolve_side_effects( &self, path: &Path, invalidations: &Invalidations, ) -> Result<bool, ResolverError>
Returns whether the given path has side effects, according to its parent package.json.
Sourcepub fn resolve_module_type(
&self,
path: &Path,
invalidations: &Invalidations,
) -> Result<ModuleType, ResolverError>
pub fn resolve_module_type( &self, path: &Path, invalidations: &Invalidations, ) -> Result<ModuleType, ResolverError>
Returns the module type (CommonJS, ESM, or JSON) of the given path,
according to either its extension or the package.json type
field.
Auto Trait Implementations§
impl<'a> Freeze for Resolver<'a>
impl<'a> !RefUnwindSafe for Resolver<'a>
impl<'a> Send for Resolver<'a>
impl<'a> Sync for Resolver<'a>
impl<'a> Unpin for Resolver<'a>
impl<'a> !UnwindSafe for Resolver<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more