From 59d53b3ea2f66c7d35250b278b3ada551cef8741 Mon Sep 17 00:00:00 2001 From: milaninfy <111582375+milaninfy@users.noreply.github.com> Date: Mon, 22 Jul 2024 10:58:10 -0400 Subject: [PATCH] fix: throws an err when alias is without name (#184) throws error when alias spec is without name. e.g. ( foo@npm: ) Fixes: https://github.com/npm/cli/issues/7590 --- 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')