From ec039aa33d1c8d7062ce61e61e49a84f4340740a Mon Sep 17 00:00:00 2001 From: vhinayindia Date: Tue, 6 Oct 2026 19:15:07 +0530 Subject: [PATCH] fix: preserve scoped package names in array dependencies --- lib/fixer.js | 11 ++++++++++- test/dependencies.js | 11 +++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/fixer.js b/lib/fixer.js index 0b8defa..340c9c2 100644 --- a/lib/fixer.js +++ b/lib/fixer.js @@ -445,8 +445,17 @@ function depObjectify (deps, type, warn) { deps.filter(function (d) { return typeof d === 'string' }).forEach(function (d) { + var prefix = '' + d = d.trim() + if (d.charAt(0) === '@') { + var slash = d.indexOf('/') + if (slash !== -1) { + prefix = d.slice(0, slash + 1) + d = d.slice(slash + 1) + } + } d = d.trim().split(/(:?[@\s><=])/) - var dn = d.shift() + var dn = prefix + d.shift() var dv = d.join('') dv = dv.trim() dv = dv.replace(/^@/, '') diff --git a/test/dependencies.js b/test/dependencies.js index 7e232d4..16e7a3f 100644 --- a/test/dependencies.js +++ b/test/dependencies.js @@ -110,6 +110,17 @@ test('warn if dependencies is not an object', function () { ) }) +test('preserve scoped package names in array dependencies', function () { + var data = { + dependencies: ['@scope/pkg@^1.2.3', '@scope/without-version'], + } + normalize(data) + assert.deepStrictEqual(data.dependencies, { + '@scope/pkg': '^1.2.3', + '@scope/without-version': '', + }) +}) + test('safeFormat throws TypeError on falsy argument', function () { assert.throws( () => safeFormat(null),