Skip to content

Commit

Permalink
fix: throws an err when alias is without name (#184)
Browse files Browse the repository at this point in the history
throws error when alias spec is without name. e.g. ( foo@npm: )
Fixes: npm/cli#7590
  • Loading branch information
milaninfy committed Jul 22, 2024
1 parent 74d06ae commit 59d53b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/npa.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ function fromAlias (res, where) {
throw new Error('aliases only work for registry deps')
}

if (!subSpec.name) {
throw new Error('aliases must have a name')
}

res.subSpec = subSpec
res.registry = true
res.type = 'alias'
Expand Down
4 changes: 4 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,10 @@ t.test('basic', function (t) {
npa('foo@npm:bar@npm:baz')
}, 'nested aliases not supported')

t.throws(() => {
npa('foo@npm:')
}, 'aliases must have a name')

t.throws(() => {
npa('foo@npm:foo/bar')
}, 'aliases only work for registry deps')
Expand Down

0 comments on commit 59d53b3

Please sign in to comment.