Skip to content

Surface tarball-verified dist.pnpr.requiresBuild from pnpr and use it to speed up pnpm installs #177

Closed
pnpm/pnpm
#17164

Description

@zkochan

Summary

Today pnpm cannot reliably tell whether a package requires a build (requiresBuild) until after its tarball is downloaded and inspected, because npm registry packuments do not accurately reflect tarball build triggers (binding.gyp, .hooks/*, or scripts.{preinstall,install,postinstall} when omitted from abbreviated metadata or modified in the tarball). requiresBuild was previously removed from pnpm-lock.yaml in pnpm/pnpm#7710 (pnpm/pnpm#0e6b757cf5) because un-fetched optional dependencies and --lockfile-only installs could not populate it deterministically.

With pnpr, we can solve this without putting requiresBuild back into pnpm-lock.yaml: whenever pnpr inspects a tarball (at publish time for hosted packages, or on first tarball stream/cache for upstream packages), it can record a verified requiresBuild: bool keyed by the tarball's .tgz integrity and project it onto served metadata as versions[v].dist.pnpr.requiresBuild (as well as POST /-/pnpr/v0/resolve package frames). When a version's tarball has not yet been inspected by pnpr, dist.pnpr.requiresBuild is omitted so pnpm falls back to its existing tarball inspection.


Wire & Storage Design

1. Tri-state semantics under versions[v].dist.pnpr.requiresBuild

  • dist.pnpr.requiresBuild: true: pnpr has inspected the tarball and verified that it triggers a build (scripts.preinstall / scripts.install / scripts.postinstall in the tarball's package.json, binding.gyp unless gypfile: false, or .hooks/*).
  • dist.pnpr.requiresBuild: false: pnpr has inspected the tarball and verified that it does not trigger a build.
  • Omitted (undefined): pnpr has not yet inspected the tarball for this version (e.g., an uncached upstream version). pnpm treats it as unknown and falls back to inspecting the tarball upon fetch.

2. Why versions[v].dist.pnpr.requiresBuild

  • Data model fit: requiresBuild is a property of the distribution archive (keyed by dist.integrity), alongside dist.integrity, dist.fileCount, dist.unpackedSize, and dist.attestations.
  • Trust boundary: pnpr already constructs dist on publish (pnpr/crates/pnpr/src/server/publishing/manifest.rs) and rewrites dist on upstream packuments (pnpr/crates/upstream/src/packument.rs, pnpr/crates/pnpr/src/server/tar_registry.rs). Stripping any untrusted incoming dist.pnpr field and injecting only pnpr's own tarball-verified metadata is handled at a single choke point.
  • Zero-allocation deserialization in pnpm: PackageDistribution (pnpm/crates/registry/src/package_distribution.rs) is a strongly-typed struct without a #[serde(flatten)] HashMap catch-all (unlike PackageVersion), so adding pub pnpr: Option<PnprDist> costs a single Option<bool> on the stack when parsing large packuments.

Tasks

Part 1: pnpr — Derive, persist, and serve requiresBuild

  • Share or port build-trigger detection in pnpr:
    • Inspect entries while streaming the decoded .tar in pnpr/crates/pnpr/src/server/publishing/attachments.rs (write_and_derive_tar) and pnpr/crates/pnpr/src/server/tar_responses.rs (decoded_response), matching pnpm/crates/package-manifest/src/build_triggers.rs (package/package.json scripts.{preinstall,install,postinstall}, package/binding.gyp unless gypfile: false, and package/.hooks/*).
  • Persist per-tarball requiresBuild in pnpr_storage:
    • Extend per-package derived tarball metadata (pnpr/crates/storage/src/tar_integrities.rs or a companion derived-tar metadata table keyed by tgz_integrity) so requiresBuild: bool is stored alongside tar_integrity on publish and on first upstream tarball decode.
  • Project dist.pnpr.requiresBuild in packument & manifest responses:
    • Strip any upstream-supplied dist.pnpr in pnpr/crates/upstream/src/packument.rs and pnpr/crates/pnpr/src/server/publishing/manifest.rs.
    • Overlay dist.pnpr.requiresBuild for every version whose tgz_integrity_key(dist) has a verified entry in storage (for both full packuments, application/vnd.npm.install-v1+json abbreviated packuments, and single-version /<pkg>/<version> endpoints).
  • Include requiresBuild in POST /-/pnpr/v0/resolve NDJSON package frames:
    • Emit requiresBuild (or pnpr.requiresBuild) on package frames in pnpr/crates/pnpr/src/resolver/wire.rs for both fresh resolutions (package_frame) and frozen-lockfile resolutions (frozen_package_frames).
  • Document the wire field in pnpr/docs/endpoints.md.

Part 2: pnpm (v12) — Plumb dist.pnpr.requiresBuild and accelerate installation

  • Deserialize dist.pnpr.requiresBuild in pnpm-registry and pnpm-pnpr-client:
    • Add pnpr: Option<PnprDist> (requires_build: Option<bool>) to PackageDistribution in pnpm/crates/registry/src/package_distribution.rs and to ResolvedPackageFrame in pnpm/crates/pnpr-client/.
    • Thread the verified Option<bool> through ResolveResult / PrefetchingResolver and into the store index (requires_build column in index.db) and CreateVirtualStore (requires_build_by_snapshot).
  • Overlap remote side-effects cache lookups (apply_shared_side_effects) with cold tarball downloads:
    • Today CreateVirtualStore::materialize_plan (pnpm/crates/deps-restorer/src/create_virtual_store/pipeline.rs) cannot plan or query POST /-/pnpr/v0/artifacts/resolve until download_cold finishes downloading and unpacking every cold tarball, because eligible_roots (pnpm/crates/deps-restorer/src/shared_side_effects/planning.rs) waits on requires_build_by_snapshot from tarball extraction.
    • Use pre-known requiresBuild to plan eligible roots and fetch remote side-effects artifacts concurrently with cold tarball downloads.
  • Skip spawning node --version (~150 ms) and BuildModules graph setup when no package requires a build:
    • In plan_materialization (pnpm/crates/deps-restorer/src/install_frozen_lockfile/materialization.rs), when GVS is off and no package has engines.node constraints, pnpm still spawns node --version in case BuildModules needs engine_name for side-effects cache keys.
    • When all resolved snapshots have a known requiresBuild == false (or are disallowed by allowBuilds), skip the node --version probe and short-circuit BuildModules.
  • Fail fast on ERR_PNPM_IGNORED_BUILDS (strictDepBuilds) and support early pruneAllowBuilds:
    • When strictDepBuilds: true and dist.pnpr.requiresBuild is true for an unapproved package, surface ERR_PNPM_IGNORED_BUILDS before downloading/extracting tarballs and linking node_modules.
  • Avoid post-extraction package.json / filesystem inspection fallbacks:
    • Skip fallback disk/manifest reads in pnpm/crates/tarball/src/prefetch.rs (resolve_row_requires_build) and pnpm/crates/deps-restorer/src/build_modules/build_requirements.rs (requires_build_by_key) when requiresBuild was already verified by pnpr.

Written by an agent (Antigravity, Gemini 4 Argon).

Activity

  1. self-assigned this
    on Oct 20, 2026
  2. zkochan commented on Oct 20, 2026

    @zkochan
    MemberAuthor

    Opened pnpm/pnpm#17164 covering the full issue:

    • pnpr: inspects decoded .tar streams via pnpm_tarball::tar_requires_build (on publish, on first tar decode, and asynchronously after caching an upstream .tgz), persists requiresBuild: Option<bool> alongside tar_integrity in <pkg>/tar-integrities.json, strips any untrusted upstream/publisher dist.pnpr, and projects versions[v].dist.pnpr.requiresBuild onto packuments, abbreviated packuments, single-version manifests, and POST /-/pnpr/v0/resolve package frames (fresh and frozen).
    • pnpm v12: deserializes dist.pnpr.requiresBuild and ResolvedPackageFrame.requires_build, threads them into EarlyMaterializer and CreateVirtualStore, overlaps remote side-effects artifact resolution (POST /-/pnpr/v0/artifacts/resolve) with cold tarball downloads when cold snapshots have a known requiresBuild, and skips the node --version probe and BuildModules pass when every snapshot is known not to need a build (or is disallowed by allowBuilds).

    Written by an agent (Antigravity, Gemini 4 Argon).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions