npm_utils/lib.rs
1//! Pure-Rust utilities for the npm registry and web assets.
2//!
3//! Building blocks for fetching browser/JS dependencies at build time without
4//! Node or npm:
5//!
6//! - [`registry`] — talk to an npm registry: build tarball URLs, fetch a
7//! package's metadata, and resolve the newest version matching a semver range.
8//! - [`download`] — fetch bytes over HTTP (with a retry) and build GitHub
9//! archive URLs.
10//! - [`extract`] — unpack `.tar.gz` and `.zip` archives into a destination
11//! directory, selecting all files, an explicit file map, or a predicate, with
12//! path-traversal protection.
13//! - [`cache`] — content-hash markers, a cross-process build lock, and directory
14//! helpers for skip-if-unchanged download caches.
15//! - [`package_json`] — read pinned dependency versions from a `package.json`, and
16//! resolve its `exports`/`module`/`browser`/`main` to browser entry points (for
17//! generating an ES-module import map).
18//!
19//! ```no_run
20//! use npm_utils::{download, extract, registry::Registry};
21//!
22//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
23//! let reg = Registry::npm();
24//! let lit = reg.resolve("lit", &"^3".parse()?)?;
25//! let tgz = download::fetch(&lit.tarball_url)?;
26//! extract::tar_gz(&tgz, "dist/lit".as_ref(), Some("package/"), extract::Select::All)?;
27//! # Ok(()) }
28//! ```
29
30pub mod cache;
31pub mod download;
32pub mod extract;
33pub mod package_json;
34pub mod registry;