Skip to content

feat: global virtual store #8190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 49 commits into from
Jun 3, 2025
Merged

feat: global virtual store #8190

merged 49 commits into from
Jun 3, 2025

Conversation

zkochan
Copy link
Member

@zkochan zkochan commented Jun 10, 2024

close #1001

@zkochan zkochan changed the title perf: symlink dependencies from store feat: global virtual store May 30, 2025
@zkochan zkochan force-pushed the symlink-deps-from-store branch from 21d489c to c288e57 Compare June 2, 2025 08:29
@zkochan zkochan marked this pull request as ready for review June 2, 2025 22:33
@zkochan zkochan requested a review from Copilot June 2, 2025 22:46
Copy link

@Copilot 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

Adds support for a global virtual store to centralize package storage and symlink into project node_modules.

  • Introduces enableGlobalVirtualStore & globalVirtualStoreDir flags across resolution, install, and config layers
  • Updates dependency-graph builders and installers to route packages into a shared deps directory
  • Adds new utilities (iterateHashedGraphNodes, iteratePkgsForVirtualStore) and an end-to-end test for the global virtual store

Reviewed Changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg-manager/resolve-dependencies/src/index.ts Added enableGlobalVirtualStore flag and extended graph logic
pkg-manager/resolve-dependencies/src/resolveDependencyTree.ts Exposed globalVirtualStoreDir in resolve options
pkg-manager/headless/src/index.ts Updated HeadlessOptions and lockfile graph invocation
pkg-manager/core/src/install/index.ts Integrated enableGlobalVirtualStore into prune logic
pkg-manager/core/src/install/extendInstallOptions.ts Defaulted globalVirtualStoreDir when the flag is enabled
pkg-manager/core/src/getPeerDependencyIssues.ts Passed globalVirtualStoreDir into peer dependency resolution
pkg-manager/core/test/install/globalVirtualStore.ts Added integration test for global virtual store
packages/calc-dep-state/src/index.ts Introduced iterateHashedGraphNodes API
packages/calc-dep-state/package.json Added sort-keys dependency
deps/graph-builder/… Adapted lockfileToDepGraph and iterators for global store support
config/config/src/types.ts & Config.ts Exposed CLI flags enable-global-virtual-store and global-virtual-store-dir
Comments suppressed due to low confidence (2)

pkg-manager/resolve-dependencies/src/index.ts:122

  • The resolveDependencies options include enableGlobalVirtualStore but lack a corresponding globalVirtualStoreDir property, which may lead to undefined being passed into extendGraph. Consider adding globalVirtualStoreDir?: string to the options interface.
enableGlobalVirtualStore?: boolean

packages/calc-dep-state/package.json:40

  • The dependency version spec "catalog:" for sort-keys appears malformed and will likely cause installation failures. Verify and correct the version string.
"sort-keys": "catalog:"

@@ -142,6 +142,8 @@ export interface HeadlessOptions {
currentHoistedLocations?: Record<string, string[]>
lockfileDir: string
modulesDir?: string
enableGlobalVirtualStore: boolean
Copy link
Preview

Copilot AI Jun 2, 2025

Choose a reason for hiding this comment

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

Declaring enableGlobalVirtualStore as a required boolean may break existing consumers. Consider making this field optional (enableGlobalVirtualStore?: boolean) to maintain backward compatibility.

Copilot uses AI. Check for mistakes.

@@ -19,6 +19,7 @@ export const types = Object.assign({
'disallow-workspace-cycles': Boolean,
'enable-modules-dir': Boolean,
'enable-pre-post-scripts': Boolean,
'enable-global-virtual-store': Boolean,
Copy link
Preview

Copilot AI Jun 2, 2025

Choose a reason for hiding this comment

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

[nitpick] The new enable-global-virtual-store and global-virtual-store-dir config options need documentation in the CLI reference or README to guide users on their usage.

Copilot uses AI. Check for mistakes.

@zkochan
Copy link
Member Author

zkochan commented Jun 2, 2025

I am not sure yet how this global virtual store will be cleaned. Probably we can do this in a later PR.

Probably we could record the locations of all projects using the given global virtual store. The easiest way to record them would be probably to create symlinks to these projects. We'd have a directory with symlinks (e.g. in <store-dir>/users). The symlink file names could be the hashed paths of the user projects.

Once we have the locations of projects that are using the global virtual store, we can recursively resolve all symlink dependencies of all projects. When that's done, we'll have the list of all dependencies currently referenced. All unreferenced dependencies can be removed.

@kenrick95
Copy link
Member

I'd like to check what's the consequence of this (since the linked issue is very old and contains lots of comments that I felt could be outdated)?

My understanding that this PR adds an opt-in option to having the PNPM 'virtual store' instead of located at workspace (usually repo root), makes it located at a global location.

My questions are:

  1. What are the benefit of this?
  2. Would hoisting still work? Or is it strictly prohibited now?
  3. If hoisiting is allowed, would that make this much less correct? Since a package installed from a workspace will use that global virtual store and it can access package installed from other repo?

Thanks~

@zkochan
Copy link
Member Author

zkochan commented Jun 3, 2025

What are the benefit of this?

Installation will be much faster during local development.

Would hoisting still work? Or is it strictly prohibited now?

This doesn't change how nodeLinker: hoisted works. If you mean the hoisting with symlinks then I think we can still make it work by setting the NODE_PATH env variable.

If hoisiting is allowed, would that make this much less correct? Since a package installed from a workspace will use that global virtual store and it can access package installed from other repo?

No, the hoisting will not be global. The hoisting remains local to the project.

@zkochan zkochan merged commit b0ead51 into main Jun 3, 2025
16 of 20 checks passed
@zkochan zkochan deleted the symlink-deps-from-store branch June 3, 2025 16:19
zkochan added a commit that referenced this pull request Jun 8, 2025
This is an addition to #8190. The global virtual store isn't a good choice for CI. So, we disable it even if the setting sets `enableGlobalVirtualStore` to `true`.
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.

Saving packages with their dependency set in the store
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy