Skip to content

feat: enhance store prune to clean global virtual store#10360

Merged
zkochan merged 17 commits intomainfrom
fix-prune-for-global-virtual-store
Dec 26, 2025
Merged

feat: enhance store prune to clean global virtual store#10360
zkochan merged 17 commits intomainfrom
fix-prune-for-global-virtual-store

Conversation

@zkochan
Copy link
Copy Markdown
Member

@zkochan zkochan commented Dec 24, 2025

pnpm store prune will 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

`pnpm store prune` will now clean the global virtual store
via a new project registry and mark-and-sweep garbage collection.
@zkochan zkochan marked this pull request as ready for review December 25, 2025 20:22
Copilot AI review requested due to automatic review settings December 25, 2025 20:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

zkochan and others added 3 commits December 25, 2025 22:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@zkochan zkochan merged commit 9eddabb into main Dec 26, 2025
13 checks passed
@zkochan zkochan deleted the fix-prune-for-global-virtual-store branch December 26, 2025 00:35
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants