npm-utils
Pure-Rust utilities for the npm registry and web assets — resolve a package
version, download npm tarballs and GitHub archives, extract files, and install a
real node_modules/ from a package.json or package-lock.json. No Node or npm
at build time; just ureq + archive extraction. Handy from a build.rs to vendor
browser/JS dependencies into your own asset tree.
Modules
registry—Registry::npm();tarball_url(name, version)(handles@scope/pkg);packument(name);resolve(name, &VersionReq)→ the newest published version matching a semver range.download—fetch(url)(one retry, 100 MB cap);github_archive_url(...).extract—tar_gz(..)/zip(..)into a directory, selectingAll, an explicitFilesmap, or aMatchingpredicate; path-traversal-safe.cache— content-hash markers, a cross-processwith_lock, and directory helpers for skip-if-unchanged download caches.package_json— the rolled-own npm-format schemas as a pure-parsing module:package.json(dependency specs + a browser-favoringexportsresolver), thepackage-specgrammar (spec::Spec), andpackage-lock.jsonparsing (lock::Lockfile) — modeled on the npm specs and held to a strict spec-conformance suite.integrity— verify a downloaded tarball'ssha512Subresource-Integrity (both install paths check it before trusting bytes).install— produce a realnode_modules/tree, pure Rust, verifying every tarball'ssha512integrity.node_modules(..)resolves apackage.json's transitivedependenciesagainst the registry, checking each tarball against the registry'sdist.integritylikenpm install;from_lockfile(..)is annpm ciin Rust — it installs the exact tree apackage-lock.json(v2/v3) pins, devDependencies included, with no semver resolution: each tarball's pinnedsha512integrity is verified, platform-mismatched optional deps (e.g. darwin-onlyfseventson Linux) are skipped, andnode_modules/.bin/shims are created. That installs a project's Node test tooling (Playwright,tsc) withoutnpm— only the Node runtime is needed to then run it.
Examples
Vendor a single package's browser assets:
use ;
#
Install a committed lockfile's full tree (an npm ci, in Rust):
use Path;
#
See examples/date-converter for a runnable Lit +
Temporal demo that vendors its dependencies with this crate.
License
MIT — see LICENSE.