Struct rspack_resolver::ResolveOptions

source ·
pub struct ResolveOptions {
Show 22 fields pub tsconfig: Option<TsconfigOptions>, pub alias: Alias, pub alias_fields: Vec<Vec<String>>, pub condition_names: Vec<String>, pub description_files: Vec<String>, pub enforce_extension: EnforceExtension, pub exports_fields: Vec<Vec<String>>, pub imports_fields: Vec<Vec<String>>, pub extension_alias: Vec<(String, Vec<String>)>, pub extensions: Vec<String>, pub fallback: Alias, pub fully_specified: bool, pub main_fields: Vec<String>, pub main_files: Vec<String>, pub modules: Vec<String>, pub resolve_to_context: bool, pub prefer_relative: bool, pub prefer_absolute: bool, pub restrictions: Vec<Restriction>, pub roots: Vec<PathBuf>, pub symlinks: bool, pub builtin_modules: bool,
}
Expand description

Module Resolution Options

Options are directly ported from enhanced-resolve.

See webpack resolve for information and examples

Fields§

§tsconfig: Option<TsconfigOptions>

Path to TypeScript configuration file.

Default None

§alias: Alias

Create aliases to import or require certain modules more easily.

An alias is used to replace a whole path or part of a path. For example, to alias a commonly used src/ folders: vec![("@/src"), vec![AliasValue::Path("/path/to/src")]]

A trailing $ can also be added to the given object’s keys to signify an exact match.

See webpack’s resolve.alias documentation for a list of use cases.

§alias_fields: Vec<Vec<String>>

A list of alias fields in description files.

Specify a field, such as browser, to be parsed according to this specification. Can be a path to json object such as ["path", "to", "exports"].

Default []

§condition_names: Vec<String>

Condition names for exports field which defines entry points of a package.

The key order in the exports field is significant. During condition matching, earlier entries have higher priority and take precedence over later entries.

Default []

§description_files: Vec<String>

The JSON files to use for descriptions. (There was once a bower.json.)

Default ["package.json"]

§enforce_extension: EnforceExtension

Set to EnforceExtension::Enabled for ESM Mandatory file extensions.

If enforce_extension is set to EnforceExtension::Enabled, resolution will not allow extension-less files. This means require('./foo.js') will resolve, while require('./foo') will not.

The default value for enforce_extension is EnforceExtension::Auto, which is changed upon initialization.

It changes to EnforceExtension::Enabled if ResolveOptions::extensions contains an empty string; otherwise, this value changes to EnforceExtension::Disabled.

Explicitly set the value to EnforceExtension::Disabled to disable this automatic behavior.

For reference, this behavior is aligned with enhanced-resolve. See https://github.com/webpack/enhanced-resolve/pull/285.

§exports_fields: Vec<Vec<String>>

A list of exports fields in description files.

Can be a path to a JSON object such as ["path", "to", "exports"].

Default [["exports"]].

§imports_fields: Vec<Vec<String>>

Fields from package.json which are used to provide the internal requests of a package (requests starting with # are considered internal).

Can be a path to a JSON object such as ["path", "to", "imports"].

Default [["imports"]].

§extension_alias: Vec<(String, Vec<String>)>

An object which maps extension to extension aliases.

Default {}

§extensions: Vec<String>

Attempt to resolve these extensions in order.

If multiple files share the same name but have different extensions, will resolve the one with the extension listed first in the array and skip the rest.

All extensions must have a leading dot.

Default [".js", ".json", ".node"]

§fallback: Alias

Redirect module requests when normal resolving fails.

Default []

§fully_specified: bool

Request passed to resolve is already fully specified and extensions or main files are not resolved for it (they are still resolved for internal requests).

See also webpack configuration resolve.fullySpecified

Default false

§main_fields: Vec<String>

A list of main fields in description files

Default ["main"].

§main_files: Vec<String>

The filename to be used while resolving directories.

Default ["index"]

§modules: Vec<String>

A list of directories to resolve modules from, can be absolute path or folder name.

Default ["node_modules"]

§resolve_to_context: bool

Resolve to a context instead of a file.

Default false

§prefer_relative: bool

Prefer to resolve module requests as relative requests instead of using modules from node_modules directories.

Default false

§prefer_absolute: bool

Prefer to resolve server-relative urls as absolute paths before falling back to resolve in ResolveOptions::roots.

Default false

§restrictions: Vec<Restriction>

A list of resolve restrictions to restrict the paths that a request can be resolved on.

Default []

§roots: Vec<PathBuf>

A list of directories where requests of server-relative URLs (starting with ‘/’) are resolved. On non-Windows systems these requests are resolved as an absolute path first.

Default []

§symlinks: bool

Whether to resolve symlinks to their symlinked location. When enabled, symlinked resources are resolved to their real path, not their symlinked location. Note that this may cause module resolution to fail when using tools that symlink packages (like npm link).

Default true

§builtin_modules: bool

Whether to parse module.builtinModules or not. For example, “zlib” will throw crate::ResolveError::Builtin when set to true.

Default false

Implementations§

source§

impl ResolveOptions

source

pub fn with_condition_names(self, names: &[&str]) -> Self

§Examples
use oxc_resolver::ResolveOptions;

let options = ResolveOptions::default().with_condition_names(&["bar"]);
assert_eq!(options.condition_names, vec!["bar".to_string()])
source

pub fn with_builtin_modules(self, flag: bool) -> Self

§Examples
use oxc_resolver::ResolveOptions;

let options = ResolveOptions::default().with_builtin_modules(false);
assert_eq!(options.builtin_modules, false)
source

pub fn with_root<P: AsRef<Path>>(self, root: P) -> Self

Adds a single root to the options

§Examples
use oxc_resolver::ResolveOptions;
use std::path::{Path, PathBuf};

let options = ResolveOptions::default().with_root("foo");
assert_eq!(options.roots, vec![PathBuf::from("foo")])
source

pub fn with_extension<S: Into<String>>(self, extension: S) -> Self

Adds a single extension to the list of extensions

§Examples
use oxc_resolver::ResolveOptions;
use std::path::{Path, PathBuf};

let options = ResolveOptions::default().with_extension("jsonc");
assert!(options.extensions.contains(&"jsonc".to_string()));
source

pub fn with_main_field<S: Into<String>>(self, field: S) -> Self

Adds a single main field to the list of fields

§Examples
use oxc_resolver::ResolveOptions;
use std::path::{Path, PathBuf};

let options = ResolveOptions::default().with_main_field("something");
assert!(options.main_fields.contains(&"something".to_string()));
source

pub fn with_force_extension(self, enforce_extension: EnforceExtension) -> Self

Changes how the extension should be treated

§Examples
use oxc_resolver::{ResolveOptions, EnforceExtension};
use std::path::{Path, PathBuf};

let options = ResolveOptions::default().with_force_extension(EnforceExtension::Enabled);
assert_eq!(options.enforce_extension, EnforceExtension::Enabled);
source

pub fn with_fully_specified(self, fully_specified: bool) -> Self

Sets the value for ResolveOptions::fully_specified

§Examples
use oxc_resolver::{ResolveOptions};
use std::path::{Path, PathBuf};

let options = ResolveOptions::default().with_fully_specified(true);
assert_eq!(options.fully_specified, true);
source

pub fn with_prefer_relative(self, flag: bool) -> Self

Sets the value for ResolveOptions::prefer_relative

§Examples
use oxc_resolver::{ResolveOptions};
use std::path::{Path, PathBuf};

let options = ResolveOptions::default().with_prefer_relative(true);
assert_eq!(options.prefer_relative, true);
source

pub fn with_prefer_absolute(self, flag: bool) -> Self

Sets the value for ResolveOptions::prefer_absolute

§Examples
use oxc_resolver::{ResolveOptions};
use std::path::{Path, PathBuf};

let options = ResolveOptions::default().with_prefer_absolute(true);
assert_eq!(options.prefer_absolute, true);

Changes the value of ResolveOptions::symlinks

§Examples
use oxc_resolver::{ResolveOptions};

let options = ResolveOptions::default().with_symbolic_link(false);
assert_eq!(options.symlinks, false);
source

pub fn with_module<M: Into<String>>(self, module: M) -> Self

Adds a module to ResolveOptions::modules

§Examples
use oxc_resolver::{ResolveOptions};

let options = ResolveOptions::default().with_module("module");
assert!(options.modules.contains(&"module".to_string()));
source

pub fn with_main_file<M: Into<String>>(self, module: M) -> Self

Adds a main file to ResolveOptions::main_files

§Examples
use oxc_resolver::{ResolveOptions};

let options = ResolveOptions::default().with_main_file("foo");
assert!(options.main_files.contains(&"foo".to_string()));

Trait Implementations§

source§

impl Clone for ResolveOptions

source§

fn clone(&self) -> ResolveOptions

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ResolveOptions

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for ResolveOptions

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Display for ResolveOptions

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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

§

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> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more