Repository navigation
Conversation
Adding a package to a workspace always paid a full resolution, even when every dependency it declared was already locked for a sibling — the normal case for a package scaffolded from a template. The importers handler now writes such a project's whole entry from the versions the lockfile already holds, by the rule #13779 established for a single changed range: the highest locked version satisfying each declared range, which is what resolution would settle on. The project arrives as an importer with nothing recorded rather than a missing one, because reading the lockfile seeds an empty entry for every project that has none. The gate that asked whether every project had an importer was therefore always satisfied; the fallback that actually fired was the handler's, on the first alias with no recorded reference. A dependency that resolves to a directory keeps the resolver, since only it decides whether a plain range on a workspace project's name becomes a link. So do a non-semver specifier and a range no locked version satisfies. A new importer is the one edit that adds reachability, so the shared epilogue has to recompute the `optional` flags rather than leave them: a package only optional dependencies reached can stop being optional. `GraphEdits.movedAcrossOptional` becomes `optionalFlagsAreStale` to cover both causes. Both stacks. A byte-identity test runs the same addition through the fast path and through a forced resolution, including on a time-based lockfile, where the new direct dependency was transitive-only before and so carries no publish date of its own. Item 3 of #13696, closes #13800.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe fast lockfile-update path now creates missing workspace importers from compatible locked versions. It preserves manifest metadata, applies resolution-mode-aware selection, and recomputes optional reachability. Unsupported or unavailable dependencies fall back to resolution. ChangesNew workspace importer fast update
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Workspace as Workspace installation
participant Composer as tryComposeFastUpdates
participant ImporterUpdater as tryFastUpdateImporters
participant Lockfile as Lockfile graph
Workspace->>Composer: Provide project manifests and workspacePackages
Composer->>ImporterUpdater: Plan importer updates
ImporterUpdater->>Lockfile: Find compatible locked versions
alt All dependencies are compatible
ImporterUpdater->>Lockfile: Insert reconstructed importer
Lockfile->>Lockfile: Recompute optional flags
else Dependency requires resolution
ImporterUpdater-->>Composer: Return false
Composer-->>Workspace: Fall back to resolver
end
Possibly related issues
Possibly related PRs
Suggested labels: Suggested reviewers: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by Qodoperf: Fast-update lockfile when adding a new workspace importer
AI Description
Diagram
High-Level Assessment
Files changed (17)
|
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Reviews (3): Last reviewed commit: "perf(pacquet): keep the locked-version p..." | Re-trigger Greptile |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts`:
- Around line 73-83: Update the TypeScript fast-update flow around the importer
lookup in tryFastUpdateImporters to reconstruct a missing
lockfile.importers[project.id] from locked versions, matching
writeImporterFromLockedVersions behavior in the Rust path, instead of
immediately returning false. Preserve the existing dependency-change handling
and optionalFlagsAreStale updates, and add coverage for both a sole missing
importer and a missing importer combined with another importer change.
In `@pnpm11/installing/deps-installer/test/install/newImporterFastUpdate.ts`:
- Around line 134-149: Extend the fast-update regression coverage in
pnpm11/installing/deps-installer/test/install/newImporterFastUpdate.ts around
tryComposeFastUpdates with equivalent workspace: and link: dependency cases,
covering both excludeLinksFromLockfile settings and the expected resolver
fallback. Add matching Rust cases in
pnpm/crates/package-manager/src/fast_update_importers/tests.rs around the
existing tests, using the corresponding configuration so TypeScript and Rust
behavior remain identical.
- Around line 35-52: Expand the regression coverage in
pnpm11/installing/deps-installer/test/install/newImporterFastUpdate.ts:35-52 and
pnpm/crates/package-manager/src/fast_update_importers/tests.rs:773-796 by
seeding at least two locked versions of `@pnpm.e2e/foo` that satisfy the requested
range, then assert the reconstructed new importer records the highest compatible
version; keep both TypeScript and Rust tests behaviorally equivalent.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 08ce3644-8c40-4e6a-b928-bbc5f37789a6
📒 Files selected for processing (17)
.changeset/new-importer-fast-update.mdpnpm/crates/package-manager/src/fast_update_compose.rspnpm/crates/package-manager/src/fast_update_importers.rspnpm/crates/package-manager/src/fast_update_importers/tests.rspnpm/crates/package-manager/src/fast_update_lockfile.rspnpm/crates/package-manager/src/fast_update_settings.rspnpm11/installing/deps-installer/src/install/index.tspnpm11/installing/deps-installer/src/install/tryComposeFastUpdates.tspnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.tspnpm11/installing/deps-installer/src/install/tryFastUpdateSettings.tspnpm11/installing/deps-installer/test/install/catalogFastUpdate.tspnpm11/installing/deps-installer/test/install/composedFastUpdate.tspnpm11/installing/deps-installer/test/install/ignoredOptionalDependencies.tspnpm11/installing/deps-installer/test/install/importerGroupMoveFastUpdate.tspnpm11/installing/deps-installer/test/install/importerRemovalFastUpdate.tspnpm11/installing/deps-installer/test/install/lockedVersionReuse.tspnpm11/installing/deps-installer/test/install/newImporterFastUpdate.ts
Micro-Benchmark ResultsLinux |
Code Review by Qodo
1.
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
This comment has been minimized.
This comment has been minimized.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #13803 +/- ##
=======================================
Coverage 88.24% 88.25%
=======================================
Files 624 624
Lines 101807 101887 +80
=======================================
+ Hits 89837 89917 +80
Misses 11970 11970 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
`resolutionMode: time-based` and `lowest-direct` resolve a direct dependency to the *lowest* version satisfying its range, so reusing the highest locked one recorded a version a full resolution would not. The reuse now declines whenever those modes are on and more than one locked version satisfies: the modes only apply to a run that leaves the manifest alone, so which end of the range wins is not a property of the lockfile. With exactly one locked candidate the two ends coincide and the reuse still applies, which is why an exact specifier keeps its fast path. This covers the changed-range reuse as much as the new importer. The overrides handler keeps taking the highest: `resolutionMode` moves only direct dependencies, and an override names a package at any depth. Also from review: - Detect and rebuild an importer the lockfile omits entirely, not only one it records as empty. Reading the lockfile seeds an empty entry so only the empty shape reaches production, but the two stacks disagreed on the absent one, and pacquet does not seed. - The reuse tests locked a single satisfying version, so they could not tell the highest from the first. Both stacks now lock two. - Cover the `workspace:` and `link:` protocols explicitly rather than only a plain range on a workspace project's name. - Drop the narration from the test fixture helper; its name carries it. The time-based test pinned the transitive version it promoted to a direct dependency, which time-based resolution is free to choose differently — it did on CI. It now reads back whatever the initial install locked.
|
CI note: That is not this PR — it is in Written by an agent (Claude Code, claude-opus-5). |
|
Code review by qodo was updated up to the latest commit 2911ca8 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Collecting the satisfying versions to take their max allocated a Vec and cloned every candidate, where a running maximum clones only the winner. The ambiguity guard the pick-lowest resolution modes need is a count, not the collection.
pnpm remove already skips resolution when the lockfile proves the outcome; its twin did not. `pnpm add <pkg>@<version>` re-resolved the whole graph even when the requested version was one the lockfile already held — promoting a transitive dependency to a direct one, or adding to a second workspace package what a first one already depends on. The rule is the one #13779 established: resolution reuses the already-locked version it would dedupe onto rather than fetching a higher one, because preferredVersions biases it toward what the graph already holds. The importers handler now records a brand-new importer edge at that version, under the group the manifest declares, alongside the whole-new-project entry #13803 added. It reuses that change's guards: a range several locked versions satisfy under `resolutionMode: time-based` or `lowest-direct` keeps the resolver, since those pick the low end and only for a run that leaves the manifest alone, and so does a plain range on a workspace project's name, which may resolve to a link instead. A lockfile carrying `time` keeps it too: `time` records a publish date per direct dependency and is only pruned on save, never extended, so a package promoted into that position would be missing the one a resolution records. `installSome` cannot edit the manifests in place the way `uninstallSome` does — the resolution path reads them to tell a new dependency from a re-added one, and reads them again to pick the range style it saves — so the edit is staged on copies, handed to the fast update and its freshness gates, and the context takes it only once the rewrite commits. The range a selector saves is computed with the resolver's own rule, extracted as `calcVersionRange` in `@pnpm/pkg-manifest.utils` alongside the `inferRangeSpecStyle` it needs. pacquet needed only the gate: `add` already pins the manifest before the install runs, so `may_fast_update_lockfile` admits `InstallSome` and `add` stops forcing `preferFrozenLockfile` off. `update` is also `InstallSome` and keeps its explicit opt-out, so it is unaffected. Its manifest pin still consults the registry packument; only the install-side resolution is skipped. The narrow cut is a plain registry specifier. A dist tag, an alias, a `workspace:`/`catalog:`/git/tarball specifier, `--save-peer`, a `catalogMode` other than `manual`, an overridden package, and a version nothing locked satisfies all keep the resolver. Closes #13798. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
pnpm remove already skips resolution when the lockfile proves the outcome; its twin did not. `pnpm add <pkg>@<version>` re-resolved the whole graph even when the requested version was one the lockfile already held — promoting a transitive dependency to a direct one, or adding to a second workspace package what a first one already depends on. The rule is the one #13779 established: resolution reuses the already-locked version it would dedupe onto rather than fetching a higher one, because preferredVersions biases it toward what the graph already holds. The importers handler now records a brand-new importer edge at that version, under the group the manifest declares, alongside the whole-new-project entry #13803 added. It reuses that change's guards: a range several locked versions satisfy under `resolutionMode: time-based` or `lowest-direct` keeps the resolver, since those pick the low end and only for a run that leaves the manifest alone, and so does a plain range on a workspace project's name, which may resolve to a link instead. A lockfile carrying `time` keeps it too: `time` records a publish date per direct dependency and is only pruned on save, never extended, so a package promoted into that position would be missing the one a resolution records. `installSome` cannot edit the manifests in place the way `uninstallSome` does — the resolution path reads them to tell a new dependency from a re-added one, and reads them again to pick the range style it saves — so the edit is staged on copies, handed to the fast update and its freshness gates, and the context takes it only once the rewrite commits. The range a selector saves is computed with the resolver's own rule, extracted as `calcVersionRange` in `@pnpm/pkg-manifest.utils` alongside the `inferRangeSpecStyle` it needs. pacquet needed only the gate: `add` already pins the manifest before the install runs, so `may_fast_update_lockfile` admits `InstallSome` and `add` stops forcing `preferFrozenLockfile` off. `update` is also `InstallSome` and keeps its explicit opt-out, so it is unaffected. Its manifest pin still consults the registry packument; only the install-side resolution is skipped. The narrow cut is a plain registry specifier. A dist tag, an alias, a `workspace:`/`catalog:`/git/tarball specifier, `--save-peer`, a `catalogMode` other than `manual`, an overridden package, and a version nothing locked satisfies all keep the resolver. Closes #13798. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
) pnpm remove already skips resolution when the lockfile proves the outcome; its twin did not. `pnpm add <pkg>@<version>` re-resolved the whole graph even when the requested version was one the lockfile already held — promoting a transitive dependency to a direct one, or adding to a second workspace package what a first one already depends on. The rule is the one #13779 established: resolution reuses the already-locked version it would dedupe onto rather than fetching a higher one, because preferredVersions biases it toward what the graph already holds. The importers handler now records a brand-new importer edge at that version, under the group the manifest declares, alongside the whole-new-project entry #13803 added. It reuses that change's guards: a range several locked versions satisfy under `resolutionMode: time-based` or `lowest-direct` keeps the resolver, since those pick the low end and only for a run that leaves the manifest alone, and so does a plain range on a workspace project's name, which may resolve to a link instead. A lockfile carrying `time` keeps it too: `time` records a publish date per direct dependency and is only pruned on save, never extended, so a package promoted into that position would be missing the one a resolution records. `installSome` cannot edit the manifests in place the way `uninstallSome` does — the resolution path reads them to tell a new dependency from a re-added one, and reads them again to pick the range style it saves — so the edit is staged on copies, handed to the fast update and its freshness gates, and the context takes it only once the rewrite commits. The range a selector saves is computed with the resolver's own rule, extracted as `calcVersionRange` in `@pnpm/pkg-manifest.utils` alongside the `inferRangeSpecStyle` it needs. pacquet needed only the gate: `add` already pins the manifest before the install runs, so `may_fast_update_lockfile` admits `InstallSome` and `add` stops forcing `preferFrozenLockfile` off. `update` is also `InstallSome` and keeps its explicit opt-out, so it is unaffected. Its manifest pin still consults the registry packument; only the install-side resolution is skipped. The narrow cut is a plain registry specifier. A dist tag, an alias, a `workspace:`/`catalog:`/git/tarball specifier, `--save-peer`, a `catalogMode` other than `manual`, an overridden package, and a version nothing locked satisfies all keep the resolver. Closes #13798.
Summary
Closes #13800, item 3 of #13696.
Adding a package to a workspace always paid a full resolution, even when every dependency it declared was already locked for a sibling — the normal case for a package scaffolded from a template. The importers fast update now writes such a project's whole entry from the versions the lockfile already holds.
The gate the issue named was not the blocker.
contextProjects.every((project) => ctx.wantedLockfile.importers[project.id] != null)is always true:readLockfilesseeds an empty{ specifiers: {} }entry for every project the lockfile has no entry for, before any handler runs. What actually fired wastryFastUpdateImporters' own fallback, on the first declared alias with no recorded reference. So a new project reaches the handler as an importer that records nothing, and that — not a missing key — is what the new branch keys on. The dead gate is removed. pacquet does not seed, so its handler takes both shapes.Which version the new edge gets is the rule #13779 established and measured: the already-locked version resolution would dedupe onto, because
preferredVersionsbiases resolution toward what the graph already holds. Four things keep the resolver:workspace:,link:,file:, and a plain range on a workspace project's name, whichlinkWorkspacePackagesmay turn into a link. Only the resolver decides that, andlinkedPackagesAreUpToDatewould not catch a wrong guess: it looks a workspace package up by the recorded version, so a registry version recorded where a link belonged reads as up to date. Break-tested in both stacks.catalog:).resolutionMode: time-basedorlowest-direct. Those modes resolve a direct dependency to the lowest satisfying version, so "the highest locked version" is the wrong end of the range — but only for a run that leaves the manifest alone, so which end applies is not a property of the lockfile. Rather than model that, the reuse declines when the candidates are ambiguous; with one candidate the two ends coincide, so an exact specifier keeps its fast path. Caught by Qodo in review, break-tested in both stacks, and it fixes the same latent gap in the existing changed-range reuse from fix: reuse the version resolution would dedupe onto for a changed range #13779. The overrides handler keeps taking the highest:resolutionModemoves only direct dependencies, and an override names a package at any depth.A new importer is the one edit that adds reachability, so the shared epilogue has to recompute the
optionalflags rather than assume them: a package that until now only optional dependencies reached can stop being optional.GraphEdits.movedAcrossOptionalis renamedoptionalFlagsAreStalesince it now covers both causes.isDirectoryDependencyalready existed in the settings handler and is reused rather than restated; the same in pacquet, along withworkspace_package_names.Confirmed rather than assumed, as every item of #13696 asks: two byte-identity tests run the same addition through the fast path and through
forceFullResolutionand compare the written lockfile. The second is on aresolutionMode: time-basedlockfile, where the new project's dependency was transitive-only before and so carries no publish date of its own — the files still match, so notimebail is needed.Not covered, unchanged from before: a new project declaring
peerDependenciesthatautoInstallPeersfolds into its dependencies. The candidate failssatisfiesPackageManifestand the run falls back to the resolver, exactly as today. The same gap already applies to existing importers with auto-installed peers, so it belongs in its own change.Squash Commit Body
Checklist
already linked to it solves it.
pnpm/port, or the description notes what still needs porting.pnpm changeset) if this PR changes any publishedpackage. Keep it short and written for pnpm users — it becomes a release note.
Written by an agent (Claude Code, claude-opus-5).
Summary by CodeRabbit
New Features
Bug Fixes