parcel_resolver

Struct Resolver

Source
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>

Source

pub fn node<C: Into<CacheCow<'a>>>(project_root: &Path, cache: C) -> Self

Creates a resolver with Node.js CommonJS settings.

Source

pub fn node_esm<C: Into<CacheCow<'a>>>(project_root: &Path, cache: C) -> Self

Creates a resolver with Node.js ESM settings.

Source

pub fn parcel<C: Into<CacheCow<'a>>>(project_root: &Path, cache: C) -> Self

Creates a resolver with Parcel settings.

Source

pub fn resolve( &self, specifier: &str, from: &Path, specifier_type: SpecifierType, ) -> ResolveResult

Resolves a specifier relative to the given path, with default options.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn cache(&self) -> &Cache

Returns the resolution cache.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T