Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/fixer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions test/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down