This repository was archived by the owner on Jan 20, 2022. It is now read-only.
fix: _findMissingEdges missing dependency due to inconsistent path separators#363
Closed
fix: _findMissingEdges missing dependency due to inconsistent path separators#363
Conversation
Dependencies nested in node_modules triggers an issue with a file path used as a cache key in the _findMissingEdges function on Windows due to paths with mixed path separtors.
Normalize path to avoid mixed path separators on Windows causing a cache miss for paths that refer to the same thing. This would otherwise cause a new node with the path of an existing node to be created which in turns deletes the existing node and its children. However, the children will not be loaded again from the file system due to the _actualTreeLoaded check in _loadFSTree.
|
@salvadorj This repo is being archived as arborist is now maintained as a workspace in the CLI. I recreated this PR as npm/cli#4261, and the commits maintain you as the author. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
_findMissingEdgesmissing 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