diff --git a/lib/fixer.js b/lib/fixer.js index 0b8defa..be817ab 100644 --- a/lib/fixer.js +++ b/lib/fixer.js @@ -445,6 +445,12 @@ function depObjectify (deps, type, warn) { deps.filter(function (d) { return typeof d === 'string' }).forEach(function (d) { + d = d.trim() + var scoped = d.match(/^(@[^/\s]+\/[^@/\s><=]+)(.*)$/) + if (scoped) { + o[scoped[1]] = scoped[2].trim().replace(/^@/, '') + return + } d = d.trim().split(/(:?[@\s><=])/) var dn = d.shift() var dv = d.join('') diff --git a/test/dependencies.js b/test/dependencies.js index 7e232d4..2f220a7 100644 --- a/test/dependencies.js +++ b/test/dependencies.js @@ -110,6 +110,25 @@ test('warn if dependencies is not an object', function () { ) }) +test('preserve scoped package names in array dependencies', function () { + var warnings = [] + var data = { + dependencies: ['@scope/pkg@^1.2.3'], + } + + normalize(data, function (warning) { + warnings.push(warning) + }) + + assert.deepStrictEqual(data.dependencies, { + '@scope/pkg': '^1.2.3', + }) + assert.ok( + warnings.includes(safeFormat(warningMessages.deprecatedArrayDependencies, 'dependencies')), + 'deprecation warning' + ) +}) + test('safeFormat throws TypeError on falsy argument', function () { assert.throws( () => safeFormat(null),