Skip to main content

Module platform

Module platform 

Source
Expand description

Platform filtering for os / cpu / libc package metadata.

npm-style packages can declare the platforms they support via the os, cpu, and libc arrays in package.json. Each entry is either a positive match ("linux", "x64", "glibc") or a negation prefixed with ! ("!win32"). pnpm’s rule:

  • empty array → unconstrained (installable everywhere)
  • any negation hit → reject
  • at least one pos → accept only if one positive matches
  • negations only → accept if no negation matched

pnpm lets the user widen the match set beyond the host via pnpm.supportedArchitectures — an object with os/cpu/libc arrays, each entry either a concrete value or the literal "current" which expands to the host triple. The package passes if ANY of the (os, cpu, libc) combinations in the supported set is installable.

This module stays intentionally small: no reading of config, no serde, just the matcher and host detection. Configuration lives on the Resolver, which calls is_supported during filtering.

Structs§

SupportedArchitectures
User-declared override for the host triple used when filtering optional dependencies. Missing arrays fall back to the host; the literal "current" inside any array expands to the same host value so users can write ["current", "linux"] to keep their native platform and also resolve optionals for Linux.

Functions§

filter_graph
Remove optional dependencies that fail the platform check or appear in the ignore list from a parsed LockfileGraph, then garbage-collect any packages that become unreachable from the surviving importers.
host_triple
Return the host’s (os, cpu, libc) triple using npm’s vocabulary. libc is "glibc" / "musl" on Linux and "" elsewhere — npm only sets libc on Linux packages, so non-Linux hosts treat libc constraints as a no-op.
is_supported
Decide whether a package is installable on any of the (os, cpu, libc) combinations expanded from supported. The pkg_libc check is skipped when the host libc is empty (non-Linux) — npm doesn’t enforce libc off Linux.
mark_optional_packages
Set each package’s optional flag the way pnpm marks the snapshots: section: a package is optional: true when it is reachable only through optional dependency edges (the classic case is every @esbuild/* platform native sitting under esbuild’s optionalDependencies). pnpm derives this during resolution; aube recomputes it as a post-resolve pass so freshly resolved lockfiles carry the same markers pnpm writes instead of an empty {} snapshot.
mark_transitive_peer_dependencies
Populate each package’s transitive_peer_dependencies the way pnpm does: a snapshot lists every peer name that some package in its dependency subtree declares but leaves unresolved (the peers that “bubble up” to be provided by a consumer). A peer that was resolved is mirrored into the declaring package’s dependencies (pnpm and aube both do this — e.g. @babel/core lands in @babel/helper-module-transforms’s deps), so peer_dependencies minus dependencies is exactly the unresolved set. Those unresolved names are propagated to every ancestor; a package never lists its own peers.