Expand description
§Rspack Resolver
Node.js CommonJS and ECMAScript Module Resolution.
Released on crates.io and npm.
A module resolution is the process of finding the file referenced by a module specifier in
import "specifier" or require("specifier").
All configuration options are aligned with webpack’s enhanced-resolve.
§Terminology
§Specifier
For CommonJS modules,
the specifier is the string passed to the require function. e.g. "id" in require("id").
For ECMAScript modules,
the specifier of an import statement is the string after the from keyword,
e.g. 'specifier' in import 'specifier' or import { sep } from 'specifier'.
Specifiers are also used in export from statements, and as the argument to an import() expression.
This is also named “request” in some places.
§References:
- Algorithm adapted from Node.js CommonJS Module Resolution Algorithm and ECMAScript Module Resolution Algorithm.
- Tests are ported from enhanced-resolve.
- Some code is adapted from parcel-resolver.
- The documentation is copied from webpack’s resolve configuration.
§Feature flags
package_json_raw_json_api— Enables the PackageJson::raw_json API, which returns thepackage.jsonwithserde_json::Value.yarn_pnp(enabled by default) — Yarn Plug’n’Play
§Example
ⓘ
use rspack_resolver::{ResolveOptions, Resolver};
let options = ResolveOptions {
extensions: vec![".js".into(), ".ts".into()],
condition_names: vec!["node".into(), "import".into()],
..ResolveOptions::default()
};
match Resolver::new(options).resolve(path, specifier).await {
Err(error) => println!("Error: {error}"),
Ok(resolution) => println!("Resolved: {:?}", resolution.full_path()),
}Structs§
- File
Metadata - Metadata information about a file
- File
System Options - File
System Os - Operating System
- Interned
Path - An interned path: equal paths share one allocation process-wide, so equality is a pointer
comparison and each path is stored once. Hashing still uses the precomputed content hash
(see
Hashbelow). - JSON
Error - JSON error from serde_json::Error
- Package
Json - Deserialized package.json
- Resolution
- The final path resolution with optional
?queryand#fragment - Resolve
Context - Context returned from the Resolver::resolve_with_context API
- Resolve
Options - Module Resolution Options
- Resolver
Generic - Generic implementation of the resolver, can be configured by the FileSystem trait
- Tsconfig
Options - Tsconfig Options for ResolveOptions::tsconfig
Enums§
- Alias
Value - Alias Value for ResolveOptions::alias and ResolveOptions::fallback
- Enforce
Extension - Value for ResolveOptions::enforce_extension
- JSON
Value - Borrowed JSON-DOM Value, consider using the
ValueTraitto access its content - Module
Type - Resolve
Error - All resolution errors
- Restriction
- Value for ResolveOptions::restrictions
- Specifier
Error - Error for ResolveError::Specifier
- Tsconfig
References - Configuration for TsconfigOptions::references
Constants§
- NODEJS_
BUILTINS - Node.js built-in modules
Traits§
- File
System - File System abstraction used for
ResolverGeneric
Type Aliases§
- Alias
- Alias for ResolveOptions::alias and ResolveOptions::fallback
- Interned
Path Set - A standard
HashSetusingInternedPathas the key type with a customHasherthat just uses the precomputed hash for speed instead of calculating it. - Resolver
- Resolver with the current operating system as the file system