From bbbde02d41a5642c6e50261dd09ba8783a3215fe Mon Sep 17 00:00:00 2001 From: Milan Meva Date: Fri, 12 Jul 2024 13:41:26 -0400 Subject: [PATCH] fix: throws err on alias without name --- lib/npa.js | 4 ++++ test/basic.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/npa.js b/lib/npa.js index 6a3f07d..8094b3e 100644 --- a/lib/npa.js +++ b/lib/npa.js @@ -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' diff --git a/test/basic.js b/test/basic.js index 7553e7a..9cabdb4 100644 --- a/test/basic.js +++ b/test/basic.js @@ -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')