diff --git a/lib/fixer.js b/lib/fixer.js index 0b8defa..95b64be 100644 --- a/lib/fixer.js +++ b/lib/fixer.js @@ -445,11 +445,21 @@ function depObjectify (deps, type, warn) { deps.filter(function (d) { return typeof d === 'string' }).forEach(function (d) { - d = d.trim().split(/(:?[@\s><=])/) + d = d.trim() + // a leading @ marks a scoped package name (e.g. "@babel/core@^7.0.0"), + // not the start of a version range, so don't split on it + var scoped = d.charAt(0) === '@' + if (scoped) { + d = d.slice(1) + } + d = d.split(/(:?[@\s><=])/) var dn = d.shift() var dv = d.join('') dv = dv.trim() dv = dv.replace(/^@/, '') + if (scoped) { + dn = '@' + dn + } o[dn] = dv }) return o diff --git a/test/dependencies.js b/test/dependencies.js index 7e232d4..bfa1340 100644 --- a/test/dependencies.js +++ b/test/dependencies.js @@ -110,6 +110,23 @@ test('warn if dependencies is not an object', function () { ) }) +test('array dependencies handle scoped package names', function () { + var warnings = [] + function warn (w) { + warnings.push(w) + } + var data = { + name: 'test-package', + version: '1.0.0', + dependencies: ['@babel/core@^7.0.0', 'lodash@^4.17.0'], + } + normalize(data, warn) + assert.deepStrictEqual(data.dependencies, { + '@babel/core': '^7.0.0', + lodash: '^4.17.0', + }) +}) + test('safeFormat throws TypeError on falsy argument', function () { assert.throws( () => safeFormat(null),