Repository navigation
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent write attempts inside Global Virtual Store (GVS) package directories when those packages are already present (“warm”), which can fail when the store is backed by a read-only CAS (e.g. Nix).
Changes:
- Add
freshlyImported?: booleantoDependenciesGraphNodeto track whetherimportPackage()actually wrote package contents. - Set
depNode.freshlyImportedafterimportPackage()and use it in GVS mode to skip self-dep symlinking and per-package bin linking for warm packages. - Thread
enableGlobalVirtualStoreintolinkAllBins()so it can apply the warm-package skip in GVS mode.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
installing/deps-restorer/src/index.ts |
Tracks whether a package was freshly imported and skips post-import linking steps for warm packages in GVS mode. |
deps/graph-builder/src/lockfileToDepGraph.ts |
Extends DependenciesGraphNode with an optional freshlyImported flag. |
.changeset/skip-linking-warm-gvs-packages.md |
Adds a changeset documenting the behavior change as a patch. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
When safeToSkip causes importPackage to skip (package already present in the store), self-dep symlinking and bin linking are also skipped. These operations were completed during the original import, so re-running them is unnecessary and fails on read-only stores (e.g. Nix). Add freshlyImported flag to DependenciesGraphNode, set after importPackage, and check it before self-dep and bin linking in GVS mode.
086ff5e to
c30599a
Compare
There was a problem hiding this comment.
Pull request overview
This PR adjusts Global Virtual Store (GVS) behavior to avoid post-import operations that write into package directories when those packages were not freshly imported (e.g. when the store path is read-only such as in Nix). It introduces a freshlyImported flag on dependency graph nodes and uses it plus filesystem existence checks to skip self-dep symlinking and bin linking for warm packages.
Changes:
- Add
freshlyImported?: booleantoDependenciesGraphNodein@pnpm/deps.graph-builder. - Set
depNode.freshlyImportedbased onimportPackage()result and conditionally skip self-dep symlinking /.binlinking in GVS mode for warm packages when targets already exist. - Add a changeset for patch releases (and include a new
.pi/tasks/...jsonmetadata file).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| installing/deps-restorer/src/index.ts | Thread enableGlobalVirtualStore into bin linking and skip post-import linking steps for warm GVS packages when targets already exist. |
| deps/graph-builder/src/lockfileToDepGraph.ts | Extend DependenciesGraphNode with freshlyImported?: boolean. |
| .changeset/skip-linking-warm-gvs-packages.md | Release note describing the new skip behavior for warm GVS packages. |
| .pi/tasks/tasks-dd9df0f0-94e3-462d-bc5d-39fcabac4d49.json | Adds task-tracking metadata file (likely unintended repo artifact). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| "pnpm": patch | ||
| --- | ||
|
|
||
| Skip self-dep symlinking and bin linking for warm Global Virtual Store packages. When `safeToSkip` causes the import to be skipped (package already present), post-import linking is also skipped since it was completed during the original import. |
| version: string | ||
| fetching?: () => Promise<PkgRequestFetchResult> | ||
| forceImportPackage?: boolean // Used to force re-imports from the store of local tarballs that have changed. | ||
| freshlyImported?: boolean // Set to true when importPackage wrote to disk (importMethod returned). |
| // In GVS mode, skip when the self-dep symlink already exists — | ||
| // it was created during the original import and the directory may | ||
| // be read-only. | ||
| if (opts.enableGlobalVirtualStore && !depNode.freshlyImported && | ||
| existsSync(path.join(targetModulesDir, depNode.name))) return | ||
| await limitLinking(async () => symlinkDependency(pkg.dir, targetModulesDir, depNode.name)) |
| // In GVS mode, skip when the self-dep symlink already exists — | ||
| // it was created during the original import and the directory may | ||
| // be read-only. | ||
| if (opts.enableGlobalVirtualStore && !depNode.freshlyImported && | ||
| existsSync(path.join(targetModulesDir, depNode.name))) return |
There was a problem hiding this comment.
I guess we could skip it in all cases. Not only inside the gvs. But I am also not sure why symlink-dir tries to create the symlink if it already exists and is correct. I have specifically worked on this case to not recreate the symlinks.
| // In GVS mode, skip bin linking when the .bin directory already exists — | ||
| // the bins were linked during the original import and the directory may | ||
| // be read-only (e.g. Nix store). | ||
| if (opts.enableGlobalVirtualStore && !depNode.freshlyImported && existsSync(binPath)) return |
There was a problem hiding this comment.
maybe check the existence of every bin file individually?
|
I'm going to step back and make sure I"m solving the right problem. Sorry for the churn. |
… target (#11069) ## Summary `linkBin()` unconditionally calls `cmdShim()` / `symlinkDir()` even when the target bin already points at the correct path. This causes redundant I/O on repeated installs and `EACCES` failures when the bin directory lives on a read-only filesystem (Docker layer caching, CI prewarm, NFS mounts). This PR adds a check at the top of `linkBin()` that verifies the existing bin before skipping: - **Symlinks**: `readlink` target is compared against `cmd.path` - **Cmd-shim files**: checked via `isShimPointingAt()` from `@zkochan/cmd-shim` v9, which embeds a `# cmd-shim-target=<path>` marker in every generated sh shim - Files larger than 4KB (binaries) are never skipped — they are not cmd-shims Stale or incorrect bins (wrong target, missing marker, different provider) are always rewritten. Follows up on feedback from #11020. ## Changes - `bins/linker/src/index.ts` — add target verification check in `linkBin()` - `bins/linker/test/index.ts` — tests for skip and rewrite behavior - `pnpm-workspace.yaml` — upgrade `@zkochan/cmd-shim` to v9 --------- Co-authored-by: Zoltan Kochan <[email protected]>
Problem
When the Global Virtual Store is backed by a read-only content-addressable store (e.g. Nix), post-import operations that write into the package directory fail:
<pkg>/node_modules/<name>fs.mkdir(<pkg>/node_modules/.bin)Other install operations succeed because they either target the writable project-local
node_modules, or skip viasafeToSkipwhen the package already exists.Solution
In GVS mode, skip these operations when the package wasn't freshly imported and the target already exists on disk. Freshly imported packages are always writable, so linking proceeds unconditionally. Warm packages that already have their bins and self-dep symlinks in place are skipped. Warm packages that are missing these targets (e.g. populated by
pnpm fetchwithvirtualStoreOnly, which skips post-import linking) still get linked.This uses a
freshlyImportedflag onDependenciesGraphNode(set fromimportMethod) combined withexistsSyncchecks on the target paths.No try/catch, no error suppression, no new options on downstream packages.
Follows #10965 (
virtualStoreOnly), #10709 (GVS warm reattach). Supersedes #11017.Changes
@pnpm/deps.graph-builder— addfreshlyImported?: booleantoDependenciesGraphNode@pnpm/installing.deps-restorer:depNode.freshlyImported = importMethod != nullafterimportPackageenableGlobalVirtualStore && !freshlyImported && symlink existsenableGlobalVirtualStore && !freshlyImported && .bin dir existsVerification
@pnpm/deps.graph-builder: compiles clean@pnpm/installing.deps-restorer: compiles cleanlinkAllPkgsandlinkAllBinsare private functions reachable only throughheadlessInstall, which requires a full store/registry integration setup. End-to-end validation requires a read-only Nix store environment.