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
6 changes: 6 additions & 0 deletions lib/fixer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('')
Expand Down
19 changes: 19 additions & 0 deletions test/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down