feat: enhance store prune to clean global virtual store#10360
Merged
Conversation
`pnpm store prune` will now clean the global virtual store via a new project registry and mark-and-sweep garbage collection.
5 tasks
Throw `PnpmError` for inaccessible projects and specifically clean up stale symlinks for `ENOENT` errors.
by placing unscoped packages under an `@` scope.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR enhances pnpm store prune to clean the global virtual store by implementing mark-and-sweep garbage collection. Projects are now registered via symlinks in a projects/ directory within the store, enabling the prune command to track active projects and safely remove unreferenced packages.
Key Changes
- Added project registry system using symlinks in
{storeDir}/projects/to track projects using the store - Implemented mark-and-sweep garbage collection algorithm that walks symlinks to identify reachable packages
- Integrated global virtual store pruning into the existing prune workflow, executing before CAS pruning
Reviewed changes
Copilot reviewed 19 out of 21 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
store/package-store/src/storeController/projectRegistry.ts |
New module for registering projects and retrieving registered project paths |
store/package-store/src/storeController/pruneGlobalVirtualStore.ts |
New module implementing mark-and-sweep garbage collection for the global virtual store |
store/package-store/src/storeController/prune.ts |
Integrated global virtual store pruning as first step before CAS pruning |
store/package-store/src/index.ts |
Exported project registry functions for use in other modules |
pkg-manager/get-context/src/index.ts |
Added project registration calls when getting context |
store/package-store/test/projectRegistry.ts |
Comprehensive unit tests for project registry functionality |
store/plugin-commands-store/test/storePrune.ts |
Integration tests for global virtual store pruning scenarios |
store/plugin-commands-store/tsconfig.json |
Added package-store project reference |
store/plugin-commands-store/package.json |
Added @pnpm/package-store dependency |
store/package-store/tsconfig.json |
Added crypto.hash and error project references |
store/package-store/package.json |
Added crypto.hash, error, and symlink-dir dependencies |
pkg-manager/headless/tsconfig.json |
Added package-store project reference |
pkg-manager/headless/src/index.ts |
Minor formatting change (empty catch block spacing) |
pkg-manager/headless/package.json |
Added @pnpm/package-store dependency |
pkg-manager/get-context/tsconfig.json |
Added package-store project reference |
pkg-manager/get-context/package.json |
Added @pnpm/package-store dependency |
pkg-manager/core/tsconfig.json |
Added package-store project reference |
pkg-manager/core/package.json |
Added @pnpm/package-store dependency |
pnpm-lock.yaml |
Updated lockfile with new dependency resolutions |
.changeset/prune-global-virtual-store.md |
Changeset documenting mark-and-sweep garbage collection feature |
.changeset/global-virtual-store-prune.md |
Changeset documenting project registry feature |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
store/package-store/src/storeController/pruneGlobalVirtualStore.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 17 out of 18 changed files in this pull request and generated 8 comments.
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
store/package-store/src/storeController/pruneGlobalVirtualStore.ts
Outdated
Show resolved
Hide resolved
store/package-store/src/storeController/pruneGlobalVirtualStore.ts
Outdated
Show resolved
Hide resolved
are within the global virtual store.
zkochan
added a commit
that referenced
this pull request
Dec 26, 2025
* feat: enhance `store prune` to clean global virtual store `pnpm store prune` will now clean the global virtual store via a new project registry and mark-and-sweep garbage collection. * test: add store prune test for transitive dependency preservation * refactor: extract global virtual store pruning logic to a new file * fix: improve symlink handling in global virtual store pruning * fix: optimize removal of unreachable packages in global virtual store * fix: refine project registry error handling Throw `PnpmError` for inaccessible projects and specifically clean up stale symlinks for `ENOENT` errors. * test: create virtual store with install command * refactor: standardize global virtual store directory structure by placing unscoped packages under an `@` scope. * test: update store prune tests to use `toContain` and `not.toContain` assertions` * fix: linting issues * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: implemented CR suggestions * fix: revert not needed change * fix: use `is-subdir` to accurately determine if symlink targets are within the global virtual store. * revert: changes in package.json files * test: add `--config.ci=false` to store prune tests
Closed
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pnpm store prunewill now clean the global virtual store via a new project registry and mark-and-sweep garbage collection.Previous refactor PR, to make this easier to implement: #10363