Resolve scoped package paths during linking on Windows #1862
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
Resolves #1861.
The above issue is Windows-specific. It's caused by the step that unlinks extraneous packages. This compares a Set
possibleExtraneous
against a Set of pathsfiles
resolved during bulk copy.The problem is how paths are added to the
files
Set. yarn attempts to add all path segments tofiles
by splitting the destination path onpath.sep
. This works as expected on Posix systems, where the path separator is the same as the scoped package name delimiter:project/node_modules/@scoped/dep/node_modules/subdep
But on Windows, the destination path is constructed naively from the package name:
project\\node_modules\\@scoped/dep\\node_modules\\subdep
possibleExtraneous
, having been resolved from reading directories on disk rather than from thepackage.json
contains the correct Windows path:project\\node_modules\\@scoped\\dep\\node_modules\\subdep
possibleExtraneous
then checks to see if its members are present infiles
. Any that are are not considered extraneous. Because of the above difference in the path string, scoped subdirectories are wrongly seen as extraneous, and deleted.What changed
It was difficult for me to tell what was intended behavior in other parts of the system, so I constrained this change to the two places that file paths are added to the non-extraneous
files
collection during the bulk copy operation. I'm callingpath.normalize
on each destination path before it's split bypath.sep
. This resolves the separator inconsistency caused by scoped package names.It may be better to resolve this higher up, e.g where the
CopyQueue
is generated.Test plan
Automated:
I'm having trouble running automated tests locally due to #1823. I could also use some help with Jest.
Manual:
The repro steps in the linked issue demonstrate that this is resolved on Windows.
yarn add
a scoped package (ex.@cycle/http
)yarn add
any dependency of the scoped package, at an incompatible version (ex.[email protected]
) (This prevents the subdependency of the scoped package from hoisting)yarn add
a second time