1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! Pure-Rust utilities for the npm registry and web assets.
//!
//! Building blocks for fetching browser/JS dependencies at build time without
//! Node or npm:
//!
//! - [`registry`] — talk to an npm registry: build tarball URLs, fetch a
//! package's metadata, resolve the newest version matching a semver range, and
//! search the registry ([`Registry::search`](registry::Registry::search)).
//! - [`download`] — fetch bytes over HTTP (with a retry) and build GitHub
//! archive URLs.
//! - [`extract`] — unpack `.tar.gz` and `.zip` archives into a destination
//! directory, selecting all files, an explicit file map, or a predicate, with
//! path-traversal protection.
//! - [`path_safety`] — the path-traversal hardening shared by `extract` and
//! `install`: reject `..`/absolute paths and refuse symlink-redirected writes.
//! - [`cache`] — content-hash markers, a cross-process build lock, and directory
//! helpers for skip-if-unchanged download caches.
//! - [`package_json`] — read pinned dependency versions from a `package.json`, and
//! resolve its `exports`/`module`/`browser`/`main` to browser entry points (for
//! generating an ES-module import map).
//! - [`resolve`] — locate files inside an installed dependency under `node_modules/`:
//! walk up to `node_modules/<name>` and map a `<name>/<subpath>` to a real file,
//! honoring the package's `exports` when declared.
//! - [`install`] — produce a real `node_modules/` directory, pure Rust, with every tarball
//! sha512-verified: resolve a `package.json`'s transitive `dependencies` against the registry
//! ([`install::node_modules`]), or install the exact tree a `package-lock.json` pins —
//! devDependencies included, `.bin` shims and all — an `npm ci` in Rust
//! ([`install::from_lockfile`]).
//! - [`project`] — mutate a `package.json` project: keep the lock + `node_modules/` in sync
//! ([`project::sync`]), upgrade dependencies within their ranges with a dry-run plan
//! ([`project::plan_upgrade`] / [`project::upgrade`]), and remove them ([`project::remove`]).
//! - [`integrity`] — verify a downloaded tarball's `sha512` Subresource-Integrity (both
//! install paths check it before trusting bytes).
//! - [`sbom`] — render the packages a `package-lock.json` pins as a license summary, a CycloneDX
//! 1.6 document, or an SPDX 2.3 document — compliance artifacts, pure Rust, no Node.
//! - [`audit`] — check those same pinned packages against vulnerability advisories from multiple
//! sources (npm's registry endpoint, OSV) behind a small source trait — `npm audit`, pure Rust.
//!
//! ```no_run
//! use npm_utils::{download, extract, registry::Registry};
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//! let reg = Registry::npm();
//! let lit = reg.resolve("lit", &"^3".parse()?)?;
//! let tgz = download::fetch(&lit.tarball_url)?;
//! extract::tar_gz(&tgz, "dist/lit".as_ref(), Some("package/"), extract::Select::All)?;
//! # Ok(()) }
//! ```
/// The crate's boxed, thread-safe error type. A single alias so the whole crate shares one error
/// spelling, errors cross thread boundaries, and a future switch to a structured enum is one edit.
pub type Error = ;
/// The crate's result type, defaulting the error to [`Error`].
pub type Result<T, E = Error> = Result;
// Vulnerability auditing (`npm audit`, pure Rust): check the packages a `package-lock.json` pins
// against multiple advisory sources (npm's registry endpoint, OSV) behind a small source trait.
// The command-line tool (`npm-utils` / `cargo npm-utils`), behind the `cli` feature so a default
// library build pulls no `clap`. Drives the primitives below — `registry`, `install`, `project`, and
// the `package_json` manifest/lock writers — for `install`/`ci`/`add`/`remove`/`init`/`upgrade`.
// The npm `package.json` / `package-lock.json` schemas — a pure-parsing module (no IO),
// modeled on the npm specs, with strict spec-conformance tests living beside it.
// Project mutations (`sync` / `upgrade` / `remove`) that keep package.json + lock + node_modules in
// step — the IO orchestration over the pure `package_json` transforms and `registry`/`install`.
// Locate files inside an installed `node_modules/<name>`: walk up to the package and map a
// `<name>/<subpath>` to a real file on disk, honoring `exports`. The IO counterpart to the pure
// `package_json` resolver, and the foundation web_modules builds `npm://` asset references on.
// License/SBOM output (license summary · CycloneDX · SPDX) for a parsed `package-lock.json`.
// Crate-internal `npm-utils:` warning routing — the CLI installs a sink so library warnings print
// above a live progress region instead of corrupting it.