Skip to content

fix: handle scoped package names in array dependencies - #268

Open
afonsojanu wants to merge 1 commit into
npm:mainfrom
afonsojanu:fix/array-deps-scoped-package-name
Open

afonsojanu wants to merge 1 commit into
npm:mainfrom
afonsojanu:fix/array-deps-scoped-package-name

Conversation

@afonsojanu

Copy link
Copy Markdown

Fixes #105.

depObjectify (used when dependencies/devDependencies/optionalDependencies is 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 the 400 error 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:

normalize({ name: 'x', version: '1.0.0', dependencies: ['@babel/core@^7.0.0', 'lodash@^4.17.0'] }, warn)
// before: { '': 'babel/core@^7.0.0', lodash: '^4.17.0' }
// after:  { '@babel/core': '^7.0.0', lodash: '^4.17.0' }

Added a test covering this in test/dependencies.js. Full suite (69 tests) and lint both pass.

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.
@afonsojanu
afonsojanu requested a review from a team as a code owner September 7, 2026 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Array dependencies can't handle scoped packages

1 participant