Skip to content

perf(pnpm): install without a readPackage hook - #10787

Merged
zkochan merged 5 commits into
teambit:masterfrom
zkochan:pnpm/hook-free-install
Oct 10, 2026
Merged

zkochan merged 5 commits into
teambit:masterfrom
zkochan:pnpm/hook-free-install

Conversation

@zkochan

@zkochan zkochan commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

Proposed Changes

  • No readPackage hook. Every dependency manifest the engine resolved used to go through a JavaScript callback. Its jobs now use static options that @pnpm/napi has supported since v12.0.0 (fix(napi): deterministic overrides, hook-free install options, and large-workspace install fixes pnpm/pnpm#13492):
    • @teambit/legacy and @teambit/harmony are removed with "@teambit/legacy@*": "-" style overrides, which cover registry packages. The @* selector matches only semver ranges, so the link: dependencies Bit's linker adds stay, as the hook kept them. A workspace project can also declare them with workspace:, file: or npm: specs, so they are removed from the workspace manifests before the install as well.
    • An injected component gets its raw manifest through projects[].dependencyManifest. Before, the hook swapped it in by directory.
    • The stripping of never-built packages' scripts is removed. It did nothing: those packages are already denied with allowBuilds: false.
  • Graph-restored lockfiles carry the overrides. Without a hook there is no pnpmfileChecksum to record. pnpm instead compares the lockfile's overrides with the install's, so the dependency graph now records them, like the settings from fix(pnpm): restore the lockfile settings a dependency graph was resolved under #10784. A graph resolved with the old hooks (checksum bit-1) is read as having the two removal overrides, so existing graphs keep being reused.
  • Measured (single runs):
    • Ripple container, bit sign of a component with about 5,500 dependencies: the component capsule's install took 34 s instead of 72 s. The env capsules reused their restored lockfiles either way.
    • This repo: a repeat bit install spends 5 s in the engine instead of 12 s.
    • With @pnpm/napi 12.12.0 (below), a repeat bit install in this repo is "Already up to date" and the engine call takes under a second (926 ms).
  • @pnpm/napi 12.12.0. It includes two engine fixes this PR builds on:
  • This repo's pnpm-lock.yaml: it gains the @teambit/legacy@* override and drops pnpmfileChecksum: bit-1. The resolutions are identical. This workspace forces a harmony version, so there is no harmony removal here.

🤖 Generated with Claude Code

@zkochan
zkochan marked this pull request as ready for review October 10, 2026 10:46
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Speed up pnpm installs by removing the readPackage hook

✨ Enhancement 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Replace per-dependency JavaScript hooks with pnpm overrides and injected-project manifests to
 reduce install time.
• Preserve lockfile reuse by recording overrides in dependency graphs and migrating graphs with the
 old hook checksum.
• Test hook-free lockfiles, graph round-trips, and safe merging of resolutions.
Diagram

graph TD
  A["Project manifests"] --> B["Bit install"] --> C["pnpm engine"] --> D[("pnpm lockfile")] --> E[("Dependency graph")] --> F[("Restored lockfile")]
  F --> C
Loading
High-Level Assessment

Use pnpm's static overrides and dependencyManifest support. Keeping the callback would retain per-dependency JavaScript work; removing it without persisting overrides would undermine restored-lockfile reuse. The graph migration addresses that compatibility cost.

Files changed (10) +239 / -129

Enhancement (4) +101 / -104
lockfile-deps-graph-converter.tsCarry overrides between lockfiles and dependency graphs +9/-2

Carry overrides between lockfiles and dependency graphs

• Captures lockfile overrides when building a graph and restores them when generating a lockfile, alongside existing resolution metadata.

scopes/dependencies/pnpm/lockfile-deps-graph-converter.ts

lynx.tsInstall through pnpm without a dependency readPackage hook +35/-89

Install through pnpm without a dependency readPackage hook

• Replaces per-dependency transformations with core-dependency removal overrides and supplies raw manifests for injected projects. Removes the hook checksum and redundant script-stripping path while retaining importer-specific transformations.

scopes/dependencies/pnpm/lynx.ts

pnpm.package-manager.tsGuard merged resolutions with matching overrides +10/-7

Guard merged resolutions with matching overrides

• Keeps override metadata only when both lockfiles with resolutions agree, so pnpm does not trust a mixed resolution under an incorrect override policy.

scopes/dependencies/pnpm/pnpm.package-manager.ts

dependencies-graph.tsPersist overrides and migrate legacy hook metadata +47/-6

Persist overrides and migrate legacy hook metadata

• Adds overrides to the dependency graph's serialized resolution metadata and merges them only when compatible. Converts graphs bearing Bit's former hook checksum into graphs bearing the equivalent removal overrides.

scopes/scope/objects/models/dependencies-graph.ts

Tests (5) +137 / -23
dependency-resolver.e2e.tsVerify hook-free install lockfile metadata +9/-6

Verify hook-free install lockfile metadata

• Expects no hook checksum or untracked-hook marker and checks that the lockfile records the legacy-removal override.

e2e/harmony/dependency-resolver.e2e.ts

lockfile-deps-graph-converter.spec.tsTest override round-trips and old-checksum migration +61/-4

Test override round-trips and old-checksum migration

• Covers preservation and omission of overrides through graph serialization and lockfile restoration. Verifies that an old Bit hook checksum restores as removal overrides while unrelated checksums remain intact.

scopes/dependencies/pnpm/lockfile-deps-graph-converter.spec.ts

lynx.spec.tsAdjust script-policy expectation +0/-1

Adjust script-policy expectation

• Expects denied builds to be represented by allowBuilds without a separate never-build package list.

scopes/dependencies/pnpm/lynx.spec.ts

pnpm.package-manager.spec.tsTest override compatibility during lockfile merges +13/-0

Test override compatibility during lockfile merges

• Checks that merges retain matching overrides and drop them when resolutions come from lockfiles with differing override metadata.

scopes/dependencies/pnpm/pnpm.package-manager.spec.ts

dependencies-graph.spec.tsTest graph override persistence and merging +54/-12

Test graph override persistence and merging

• Covers override serialization, migration of the old Bit hook checksum, and retention or removal of overrides when dependency graphs merge.

scopes/scope/objects/models/dependencies-graph.spec.ts

Other (1) +1 / -2
pnpm-lock.yamlRecord the legacy override instead of a hook checksum +1/-2

Record the legacy override instead of a hook checksum

• Adds the legacy-removal override and drops the obsolete Bit readPackage checksum without changing dependency resolutions.

pnpm-lock.yaml

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Empty workspaces re-resolve restored graphs ✓ Resolved
Description
mergeGraphLockfileIntoExisting deletes the graph's overrides when they differ from the existing
lockfile's, without checking whether the existing lockfile contributes any resolutions. When a graph
is restored into an empty or link-only workspace whose lockfile lacks those overrides, the merged
lockfile loses the graph's resolution metadata and the subsequent install must resolve it again.
Code

scopes/dependencies/pnpm/pnpm.package-manager.ts[R656-658]

+    if (!sameRecords(existing.overrides, graph.overrides)) {
+      delete merged.overrides;
+    }
Evidence
Graph conversion writes recorded overrides to the restored lockfile, and dependency-graph
restoration merges that lockfile into an existing one. The merge starts with the existing lockfile's
metadata, then deletes overrides on a mismatch whenever the graph has resolutions; it does not check
whether the existing lockfile has resolutions of its own.

scopes/dependencies/pnpm/lockfile-deps-graph-converter.ts[378-384]
scopes/dependencies/pnpm/pnpm.package-manager.ts[116-132]
scopes/dependencies/pnpm/pnpm.package-manager.ts[635-658]
scopes/dependencies/pnpm/pnpm.package-manager.ts[672-673]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Merging a resolved graph into an existing lockfile with no package or snapshot resolutions discards the graph's overrides, preventing reuse of its restored resolutions.
## Fix Focus Areas
- scopes/dependencies/pnpm/pnpm.package-manager.ts[635-658]
- scopes/dependencies/pnpm/pnpm.package-manager.spec.ts[124-135]
## Recommended Fix
When the existing lockfile contributes no resolutions, take the graph's resolution metadata, including overrides, rather than treating absent existing metadata as a conflict. Keep the current mismatch behavior when both sides contribute resolutions, and add a test for an empty existing lockfile merged with a resolved graph.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Local core packages can be installed ✓ Resolved
Description
removedCoreDependencyOverrides() uses @* selectors that match only semver ranges, whereas the
removed hooks deleted core dependencies with any specifier except link:. If a component declares
@teambit/legacy or @teambit/harmony with a file:, workspace:, or npm-alias specifier, that
reference reaches pnpm instead of being removed, so pnpm can install a core package that Bit expects
its running installation to provide.
Code

scopes/dependencies/pnpm/lynx.ts[R220-223]

+export function removedCoreDependencyOverrides(forcedHarmonyVersion?: string): Record<string, string> {
+  const overrides: Record<string, string> = { '@teambit/legacy@*': '-' };
+  if (!forcedHarmonyVersion) {
+    overrides['@teambit/harmony@*'] = '-';
Evidence
The new code states that @* matches only semver ranges, then passes those selectors as the
core-removal overrides. The install passes raw manifests for injected dependencies, so their
non-semver references are not transformed before resolution; the removed hooks handled those
references.

scopes/dependencies/pnpm/lynx.ts[213-225]
scopes/dependencies/pnpm/lynx.ts[289-298]
scopes/dependencies/pnpm/lynx.ts[319-334]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new core-removal overrides match semver ranges only. The previous hooks also removed `file:`, `workspace:`, and npm-alias references to core packages, while retaining `link:` runtime dependencies.
## Fix Focus Areas
- scopes/dependencies/pnpm/lynx.ts[213-225]
- scopes/dependencies/pnpm/lynx.ts[319-334]
## Recommended Fix
Ensure non-link core references are removed from both importer and dependency manifests before resolution, while preserving `link:` references. Add coverage for non-semver references in each manifest role.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can copy the agent prompt from any finding and feed it to your IDE agent

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit f11eaee

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 81ee6a5

zkochan and others added 5 commits October 10, 2026 21:57
Every dependency manifest the engine resolved went through a JavaScript
readPackage hook. Its jobs now have static equivalents in @pnpm/napi:

- `@teambit/legacy` and `@teambit/harmony` are removed with `"-"`
  overrides. The `@*` selector matches only semver ranges, so the
  `link:` dependencies Bit's linker adds stay, as the hook kept them.
- An injected workspace project gets its raw manifest through
  `dependencyManifest` instead of the hook swapping it in by directory.
- Stripping the scripts of never-built packages did nothing: they are
  already denied with `allowBuilds: false`.

Without a hook there is no checksum to record. Lockfiles restored from
a component's dependency graph need the install's overrides instead, so
the graph records the lockfile's `overrides`, and a graph resolved with
the old hooks (checksum `bit-1`) stands for the overrides that replaced
them, so existing graphs keep being reused.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…fests

The overrides match only semver ranges, while the removed hooks dropped
the core dependencies under any spec but link:. Only a workspace project
can declare one with a workspace:, file: or npm: spec, so they are
removed from the workspace manifests before the install.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…file has no resolutions

Co-Authored-By: Claude Opus 5.5 <[email protected]>
12.12.0 checks allowBuilds denials before dangerouslyAllowAllBuilds, so a
workspace with dangerouslyAllowAllScripts and neverBuiltDependencies now
passes the allow-all flag together with the denials. Before, that mode passed
only the denials, and the engine built nothing else.

12.12.0 also compares injected projects with their dependencyManifest when
checking lockfile freshness, so a repeat install reports "Already up to date".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zkochan
zkochan force-pushed the pnpm/hook-free-install branch from 81ee6a5 to 8f23681 Compare October 10, 2026 20:01
@zkochan
zkochan enabled auto-merge (squash) October 10, 2026 20:04
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 8f23681

@zkochan
zkochan merged commit 5e70a8b into teambit:master Oct 10, 2026
20 checks passed
zkochan added a commit that referenced this pull request Oct 13, 2026
## Proposed Changes

- **Bump `@pnpm/napi` to 12.13.0.** `pnpm-lock.yaml` changes only in the
napi version entries.
- 12.13.0 ships the engine changes for a store shared over a network
filesystem, where the Rust engine was slower than pnpm v10 and two
concurrent installs could corrupt the store index:
- **`storeIndexFormat: files`** (pnpm/pnpm#16875, pnpm/pnpm#16879,
pnpm/pnpm#16890): the store's package index as one file per package
instead of the SQLite `index.db`, whose locking does not work across
machines. Reads take no lock. Bit does not set it. The engine honours
`PNPM_CONFIG_STORE_INDEX_FORMAT=files` in the environment or
`storeIndexFormat: files` in the global pnpm config, and a store that
already has a per-file index is detected on its own, whatever the
setting says.
- **Lockfile-reused subtrees stay out of the resolution warm-up**
(pnpm/pnpm#16886). On a 5,100-package capsule install the engine
resolved ~5,650 packages from registry metadata that the walk then took
from the lockfile anyway, 22 s of a 28 s resolution.
- **Store verification runs during resolution** when `enableModulesDir:
false` (pnpm/pnpm#16888), with a package's files checked in parallel. On
a network-filesystem store this removed a 19 s pause between resolution
and fetching.
- Installed with Bit 2.2.104 so the lockfile keeps the `overrides` form
that #10787 writes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

— Claude Code (Fable 5.1)

Co-authored-by: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants