es_resolve

Crates.ioes_resolve
lib.rses_resolve
version0.4.3
sourcesrc
created_at2022-10-14 03:20:25.102357
updated_at2023-08-22 02:57:27.357262
descriptionJavaScript/TypeScript module resolution in Rust
homepage
repositoryhttps://github.com/hanayashiki/es_resolve
max_upload_size
id687910
size45,582
wang chenyu (hanayashiki)

documentation

README

Crates.io

ES Resolve

JavaScript/TypeScript module resolution in Rust

Installation

cargo add es_resolve

Get Started

use std::path::{Path, PathBuf};
use es_resolve::*;

// Provide an exact path to the file from which we resolve
let source = PathBuf::from("tests/fixtures/relative/js.js");
// Construct an `es_resolve::EsResolver`, then call `resolve` to get the result.
// Also check `es_resolve::EsResolverError` for a list of errors that might occur!
let target = EsResolver::new("./ts", &source, TargetEnv::Browser).resolve().unwrap();
let expected_target_path = Path::new("tests/fixtures/relative/ts.ts").canonicalize().unwrap();
let expected_target = expected_target_path.to_string_lossy();

// We expect to get the absolute path to the resolved target module!
assert_eq!(target, expected_target);

Features

General Features

Feature Status Since Note
Relative Module Import 👌 0.1.0 import './App' when there is an ./App.ts ./App.tsx ./App.js etc.
Non-relative Module Import 👌 0.1.0 import '@angular/core'. See also Package.json Supports.
TypeScript Path Mapping 👌 0.1.0 import '@/App' when you define baseUrl and paths in a parent tsconfig.json.
Node Built-in Modules 👌 0.1.0 Resolve node built-in modules like "http" as-is instead of throwing an error.

Package.json Supports

Feature Status Since Note
Main Fields 👌 0.1.0 Try fields like "main", "browser", "module" in package.json by default.
Subpath Exports 👌 0.1.0 { "exports": { "import": "./index.mjs", "require": "./index.cjs" } } in package.json is gaining popularity.
Subpath Imports 👷
Commit count: 21

cargo fmt