fix: handle scoped package names in array dependencies - #268
Open
afonsojanu wants to merge 1 commit into
Open
afonsojanu wants to merge 1 commit into
afonsojanu wants to merge 1 commit into
Conversation
depObjectify splits each array-dependency string on the first occurrence of @, whitespace, >, <, or =, treating whatever comes before as the name and the rest as the version range. For a scoped package like "@babel/core@^7.0.0" the leading @ that marks the scope gets treated as that same separator, so the parsed name ends up empty and the version range ends up being "babel/core@^7.0.0" instead. Now a leading @ is stripped before splitting and re-added to the parsed name afterward, so it's no longer confused with the @ that separates a name from its version. Fixes npm#105.
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.
Fixes #105.
depObjectify(used whendependencies/devDependencies/optionalDependenciesis given as an array of strings instead of an object) splits each entry on the first@, whitespace,>,<, or=, treating whatever comes before as the package name and the rest as the version range.For a scoped package like
"@babel/core@^7.0.0", the leading@that marks the scope gets picked up by that same split, so the parsed name ends up being an empty string and the version range ends up as"babel/core@^7.0.0"(the actual version got lost inside it). That matches exactly what's in the issue's screenshot and the400error from the registry.Fix: strip a leading
@before splitting (so it isn't mistaken for the name/version separator), then add it back to the parsed name afterward. Verified against the exact case from the issue:Added a test covering this in
test/dependencies.js. Full suite (69 tests) and lint both pass.