fix: support npm install-strategy=linked (.store layout)#596
Open
manzoorwanijk wants to merge 1 commit intods300:masterfrom
Open
fix: support npm install-strategy=linked (.store layout)#596manzoorwanijk wants to merge 1 commit intods300:masterfrom
manzoorwanijk wants to merge 1 commit intods300:masterfrom
Conversation
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.
Summary
resolvePackagePathutility that locates packages when they aren't at the expectednode_modules/path, with two fallback strategies:node_modules/.store/for npminstall-strategy=linkedlayoutsgetPatchApplicationState,savePatchApplicationState,clearPatchApplicationState)makePatchso patch creation also works with non-standard layoutsFixes #595, partially addresses #277
Context
npm's experimental
install-strategy=linkedstores packages innode_modules/.store/<pkg>@<version>-<hash>/node_modules/<pkg>/and creates symlinks. For nested dependencies in monorepo/workspace setups, the symlink may not exist at the path patch-package expects (e.g.node_modules/parent/node_modules/child), causing patch application to fail with "package not present" errors.Similarly, in monorepos with hoisting (#277), a workspace package's dependency may be installed in the root
node_modules/rather than the workspace's ownnode_modules/, causing the same failure.How it works
resolvePackagePath()tries three strategies in order:node_modules/<pkg>path exists (regular install or working symlink), return immediately with no overhead..storesearch — scannode_modules/.store/for entries matching<packageName>@<version>*, preferring version-specific matches.node_modules/for the package, handling monorepo hoisting.When the resolved path differs from the original,
remapPatchPaths()rewrites the path prefixes in all patch effects (file patches, creations, deletions, renames, mode changes) beforeexecuteEffectsruns. The resolved path is also passed to state file operations so.patch-package.jsonis read/written at the correct location.