Repository navigation
fix(pacquet): make the global virtual store safe to share, and reachable from the Node API - #13648
Conversation
PR Summary by QodoFix global virtual store concurrency; keep directory deps local; expose GVS via N-API
AI Description
Diagram
High-Level Assessment
Files changed (17)
|
Confidence Score: 5/5The PR appears safe to merge based on the currently established behavior. No blocking failure remains established; the prior shared-slot content-integrity concern cannot be classified conclusively without evidence that unintended content modification is reachable under supported store ownership and permissions. Reviews (10): Last reviewed commit: "docs(pacquet): align comments with style..." | Re-trigger Greptile |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe PR adds NAPI options and resolved fields for global virtual stores, package extensions, and patched dependencies. It routes directory resolutions to project-local stores and adds non-destructive reuse for completed shared slots during concurrent imports. ChangesGlobal virtual-store configuration and public API
Virtual-store routing and import behavior
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant InstallOptions
participant build_overlay
participant build_config
participant ResolvedConfig
InstallOptions->>build_overlay: provide virtual-store and dependency settings
build_overlay->>build_config: apply configuration overlay
build_config->>ResolvedConfig: expose effective virtual-store paths
sequenceDiagram
participant create_virtual_dir_by_snapshot
participant import_indexed_dir
participant stage_and_swap
participant SharedSlot
create_virtual_dir_by_snapshot->>import_indexed_dir: enable safe_to_skip
import_indexed_dir->>stage_and_swap: pass safe_to_skip
stage_and_swap->>SharedSlot: attempt staged rename
SharedSlot-->>stage_and_swap: report target state
stage_and_swap->>SharedSlot: preserve complete target or replace incomplete target
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 |
Code Review by Qodo
1.
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
a042485 to
af385fc
Compare
There was a problem hiding this comment.
Actionable comments posted: 8
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
pnpm/crates/package-manager/src/import_indexed_dir.rs (1)
394-438: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winRun the non-destructive check before preserving
node_modules.When
keep_modules_diris true, Lines 395-408 move the livenode_modulesinto staging. That setsnm_moved, so Lines 428-438 bypass the safe branch.pnpm/crates/package-manager/src/create_virtual_dir_by_snapshot.rspasses both flags for interrupted global-store imports. A completed shared slot with dependencies is still dismantled and replaced, so concurrent readers can lose itsnode_modules.Try the occupied-target check before moving
target_modules. Preservenode_modulesonly after the target is known incomplete. Add coverage forsafe_to_skip: true,keep_modules_dir: true, and a completed target with nested dependencies.🤖 Prompt for 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. In `@pnpm/crates/package-manager/src/import_indexed_dir.rs` around lines 394 - 438, Reorder the import flow so the safe-to-skip occupied-target check runs before the `nm_moved`/`node_modules` preservation block. For `safe_to_skip` with a completed target confirmed by `all_files_match`, discard staging and return without moving or removing `target_modules`; only preserve `node_modules` when the target is incomplete and the destructive swap is required. Add coverage for `safe_to_skip: true`, `keep_modules_dir: true`, and a completed target containing nested dependencies.
🧹 Nitpick comments (3)
pnpm/crates/package-manager/src/virtual_store_layout/tests.rs (1)
572-572: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRemove assertion-narrating comments.
The comments on Line 572 and Line 582 only restate the adjacent assertions. Keep the test-level doc comment because it records the cross-project routing invariant.
Proposed cleanup
- // Each project keeps its own copy of the injected directory, under its own store. assert_ne!(dir_in_a, dir_in_b); @@ - // The registry dependency is unaffected: same shared slot for both projects. assert_eq!(registry_in_a, registry_in_b);As per coding guidelines, comments must explain non-obvious invariants instead of narrating code. As per path instructions, document only non-obvious reasons or invariants.
Also applies to: 582-582
🤖 Prompt for 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. In `@pnpm/crates/package-manager/src/virtual_store_layout/tests.rs` at line 572, Remove the assertion-narrating comments adjacent to the assertions at the referenced locations in the test. Preserve the test-level documentation comment describing the cross-project routing invariant, and leave the assertions and test behavior unchanged.Sources: Coding guidelines, Path instructions
.changeset/gvs-directory-resolutions-stay-local.md (1)
7-7: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winKeep the changeset user-facing.
Line 7 describes hash scoping and module-resolution internals. Remove that rationale from the release note. Keep a concise statement that directory resolutions remain local and registry resolutions remain shared.
As per coding guidelines, changesets must describe user-visible behavior. Based on learnings, keep implementation rationale outside Changeset entries.
🤖 Prompt for 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. In @.changeset/gvs-directory-resolutions-stay-local.md at line 7, Update the changeset entry to remove the internal rationale about hash scoping, global virtual stores, and module-resolution paths. Keep only a concise user-facing statement that directory resolutions remain local while registry resolutions remain shared.Sources: Coding guidelines, Path instructions, Learnings
pnpm/crates/package-manager/src/virtual_store_layout.rs (1)
71-94: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCorrect the
package_store_dirdocumentation contract.Directory slots can now live under
local_store_dir, but the existingpackage_store_dirfield and accessor documentation say that this path contains every snapshot slot. Describe it as the default slot root, which is global only in GVS mode. Direct per-slot callers tostore_root_for.As per coding guidelines, comments must explain non-obvious invariants. As per path instructions, document hidden path and compatibility invariants.
🤖 Prompt for 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. In `@pnpm/crates/package-manager/src/virtual_store_layout.rs` around lines 71 - 94, Update the documentation for the package_store_dir field and its accessor to describe it as the default snapshot-slot root, global only when GVS is enabled, rather than claiming it contains every slot. Explain that directory-resolved slots may use local_store_dir, and direct per-slot callers to store_root_for. Preserve comments documenting the hidden path and compatibility invariants.Sources: Coding guidelines, Path instructions
🤖 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 @.changeset/gvs-concurrent-slot-import.md:
- Around line 5-7: Rewrite the changeset description to state only the
user-visible fix: concurrent global virtual-store imports no longer fail or
temporarily remove shared package slots. Remove implementation details about
directory removal, staging, content-addressed paths, and pnpm internals.
In @.changeset/gvs-directory-resolutions-stay-local.md:
- Around line 1-2: Add a separate changeset entry for the published package
"pnpm/napi" with a minor version bump, while retaining the existing "pacquet"
patch entry for the Rust-only routing fix. Ensure the changeset names both
affected packages with their required bump levels.
In `@pnpm/crates/napi/src/install/tests.rs`:
- Around line 534-537: Extend the tests around build_overlay() and
build_config() with focused cases for enableGlobalVirtualStore,
globalVirtualStoreDir, packageExtensions, and patchedDependencies. Verify
shared-store path derivation/pinning, package-extension conversion, relative
patch paths anchored to the install dir, and workspace_dir set when no workspace
manifest exists; replace or supplement the current all-None fixture values with
targeted assertions for each behavior.
In `@pnpm/crates/package-manager/src/create_virtual_dir_by_snapshot.rs`:
- Around line 166-175: Derive safe_to_skip in the import-options setup around
ImportIndexedDirOpts from whether the per-snapshot resolution uses the global
store, rather than directly from layout.enable_global_virtual_store(). Ensure
local_store_dir imports cannot skip replacement when source bytes change, while
preserving skip behavior for the per-snapshot global-store route. Add a
regression test covering global mode, a directory dependency with unchanged
filenames, and changed source bytes.
In `@pnpm/crates/package-manager/src/import_indexed_dir.rs`:
- Around line 431-433: Update the occupied-target branch in importIndexedDir to
handle errors from fs::remove_dir_all(&stage) instead of discarding them.
Propagate a contextual ImportIndexedDirError when staging cleanup fails, while
preserving Ok(()) only when cleanup succeeds.
In `@pnpm/crates/package-manager/src/validate_lockfile_paths.rs`:
- Around line 40-43: Add tests in validate_lockfile_paths/tests.rs covering
validate_virtual_store_slot_containment with LockfileResolution::Directory
snapshots under GVS: verify an injected local directory slot within the
project-local store passes, and a crafted directory slot escaping its selected
route fails. Reuse the existing lockfile path fixtures and assertions for
regular containment and GVS escape cases.
In `@pnpm/npm/napi/index.d.ts`:
- Around line 142-146: Correct the mixed virtual-store contract across
pnpm/npm/napi/index.d.ts lines 142-146, pnpm/npm/napi/index.d.ts lines 421-427,
and pnpm/crates/napi/src/read_config.rs lines 62-70: document that shared-store
placement applies only to global-eligible snapshots, while directory-resolved
snapshots remain project-local; scope the virtual-store path field accordingly
or expose both roots, and keep the Rust read_config contract aligned with the
TypeScript declaration.
- Around line 107-112: Extend the NAPI PackageExtension type to expose
peerDependenciesMeta, then update the object conversion and build_overlay in
install.rs to map it into pacquet_config::PackageExtension instead of always
setting peer_dependencies_meta to None. Add an install test covering propagation
of peer dependency metadata through the Node API configuration.
---
Outside diff comments:
In `@pnpm/crates/package-manager/src/import_indexed_dir.rs`:
- Around line 394-438: Reorder the import flow so the safe-to-skip
occupied-target check runs before the `nm_moved`/`node_modules` preservation
block. For `safe_to_skip` with a completed target confirmed by
`all_files_match`, discard staging and return without moving or removing
`target_modules`; only preserve `node_modules` when the target is incomplete and
the destructive swap is required. Add coverage for `safe_to_skip: true`,
`keep_modules_dir: true`, and a completed target containing nested dependencies.
---
Nitpick comments:
In @.changeset/gvs-directory-resolutions-stay-local.md:
- Line 7: Update the changeset entry to remove the internal rationale about hash
scoping, global virtual stores, and module-resolution paths. Keep only a concise
user-facing statement that directory resolutions remain local while registry
resolutions remain shared.
In `@pnpm/crates/package-manager/src/virtual_store_layout.rs`:
- Around line 71-94: Update the documentation for the package_store_dir field
and its accessor to describe it as the default snapshot-slot root, global only
when GVS is enabled, rather than claiming it contains every slot. Explain that
directory-resolved slots may use local_store_dir, and direct per-slot callers to
store_root_for. Preserve comments documenting the hidden path and compatibility
invariants.
In `@pnpm/crates/package-manager/src/virtual_store_layout/tests.rs`:
- Line 572: Remove the assertion-narrating comments adjacent to the assertions
at the referenced locations in the test. Preserve the test-level documentation
comment describing the cross-project routing invariant, and leave the assertions
and test behavior unchanged.
🪄 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: 743851ea-4152-4cdb-83f5-2ce852296ee8
📒 Files selected for processing (17)
.changeset/gvs-concurrent-slot-import.md.changeset/gvs-directory-resolutions-stay-local.mdpnpm/crates/cli/src/cli_args/deploy.rspnpm/crates/napi/src/config.rspnpm/crates/napi/src/install.rspnpm/crates/napi/src/install/tests.rspnpm/crates/napi/src/read_config.rspnpm/crates/package-manager/src/build_modules.rspnpm/crates/package-manager/src/create_virtual_dir_by_snapshot.rspnpm/crates/package-manager/src/import_indexed_dir.rspnpm/crates/package-manager/src/import_indexed_dir/tests.rspnpm/crates/package-manager/src/link_hoisted_modules.rspnpm/crates/package-manager/src/patch.rspnpm/crates/package-manager/src/validate_lockfile_paths.rspnpm/crates/package-manager/src/virtual_store_layout.rspnpm/crates/package-manager/src/virtual_store_layout/tests.rspnpm/npm/napi/index.d.ts
Micro-Benchmark ResultsLinux |
|
Code review by qodo was updated up to the latest commit af385fc |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
af385fc to
67e7792
Compare
|
Code review by qodo was updated up to the latest commit 67e7792 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
pnpm/crates/deps-restorer/src/build_modules.rs (1)
264-266: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winDocument the newly public utility contracts.
Each function now has
pubvisibility but no Rustdoc contract.
pnpm/crates/deps-restorer/src/build_modules.rs#L264-L266: document the peer-suffix normalization guarantee.pnpm/crates/deps-restorer/src/build_modules.rs#L1607-L1613: document leading-slash handling, last-@splitting, and the empty-version result.pnpm/crates/deps-restorer/src/create_virtual_dir_by_snapshot.rs#L259-L267: document the mapping fromPackageImportMethodtoWireImportMethod.As per coding guidelines, use Rustdoc comments for public API contracts.
🤖 Prompt for 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. In `@pnpm/crates/deps-restorer/src/build_modules.rs` around lines 264 - 266, Document the public utility contracts with Rustdoc comments at all three sites: in pnpm/crates/deps-restorer/src/build_modules.rs:264-266, describe normalize_build_dep_path’s peer-suffix normalization guarantee; in pnpm/crates/deps-restorer/src/build_modules.rs:1607-1613, document leading-slash handling, splitting at the last @, and the empty-version result; and in pnpm/crates/deps-restorer/src/create_virtual_dir_by_snapshot.rs:259-267, document the mapping from PackageImportMethod to WireImportMethod.Sources: Coding guidelines, Path instructions
🤖 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 `@pnpm/crates/deps-restorer/src/create_virtual_dir_by_snapshot.rs`:
- Around line 166-174: Restrict safe_to_skip in the
create_virtual_dir_by_snapshot import flow to shared global-virtual-store
content-addressed slots: derive it per PackageKey only when a precomputed GVS
suffix exists and the key is not a directory dependency, rather than using
VirtualStoreLayout::enable_global_virtual_store() alone. Preserve project-local
handling for directory packages and add a regression covering changed directory
contents with an unchanged file list.
In `@pnpm/crates/deps-restorer/src/import_indexed_dir/tests.rs`:
- Around line 687-689: Update the test comment near the shared content-addressed
slot case to describe only the invariant that a slot being populated by another
process must not be torn down. Remove the references to safe_to_skip, the prior
remove_dir_all behavior, concurrent-writer leftovers, and the obsolete
“RemoveExisting” error.
In `@pnpm/crates/deps-restorer/src/virtual_store_layout.rs`:
- Around line 296-306: Update the directory_keys filter to reuse
is_local_directory(), so metadata-less file snapshots and entries marked
LockfileResolution::Directory are classified as project-local regardless of
whether packages is None or lacks the peer-stripped entry. Add a regression
covering snapshots: Some(...) with packages: None and verify the snapshot
remains in the local layout.
---
Outside diff comments:
In `@pnpm/crates/deps-restorer/src/build_modules.rs`:
- Around line 264-266: Document the public utility contracts with Rustdoc
comments at all three sites: in
pnpm/crates/deps-restorer/src/build_modules.rs:264-266, describe
normalize_build_dep_path’s peer-suffix normalization guarantee; in
pnpm/crates/deps-restorer/src/build_modules.rs:1607-1613, document leading-slash
handling, splitting at the last @, and the empty-version result; and in
pnpm/crates/deps-restorer/src/create_virtual_dir_by_snapshot.rs:259-267,
document the mapping from PackageImportMethod to WireImportMethod.
🪄 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: 76c0694c-1174-4d3d-95a0-56fbecc69e53
📒 Files selected for processing (17)
.changeset/gvs-concurrent-slot-import.md.changeset/gvs-directory-resolutions-stay-local.mdpnpm/crates/cli/src/cli_args/deploy.rspnpm/crates/deps-restorer/src/build_modules.rspnpm/crates/deps-restorer/src/create_virtual_dir_by_snapshot.rspnpm/crates/deps-restorer/src/import_indexed_dir.rspnpm/crates/deps-restorer/src/import_indexed_dir/tests.rspnpm/crates/deps-restorer/src/link_hoisted_modules.rspnpm/crates/deps-restorer/src/validate_lockfile_paths.rspnpm/crates/deps-restorer/src/virtual_store_layout.rspnpm/crates/deps-restorer/src/virtual_store_layout/tests.rspnpm/crates/napi/src/config.rspnpm/crates/napi/src/install.rspnpm/crates/napi/src/install/tests.rspnpm/crates/napi/src/read_config.rspnpm/crates/package-manager/src/patch.rspnpm/npm/napi/index.d.ts
🚧 Files skipped from review as they are similar to previous changes (8)
- pnpm/crates/cli/src/cli_args/deploy.rs
- pnpm/crates/napi/src/install/tests.rs
- pnpm/crates/package-manager/src/patch.rs
- .changeset/gvs-directory-resolutions-stay-local.md
- pnpm/npm/napi/index.d.ts
- pnpm/crates/napi/src/config.rs
- pnpm/crates/napi/src/install.rs
- pnpm/crates/napi/src/read_config.rs
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 `@pnpm/crates/deps-restorer/src/import_indexed_dir/tests.rs`:
- Around line 691-724: Update
safe_to_skip_keeps_a_target_a_concurrent_importer_already_completed and its test
setup to run two import_indexed_dir calls concurrently against the same target,
synchronizing both at the swap point. Assert both imports succeed, the completed
target contents remain intact, and no staging directories remain; retain
coverage for the occupied completed-target interleaving rather than only
pre-populating the target before a single import.
In `@pnpm/crates/napi/src/read_config.rs`:
- Around line 65-71: Update the rustdoc for the public field virtual_store_dir
to state that <modules_dir>/.pnpm is its default value, while the actual path is
configurable through config.virtual_store_dir. Preserve the existing explanation
that local resolutions remain in this project-local store even when the global
virtual store is enabled.
🪄 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: d21d927a-7987-49f5-a975-399691d45b87
📒 Files selected for processing (17)
.changeset/gvs-concurrent-slot-import.md.changeset/gvs-directory-resolutions-stay-local.mdpnpm/crates/cli/src/cli_args/deploy.rspnpm/crates/deps-restorer/src/build_modules.rspnpm/crates/deps-restorer/src/create_virtual_dir_by_snapshot.rspnpm/crates/deps-restorer/src/import_indexed_dir.rspnpm/crates/deps-restorer/src/import_indexed_dir/tests.rspnpm/crates/deps-restorer/src/link_hoisted_modules.rspnpm/crates/deps-restorer/src/validate_lockfile_paths.rspnpm/crates/deps-restorer/src/virtual_store_layout.rspnpm/crates/deps-restorer/src/virtual_store_layout/tests.rspnpm/crates/napi/src/config.rspnpm/crates/napi/src/install.rspnpm/crates/napi/src/install/tests.rspnpm/crates/napi/src/read_config.rspnpm/crates/package-manager/src/patch.rspnpm/npm/napi/index.d.ts
🚧 Files skipped from review as they are similar to previous changes (14)
- pnpm/crates/package-manager/src/patch.rs
- pnpm/crates/cli/src/cli_args/deploy.rs
- pnpm/crates/deps-restorer/src/link_hoisted_modules.rs
- .changeset/gvs-directory-resolutions-stay-local.md
- pnpm/crates/deps-restorer/src/virtual_store_layout/tests.rs
- pnpm/npm/napi/index.d.ts
- pnpm/crates/deps-restorer/src/create_virtual_dir_by_snapshot.rs
- pnpm/crates/deps-restorer/src/validate_lockfile_paths.rs
- pnpm/crates/napi/src/install.rs
- pnpm/crates/deps-restorer/src/virtual_store_layout.rs
- pnpm/crates/napi/src/install/tests.rs
- pnpm/crates/deps-restorer/src/import_indexed_dir.rs
- pnpm/crates/deps-restorer/src/build_modules.rs
- pnpm/crates/napi/src/config.rs
67e7792 to
3963d42
Compare
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
|
Code review by qodo was updated up to the latest commit 6583d13 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Documents `enableGlobalVirtualStore`, `globalVirtualStoreDir` and `patchedDependencies`, and adds the script that installs a locally built pnpm engine over the published `@pnpm/napi` - needed until a release carries the options this branch passes (pnpm/pnpm#13648).
The global virtual store work needs two engine changes that are now in a released build: the napi surface for `enableGlobalVirtualStore`, `globalVirtualStoreDir`, `packageExtensions` and `patchedDependencies` (pnpm/pnpm#13648), and the fix for `link:` dependencies vanishing from virtual-store slots (pnpm/pnpm#13658). Verified on the released engine: a global-virtual-store install of the opus-5 workspace reuses all 30,766 existing slots (creates none), leaves the project-local `node_modules/.pnpm` empty, and still applies the react-env tsconfig patch. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The global virtual store work needs two engine changes that are now in a released build: the napi surface for `enableGlobalVirtualStore`, `globalVirtualStoreDir`, `packageExtensions` and `patchedDependencies` (pnpm/pnpm#13648), and the fix for `link:` dependencies vanishing from virtual-store slots (pnpm/pnpm#13658). Verified on the released engine: a global-virtual-store install of the opus-5 workspace reuses all 30,766 existing slots (creates none), leaves the project-local `node_modules/.pnpm` empty, and still applies the react-env tsconfig patch. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The global virtual store work needs two engine changes that are now in a released build: the napi surface for `enableGlobalVirtualStore`, `globalVirtualStoreDir`, `packageExtensions` and `patchedDependencies` (pnpm/pnpm#13648), and the fix for `link:` dependencies vanishing from virtual-store slots (pnpm/pnpm#13658). Verified on the released engine: a global-virtual-store install of the opus-5 workspace reuses all 30,766 existing slots (creates none), leaves the project-local `node_modules/.pnpm` empty, and still applies the react-env tsconfig patch. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Documents `enableGlobalVirtualStore`, `globalVirtualStoreDir` and `patchedDependencies`, and adds the script that installs a locally built pnpm engine over the published `@pnpm/napi` - needed until a release carries the options this branch passes (pnpm/pnpm#13648).
The global virtual store work needs two engine changes that are now in a released build: the napi surface for `enableGlobalVirtualStore`, `globalVirtualStoreDir`, `packageExtensions` and `patchedDependencies` (pnpm/pnpm#13648), and the fix for `link:` dependencies vanishing from virtual-store slots (pnpm/pnpm#13658). Verified on the released engine: a global-virtual-store install of the opus-5 workspace reuses all 30,766 existing slots (creates none), leaves the project-local `node_modules/.pnpm` empty, and still applies the react-env tsconfig patch. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Documents `enableGlobalVirtualStore`, `globalVirtualStoreDir` and `patchedDependencies`, and adds the script that installs a locally built pnpm engine over the published `@pnpm/napi` - needed until a release carries the options this branch passes (pnpm/pnpm#13648).
The global virtual store work needs two engine changes that are now in a released build: the napi surface for `enableGlobalVirtualStore`, `globalVirtualStoreDir`, `packageExtensions` and `patchedDependencies` (pnpm/pnpm#13648), and the fix for `link:` dependencies vanishing from virtual-store slots (pnpm/pnpm#13658). Verified on the released engine: a global-virtual-store install of the opus-5 workspace reuses all 30,766 existing slots (creates none), leaves the project-local `node_modules/.pnpm` empty, and still applies the react-env tsconfig patch. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Opt-in support for pnpm's global virtual store: dependency directories are created once in a store shared by every workspace on the machine, instead of being re-created inside each `node_modules/.pnpm`. Capsules deliberately keep the project-local layout — see below. Every engine dependency is in a published `@pnpm/napi`: the settings surface (pnpm/pnpm#13648) and the `link:` slot fix (pnpm/pnpm#13658) in 12.0.0-rc.0, and the slot-materialization dedup (pnpm/pnpm#13669) in 12.0.0-rc.1, which this branch pins. The local-engine bootstrap script is gone. ## Effect After a fresh install the project-local virtual store holds nothing but `lock.yaml` and the hoisted `node_modules` — every dependency directory, including injected workspace components, lives in the shared store: | workspace | `node_modules/.pnpm` entries, no GVS | with GVS | |---|---|---| | a Bit Cloud workspace | 20832 | 0 | | the bit repo itself | 6441 | 0 | | bitdev-envs | 4017 | 0 | Bit uses pnpm's own `<storeDir>/links`, so slots are reused across bit versions and shared with every other pnpm project on the machine, upgrades stay incremental, and `pnpm store prune` accounts for them. Migration note: switching an existing workspace over does not remove what the previous project-local store already contains — pnpm does not prune it once the effective virtual store points elsewhere — so the old directories linger until `node_modules/.pnpm` is deleted. New workspaces never see them. ## Turning it on Off by default. Per workspace under `teambit.dependencies/dependency-resolver`, machine-wide with `bit config set enable_global_virtual_store true`, or per run with `BIT_ENABLE_GLOBAL_VIRTUAL_STORE=true`. It has no effect when `nodeLinker` is `hoisted`, which uses no virtual store at all. ## What it took to behave identically A shared store breaks one assumption that runs through Bit: that a package can walk *up* out of `node_modules/.pnpm` into the workspace. Consequences: - **Core aspects (CJS).** Bit deliberately does not declare `@teambit/*` core aspects as dependencies of the envs and aspects that use them — they have to be the single copy from the running installation, and declaring them would install duplicates. Project-locally they resolved by walking up into the workspace root; nothing in a shared store can. This branch uses pnpm's documented mechanism for hoisted dependencies in this layout: the privately hoisted directory stays project-local at `node_modules/.pnpm/node_modules` even under the global virtual store, the core aspects are linked there, and `bootstrap` puts that directory on `NODE_PATH` before any aspect loads. Nothing is written inside the store itself, which is what allows the shared `<storeDir>/links` to be used at all. - **Core aspects (ESM).** Node ignores `NODE_PATH` for ESM, and bit supports ESM components, so the same hoisted-directory fallback is provided to the ESM resolver via a `module.register()` loader (adapted from pnpm's `@pnpm/plugin-esm-node-path`, MIT), installed at bootstrap and propagated to child processes through `NODE_OPTIONS`. - **Phantom `tsconfig` `extends` in published envs.** TypeScript resolves `extends` with its own resolver — neither `NODE_PATH` nor the ESM loader applies — and several published envs extend a package they never declare (`@teambit/react/typescript/tsconfig.json` from the node mocha envs, `base-react-env`, `rspack.envs.react-env` and `react-env` 1.x; `rspack.envs.react-env/config/tsconfig.json` from `cloud-react`). Project-locally the walk up out of `.pnpm` passed the privately hoisted directory and caught these by accident. Fixed with pnpm's documented remedy: built-in `packageExtensions` declaring the missing dependency for the known envs, merged under the workspace's own `packageExtensions` so users can cover third-party envs the same way. Extensions only add what a manifest lacks, an unmatched entry is not an error (react-env's is scoped to `@1` — 2.x inlined the config), and none of these envs import their extends-target at runtime, so the added copy cannot shadow the host-provided singletons. (#10572 explored a `patchedDependencies`-based variant for react-env 1.x and is closed — the extensions cover it.) - **The bit repo itself.** A workspace that *authors* the core aspects bridges them into the hoisted store only until they compile, then removes the bridge. Right project-locally, fatal from a shared store. The bridge now persists, repointed at the compiled workspace copy. - **Injected dirs.** `getInjectedDirs` reports an injected copy absolute when it cannot be made relative to the lockfile dir — under a shared store, always. `compiler.task.ts` joined it onto the capsule root regardless, hard-linking build artifacts into a path that does not exist. (`node-modules-linker` and `workspace-compiler` already guarded this; only that one site did not.) - **`bit deps diagnose`.** Its duplicate-copy counts came from scanning `node_modules/.pnpm`. The shared store holds every workspace's packages, so it cannot answer that question for one workspace; the counts now come from the current lockfile pnpm writes next to the hoisted directory, whose dep paths map one-to-one onto the project-local directory names. - **Capsules stay project-local.** A capsule is a self-contained build sandbox and TypeScript's declaration emit depends on that: it names an inferred type through the package that declares it, which it can only do while that package sits inside the capsule. Moving env/aspect packages out made `bit build` of any custom env fail with `TS2742`. Workspace installs — the ones users wait on repeatedly — still get the shared store. ## Also here: `patchedDependencies` The branch adds pnpm's `patchedDependencies` as a dependency-resolver setting (it began as the vehicle for the react-env `tsconfig` fix above, and is useful on its own): ```json { "teambit.dependencies/dependency-resolver": { "patchedDependencies": { "[email protected]": "patches/is-positive.patch" } } } ``` Paths are relative to the workspace root. pnpm resolves a relative patch path from the directory it is installing in, so capsule installs — which run in the capsules directory — get the paths resolved against the workspace root first; workspace installs keep the configured spelling, which pnpm records in `pnpm-lock.yaml` and which must stay machine-independent there. ## Self-hosting: a workspace whose node_modules provides the running bit Both layouts are safe in steady state: repeat installs preserve the top-level package directories the running process resolves from (verified by sampling them through live installs), and the end-of-install compile refreshes the per-variant copies. A layout *switch* is different — it relocates every injected component package, rebuilding the top-level directories from source, so their compiled `dist` disappears mid-install and a bit running from them dies before reaching the compile that would restore it, leaving `node_modules` unusable. The installer now detects the combination (current layout read off `.modules.yaml`, self-hosting by realpath of the running module) and refuses up front with instructions to run the one-time transition from an external bit installation. With that and the engine fix, the bit repo itself runs under the global virtual store: full install + compile of all 332 components, repeat self-hosted installs in ~50s, `npm run lint` green. The repo's own tsc needed the type-layer counterpart of the runtime bridges — `tsconfig.json` `paths` routing react typings and `@teambit/*` through the workspace's `node_modules`, since a published package's `.d.ts` cannot reach undeclared `@types`/core aspects from a store slot either. ## Phantom dependencies, generally A shared store makes an under-declared package fail loudly: it lives outside the project, so nothing the project hoisted is on its resolution path any more. That is a real constraint, not a bug to work around, and it applies to pnpm generally rather than to Bit. Every failure this branch hit was a genuine phantom dependency — an env's undeclared `tsconfig` base, a fixture env with detection switched off (`@bit-no-check` removed so the dependency gets declared), `@teambit/webpack.webpack-bundler` requiring `events/` without declaring it (covered by `packageExtensions`, documented in the aspect docs), and the repo's own undeclared `@types/graceful-fs` (now declared). ## One CI change `bit_pr` now runs on a temp lane (dropped `--keep-lane`). A reused PR lane serves components unchanged since an earlier export with artifacts from older commits, so capsules mix generations of `@teambit` packages and cross-copy `instanceof` checks start failing — deterministic red that looks exactly like branch breakage and defeats bisection (on this branch: run 1 green on a fresh lane, every later push red, across 11 runs and 2 lanes). Filed as #10583; the temp-lane flow is self-consistent per run. ## Testing - New e2e: `global-virtual-store.e2e.ts` (nothing materialized in the workspace, dependencies linked from the shared store, component loads and compiles, patched dependencies under the store) and `patched-dependencies.e2e.ts` (a workspace-relative patch applies both in the workspace and in the capsule — verified to fail before the capsule-path fix). - The bit repo (332 components): full global-virtual-store install, repeat self-hosted installs, transition guard verified in both directions (clean refusal, workspace intact), lint green. Runs on the released rc.1 engine. - A Bit Cloud workspace, 105 components: wiped-`node_modules` install + compile, slot reuse verified (a repeat install creates 0 of 30766 slots), core-aspect resolution through `NODE_PATH` verified positively and negatively, `bit start` working. - bitdev-envs (609 components, 20 apps): `bit app list` byte-identical to the non-GVS baseline, apps running — against an earlier revision of the core-aspect mechanism. - The full e2e suite under `BIT_ENABLE_GLOBAL_VIRTUAL_STORE=true` was run locally against an earlier revision: no GVS-specific failures (the `validate command` failures reproduce with the store off). CI runs the suite in its default store-off configuration, where this branch has been green including the 40-shard e2e. The first commit (`fix(doctor)`) is unrelated to the rest and can be split out — it surfaced because the e2e temp dir contains a dot, which is why `doctor-infra.e2e.ts` fails locally but passes on CI. --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Summary
Makes global virtual-store imports safe when multiple processes materialize the same content-addressed slot, and exposes the related embedding options through
@pnpm/napi.ImportIndexedDirOpts::safe_to_skipfor immutable global virtual-store slots. A competing importer keeps an occupied target only after verifying that the import is complete; incomplete targets still use the repair path.enableGlobalVirtualStore,globalVirtualStoreDir,packageExtensions, andpatchedDependenciesto the N-API install options.enableGlobalVirtualStore,globalVirtualStoreDir,virtualStoreDir, andeffectiveVirtualStoreDirfromreadConfig.The TypeScript implementation already enables
safeToSkipfor global virtual-store imports. The N-API surface is specific to pacquet, so no TypeScript implementation change is required.Validation performed on this branch:
cargo nextest run --workspace --exclude pnpr --exclude pnpr-fixtures: 7010 passed, 0 failed.Squash Commit Body
Checklist
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 (Codex, GPT-5).