Skip to main content

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`.
16//!
17//! ```no_run
18//! use npm_utils::{download, extract, registry::Registry};
19//!
20//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
21//! let reg = Registry::npm();
22//! let lit = reg.resolve("lit", &"^3".parse()?)?;
23//! let tgz = download::fetch(&lit.tarball_url)?;
24//! extract::tar_gz(&tgz, "dist/lit".as_ref(), Some("package/"), extract::Select::All)?;
25//! # Ok(()) }
26//! ```
27
28pub mod cache;
29pub mod download;
30pub mod extract;
31pub mod package_json;
32pub mod registry;