Crate oxc_resolver
source ·Expand description
§Oxc Resolver
Node.js Module Resolution.
All configuration options are aligned with enhanced-resolve.
§References:
- Algorithm adapted from Node.js CommonJS Module Resolution Algorithm and ECMAScript Module Resolution Algorithm
- Tests are ported from enhanced-resolve
- Some code adapted from parcel-resolver
§Example
ⓘ
use std::{env, path::PathBuf};
use oxc_resolver::{AliasValue, ResolveOptions, Resolver};
fn main() {
// Path to directory, must be in absolute path.
let path = env::args().nth(1).expect("path");
let specifier = env::args().nth(2).expect("specifier");
let path = PathBuf::from(path).canonicalize().unwrap();
println!("path: {path:?}");
println!("request: {specifier}");
let options = ResolveOptions {
alias_fields: vec![vec!["browser".into()]],
alias: vec![("asdf".into(), vec![AliasValue::Path("./test.js".into())])],
..ResolveOptions::default()
};
match Resolver::new(options).resolve(path, &specifier) {
Err(error) => println!("Error: {error}"),
Ok(resolution) => println!("Resolved: {:?}", resolution.full_path()),
}
}Structs§
- Metadata information about a file
- JSON error from serde_json::Error
- Deserialized package.json
- The final path resolution with optional
?queryand#fragment - Module Resolution Options
- Generic implementation of the resolver, can be configured by the FileSystem trait
- Tsconfig Options for ResolveOptions::tsconfig
Enums§
- Alias Value for ResolveOptions::alias and ResolveOptions::fallback
- Value for ResolveOptions::enforce_extension
- All resolution errors
- Value for ResolveOptions::restrictions
- Error for ResolveError::Specifier
- Configuration for TsconfigOptions::references
Traits§
- File System abstraction used for
ResolverGeneric
Type Aliases§
- Alias for ResolveOptions::alias and ResolveOptions::fallback
- Resolver with the current operating system as the file system