This repository has been archived by the owner on Jan 20, 2022. It is now read-only.
fix: _findMissingEdges missing dependency due to inconsistent path separators #363
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.
When installing a package with bundled dependencies with npm it can end up missing some dependencies that were bundled and attempt to fetch from the remote registry (see npm/cli#2757). This issue only happens on Windows and it's caused by
_findMissingEdges
missing one of the bundled dependencies. The reason it only happens on Windows is because of this lookup inthis[_cache]
with a path that contains mixed path separators:arborist/lib/arborist/load-actual.js
Lines 433 to 435 in 02f295f
On macOS we get a result back and avoid creating a new node. On Windows we get no result since the key in the cache is using backslashes but the lookup key has both backslashes and forward slashes. This results in a new node being created with the path of an existing node which in turn removes the existing node and its children from the tree. The children are however not loaded from the file system again because of this check:
arborist/lib/arborist/load-actual.js
Lines 353 to 357 in 02f295f
The end result is an unmet dependency and npm attempting to fetch it from the registry instead of using the bundled dependency.
I've changed the cache key by normalizing the path to avoid replacing existing nodes. I've setup a minimal test case where the difference in behavior (with and without normalization) shows up as an error on the outgoing edge of a node.
References
Fixes npm/cli#2757