pub struct ResolveOptions {Show 25 fields
pub cwd: Option<PathBuf>,
pub tsconfig: Option<TsconfigOptions>,
pub alias: Alias,
pub alias_fields: Vec<Vec<String>>,
pub condition_names: 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,
pub module_type: bool,
pub allow_package_exports_in_directory_resolve: bool,
pub yarn_pnp: bool,
}Expand description
Module Resolution Options
Options are directly ported from enhanced-resolve.
See webpack resolve for information and examples
Fields§
§cwd: Option<PathBuf>Current working directory, used for testing purposes.
tsconfig: Option<TsconfigOptions>Path to TypeScript configuration file.
Default None
alias: AliasCreate 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 []
enforce_extension: EnforceExtensionSet 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: AliasRedirect module requests when normal resolving fails.
Default []
fully_specified: boolRequest 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: boolResolve to a context instead of a file.
Default false
prefer_relative: boolPrefer to resolve module requests as relative requests instead of using modules from node_modules directories.
Default false
prefer_absolute: boolPrefer 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: boolWhether to resolve symlinks to their symlinked location, if possible.
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).
Even if this option has been enabled, the resolver may decide not to follow the symlinks if the target cannot be
represented as a valid path for require or import statements in NodeJS. Specifically, we won’t follow the symlink if:
-
On Windows, the symlink is a Volume mount point to a Volume that does not have a drive letter. See: How to mount a drive in a folder.
-
On Windows, the symlink points to a DOS device path that cannot be reduced into a traditional DOS path. For example, all of the following symlink targets will not be followed:
\\.\Volume{b75e2c83-0000-0000-0000-602f00000000}\folder\(Volume GUID)\\.\BootPartition\folder\file.ts(Drive name)
DOS device path either pointing to a drive with drive letter, or a UNC path, will be simplified and followed, such as
\\.\D:\path\to\file: reduced toD:\path\to\file;\\.\UNC\server\share\path\to\file: reduced to\\server\share\path\to\file.
Default true
builtin_modules: boolWhether to parse module.builtinModules or not. For example, “zlib” will throw crate::ResolveError::Builtin when set to true.
Default false
module_type: boolResolve crate::Resolution::module_type.
Default: false
allow_package_exports_in_directory_resolve: boolAllow exports field in require('../directory').
This is not part of the spec but some vite projects rely on this behavior. See
Default: false
yarn_pnp: boolEnable Yarn Plug’n’Play?.
Pass in !!process.versions.pnp if called from node.js.
Default: when env var OXC_RESOLVER_YARN_PNP is set.
Implementations§
Source§impl ResolveOptions
impl ResolveOptions
Sourcepub fn with_condition_names(self, names: &[&str]) -> Self
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()])Sourcepub const fn with_builtin_modules(self, flag: bool) -> Self
pub const 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)Sourcepub fn with_root<P: AsRef<Path>>(self, root: P) -> Self
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")])Sourcepub fn with_extension<S: Into<String>>(self, extension: S) -> Self
pub fn with_extension<S: Into<String>>(self, extension: S) -> Self
Adds a single extension to the list of extensions. Extension must start with a .
§Examples
use oxc_resolver::ResolveOptions;
use std::path::{Path, PathBuf};
let options = ResolveOptions::default().with_extension(".jsonc");
assert!(options.extensions.contains(&".jsonc".to_string()));Sourcepub fn with_main_field<S: Into<String>>(self, field: S) -> Self
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()));Sourcepub const fn with_force_extension(
self,
enforce_extension: EnforceExtension,
) -> Self
pub const 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);Sourcepub const fn with_fully_specified(self, fully_specified: bool) -> Self
pub const 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);Sourcepub const fn with_prefer_relative(self, flag: bool) -> Self
pub const 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);Sourcepub const fn with_prefer_absolute(self, flag: bool) -> Self
pub const 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);Sourcepub const fn with_symbolic_link(self, flag: bool) -> Self
pub const fn with_symbolic_link(self, flag: bool) -> Self
Changes the value of ResolveOptions::symlinks
§Examples
use oxc_resolver::{ResolveOptions};
let options = ResolveOptions::default().with_symbolic_link(false);
assert_eq!(options.symlinks, false);Sourcepub fn with_module<M: Into<String>>(self, module: M) -> Self
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()));Sourcepub fn with_main_file<M: Into<String>>(self, module: M) -> Self
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
impl Clone for ResolveOptions
Source§fn clone(&self) -> ResolveOptions
fn clone(&self) -> ResolveOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more