Repository navigation
Description
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:pnprhas inspected the tarball and verified that it triggers a build (scripts.preinstall/scripts.install/scripts.postinstallin the tarball'spackage.json,binding.gypunlessgypfile: false, or.hooks/*).dist.pnpr.requiresBuild: false:pnprhas inspected the tarball and verified that it does not trigger a build.- Omitted (
undefined):pnprhas not yet inspected the tarball for this version (e.g., an uncached upstream version).pnpmtreats it as unknown and falls back to inspecting the tarball upon fetch.
2. Why versions[v].dist.pnpr.requiresBuild
- Data model fit:
requiresBuildis a property of the distribution archive (keyed bydist.integrity), alongsidedist.integrity,dist.fileCount,dist.unpackedSize, anddist.attestations. - Trust boundary:
pnpralready constructsdiston publish (pnpr/crates/pnpr/src/server/publishing/manifest.rs) and rewritesdiston upstream packuments (pnpr/crates/upstream/src/packument.rs,pnpr/crates/pnpr/src/server/tar_registry.rs). Stripping any untrusted incomingdist.pnprfield and injecting onlypnpr'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)]HashMapcatch-all (unlikePackageVersion), so addingpub pnpr: Option<PnprDist>costs a singleOption<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
.tarinpnpr/crates/pnpr/src/server/publishing/attachments.rs(write_and_derive_tar) andpnpr/crates/pnpr/src/server/tar_responses.rs(decoded_response), matchingpnpm/crates/package-manifest/src/build_triggers.rs(package/package.jsonscripts.{preinstall,install,postinstall},package/binding.gypunlessgypfile: false, andpackage/.hooks/*).
- Inspect entries while streaming the decoded
- Persist per-tarball
requiresBuildinpnpr_storage:- Extend per-package derived tarball metadata (
pnpr/crates/storage/src/tar_integrities.rsor a companion derived-tar metadata table keyed bytgz_integrity) sorequiresBuild: boolis stored alongsidetar_integrityon publish and on first upstream tarball decode.
- Extend per-package derived tarball metadata (
- Project
dist.pnpr.requiresBuildin packument & manifest responses:- Strip any upstream-supplied
dist.pnprinpnpr/crates/upstream/src/packument.rsandpnpr/crates/pnpr/src/server/publishing/manifest.rs. - Overlay
dist.pnpr.requiresBuildfor every version whosetgz_integrity_key(dist)has a verified entry in storage (for both full packuments,application/vnd.npm.install-v1+jsonabbreviated packuments, and single-version/<pkg>/<version>endpoints).
- Strip any upstream-supplied
- Include
requiresBuildinPOST /-/pnpr/v0/resolveNDJSONpackageframes:- Emit
requiresBuild(orpnpr.requiresBuild) onpackageframes inpnpr/crates/pnpr/src/resolver/wire.rsfor both fresh resolutions (package_frame) and frozen-lockfile resolutions (frozen_package_frames).
- Emit
- Document the wire field in
pnpr/docs/endpoints.md.
Part 2: pnpm (v12) — Plumb dist.pnpr.requiresBuild and accelerate installation
- Deserialize
dist.pnpr.requiresBuildinpnpm-registryandpnpm-pnpr-client:- Add
pnpr: Option<PnprDist>(requires_build: Option<bool>) toPackageDistributioninpnpm/crates/registry/src/package_distribution.rsand toResolvedPackageFrameinpnpm/crates/pnpr-client/. - Thread the verified
Option<bool>throughResolveResult/PrefetchingResolverand into the store index (requires_buildcolumn inindex.db) andCreateVirtualStore(requires_build_by_snapshot).
- Add
- 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 queryPOST /-/pnpr/v0/artifacts/resolveuntildownload_coldfinishes downloading and unpacking every cold tarball, becauseeligible_roots(pnpm/crates/deps-restorer/src/shared_side_effects/planning.rs) waits onrequires_build_by_snapshotfrom tarball extraction. - Use pre-known
requiresBuildto plan eligible roots and fetch remote side-effects artifacts concurrently with cold tarball downloads.
- Today
- Skip spawning
node --version(~150 ms) andBuildModulesgraph 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 hasengines.nodeconstraints,pnpmstill spawnsnode --versionin caseBuildModulesneedsengine_namefor side-effects cache keys. - When all resolved snapshots have a known
requiresBuild == false(or are disallowed byallowBuilds), skip thenode --versionprobe and short-circuitBuildModules.
- In
- Fail fast on
ERR_PNPM_IGNORED_BUILDS(strictDepBuilds) and support earlypruneAllowBuilds:- When
strictDepBuilds: trueanddist.pnpr.requiresBuildistruefor an unapproved package, surfaceERR_PNPM_IGNORED_BUILDSbefore downloading/extracting tarballs and linkingnode_modules.
- When
- Avoid post-extraction
package.json/ filesystem inspection fallbacks:- Skip fallback disk/manifest reads in
pnpm/crates/tarball/src/prefetch.rs(resolve_row_requires_build) andpnpm/crates/deps-restorer/src/build_modules/build_requirements.rs(requires_build_by_key) whenrequiresBuildwas already verified bypnpr.
- Skip fallback disk/manifest reads in
Written by an agent (Antigravity, Gemini 4 Argon).
Activity
zkochan commentedon Oct 20, 2026
Opened pnpm/pnpm#17164 covering the full issue:
pnpr: inspects decoded.tarstreams viapnpm_tarball::tar_requires_build(on publish, on first tar decode, and asynchronously after caching an upstream.tgz), persistsrequiresBuild: Option<bool>alongsidetar_integrityin<pkg>/tar-integrities.json, strips any untrusted upstream/publisherdist.pnpr, and projectsversions[v].dist.pnpr.requiresBuildonto packuments, abbreviated packuments, single-version manifests, andPOST /-/pnpr/v0/resolvepackageframes (fresh and frozen).pnpmv12: deserializesdist.pnpr.requiresBuildandResolvedPackageFrame.requires_build, threads them intoEarlyMaterializerandCreateVirtualStore, overlaps remote side-effects artifact resolution (POST /-/pnpr/v0/artifacts/resolve) with cold tarball downloads when cold snapshots have a knownrequiresBuild, and skips thenode --versionprobe andBuildModulespass when every snapshot is known not to need a build (or is disallowed byallowBuilds).Written by an agent (Antigravity, Gemini 4 Argon).
feat: surface tarball-verified requiresBuild from pnpr and use it dur…