Skip to main content

Module spec

Module spec 

Source
Expand description

The npm “package spec” — the dependency-specifier grammar, per https://docs.npmjs.com/cli/v8/using-npm/package-spec.

A package.json dependencies value is one of these forms. Spec::parse classifies a value by form; Spec::is_registry reports whether it resolves to a fetchable registry tarball — the only form npm-utils installs (git / remote-tarball / local-path / alias-to-non-registry are not). Range parsing is deferred to version_req: classifying never fails, so an npm range we can’t fully parse (spaces, ||) is still a registry spec.

Structs§

Range
An npm version range: ||-separated alternatives, each a (possibly space-separated) set of comparators. Rust’s VersionReq handles only comma-separated comparators and has no ||, yet || ranges are pervasive in published packages’ dependencies (e.g. @lit/reactive-element’s ^1.6.2 || ^2.1.0). A Range parses npm’s grammar into a set of VersionReqs and is satisfied when any alternative is — so transitive resolution works on real-world trees. (version_req stays for the single-comparator-set case.)

Enums§

Spec
A classified npm dependency specifier.

Functions§

version_req
npm-faithful version → VersionReq: a bare full version (1.2.3) is an exact pin (=1.2.3); *, empty, x, and latest mean any; range syntax (^, ~, >=, …) parses as written, within what the Rust semver crate accepts (comma-separated comparators; npm’s space-separated and || ranges are not supported).