#nodejs #node #module #resolution #js #algorithm #resolve

node-resolve

The Node.js module resolution algorithm

6 stable releases

Uses old Rust 2015

2.2.0 May 16, 2018
2.1.1 May 8, 2018
2.0.0 May 6, 2018
1.1.0 Mar 8, 2018
1.0.1 Mar 6, 2018

#26 in #resolve

Download history 124/week @ 2024-07-20 134/week @ 2024-07-27 108/week @ 2024-08-03 147/week @ 2024-08-10 195/week @ 2024-08-17 200/week @ 2024-08-24 119/week @ 2024-08-31 191/week @ 2024-09-07 172/week @ 2024-09-14 348/week @ 2024-09-21 377/week @ 2024-09-28 396/week @ 2024-10-05 188/week @ 2024-10-12 189/week @ 2024-10-19 184/week @ 2024-10-26 191/week @ 2024-11-02

815 downloads per month
Used in hai_pal

Apache-2.0

18KB
320 lines

node-resolve

node-resolve on crates.io

Rust implementation of the Node.js module resolution algorithm.

Missing features:

  • async?
  • maybe more

Install

Add to your Cargo.toml:

[dependencies]
node-resolve = "2.2.0"

Usage

See docs.rs/node-resolve.

License

Apache-2.0


lib.rs:

Resolve module identifiers in a Node-style require() to a full file path.

use node_resolve::{resolve, resolve_from};

resolve("abc");
// → Ok("/path/to/cwd/node_modules/abc/index.js")
resolve_from("abc", PathBuf::from("/other/path"));
// → Ok("/other/path/node_modules/abc/index.js")

Dependencies

~0.5–1MB
~20K SLoC