Skip to main content

Crate rspack_resolver

Crate rspack_resolver 

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

§Feature flags

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

FileMetadata
Metadata information about a file
FileSystemOptions
FileSystemOs
Operating System
InternedPath
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 Hash below).
JSONError
JSON error from serde_json::Error
PackageJson
Deserialized package.json
Resolution
The final path resolution with optional ?query and #fragment
ResolveContext
Context returned from the Resolver::resolve_with_context API
ResolveOptions
Module Resolution Options
ResolverGeneric
Generic implementation of the resolver, can be configured by the FileSystem trait
TsconfigOptions
Tsconfig Options for ResolveOptions::tsconfig

Enums§

AliasValue
Alias Value for ResolveOptions::alias and ResolveOptions::fallback
EnforceExtension
Value for ResolveOptions::enforce_extension
JSONValue
Borrowed JSON-DOM Value, consider using the ValueTrait to access its content
ModuleType
ResolveError
All resolution errors
Restriction
Value for ResolveOptions::restrictions
SpecifierError
Error for ResolveError::Specifier
TsconfigReferences
Configuration for TsconfigOptions::references

Constants§

NODEJS_BUILTINS
Node.js built-in modules

Traits§

FileSystem
File System abstraction used for ResolverGeneric

Type Aliases§

Alias
Alias for ResolveOptions::alias and ResolveOptions::fallback
InternedPathSet
A standard HashSet using InternedPath as the key type with a custom Hasher that just uses the precomputed hash for speed instead of calculating it.
Resolver
Resolver with the current operating system as the file system