Resolve JavaScript/TypeScript module with Rust

Overview

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 πŸ‘·
You might also like...
Threadless Module Stomping In Rust with some features
Threadless Module Stomping In Rust with some features

NovaLdr is a Threadless Module Stomping written in Rust, designed as a learning project while exploring the world of malware development. It uses advanced techniques like indirect syscalls and string encryption to achieve its functionalities. This project is not intended to be a complete or polished product but rather a journey into the technical aspects of malware, showcasing various techniques and features.

A Rust implementation of Haxe Module Manager (hmm)

hmm-rs A Rust implementation of Haxe Module Manager (hmm) Installation hmm-rs can be installed as a binary from crates.io: https://crates.io/crates/hm

The module graph logic for Deno CLI

deno_graph The module graph/dependency logic for the Deno CLI. This repository is a Rust crate which provides the foundational code to be able to buil

An experimental, work-in-progress PAM module for Tailscale

Experimental Tailscale PAM Module This is a very very experimental Tailscale PAM module that allows you to SSH using your Tailscale credentials. This

This PAM module provides ssh-agent based authentication

PAM-RSSH This PAM module provides ssh-agent based authentication. The primary design goal is to avoid typing password when you sudo on remote servers.

COCONUT Secure VM Service Module

This is the source code repository for the COCONUT Secure VM Service Module (SVSM), a software which aims to provide secure services and device emulations to guest operating systems in confidential virtual machines (CVMs). It requires AMD Secure Encrypted Virtualization with Secure Nested Paging (AMD SEV-SNP), especially the VM Privilege Level (VMPL) feature.

Custom module for showing the weather in Waybar, using the great wttr.io
Custom module for showing the weather in Waybar, using the great wttr.io

wttrbar a simple but detailed weather indicator for Waybar using wttr.in. Installation Compile yourself using cargo build --release, or download the p

A PAM module that runs multiple other PAM modules in parallel, succeeding as long as one of them succeeds.

PAM Any A PAM module that runs multiple other PAM modules in parallel, succeeding as long as one of them succeeds. Development I created a VM to test

Pure Rust implementation of Javascript Object Signing and Encryption (JOSE)

RustCrypto: JOSE Pure Rust implementation of Javascript Object Signing and Encryption (JOSE) License All crates licensed under either of Apache Licens

Owner
wang chenyu
δ½•γ‚’γ™γ‚Œγ°ζ‚ͺι­”γ‚’ζŠΌγ—ι€€γ‘γ‚‹
wang chenyu
Js-macros - Quickly prototype Rust procedural macros using JavaScript or TypeScript!

js-macros Quickly prototype Rust procedural macros using JavaScript or TypeScript! Have you ever thought "this would be a great use case for a procedu

null 15 Jun 17, 2022
Tools - The Rome Toolchain. A linter, compiler, bundler, and more for JavaScript, TypeScript, HTML, Markdown, and CSS.

Rome is currently being rewritten in Rust. Read more about it in our latest blog post. The documentation below is out of date and available for poster

Rome 22k Jan 3, 2023
A Faster(⚑) formatter, linter, bundler, and more for JavaScript, TypeScript, JSON, HTML, Markdown, and CSS Lapce Plugin

Lapce Plugin for Rome Lapce-rome is a Lapce plugin for rome, The Rome is faster ⚑ , A formatter, linter, compiler, bundler, and more for JavaScript, T

xiaoxin 7 Dec 16, 2022
compile TypeScript or JavaScript to binaries

the powr project Development is paused until 2023. ?? powr aims to be a javascript/typescript engine to power serverless functions over the web. the j

powr.js 18 Dec 29, 2022
JavaScript/TypeScript runtime Deno was meant to be.

Project Bueno (temporary name) Bueno is a web-standards focused JS/TS runtime with as much tooling built-in as possible. It is meant to be both a lear

Bueno 22 Sep 3, 2023
A Typescript interpreter in Rust.

typescript This is a Rust native implementation of a Typescript Parser and a JIT execution engine. This project comes in two crates: [typescript-ast]:

Arne Simon 4 Oct 31, 2022
CLI tool to quickly create React + Typescript + Tailwind projects

QUICK INIT CLI Tool to quickly create React projects with Tailwind automatically configured for use. Typescript is selected as default. If JS is to be

Oscar 5 Nov 3, 2022
Write CI/CD pipelines using TypeScript

Katoa Katoa is a community fork of Cidada, a tool created by Fig which was sunset in late 2023 following acquisition by AWS. This fork and the underly

Katoa 47 Oct 6, 2023
Basic template for an out-of-tree Linux kernel module written in Rust.

Rust out-of-tree module This is a basic template for an out-of-tree Linux kernel module written in Rust. Please note that: The Rust support is experim

Rust for Linux 118 Dec 26, 2022
A Rust-based Garry's Mod module for fetching environment variables.

gm_environ Using Environment Variables in Garry's Mod. Installation Download a copy of the module from the releases (or compile from source) Move the

Joshua Piper 2 Jan 4, 2022