Skip to content

Commit

Permalink
fix: sort bundledDependencies as array (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored and keithamus committed Dec 30, 2019
1 parent b4de01d commit 0606961
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const globby = require('globby')

const onArray = fn => x => (Array.isArray(x) ? fn(x) : x)
const uniq = onArray(xs => xs.filter((x, i) => i === xs.indexOf(x)))
const sortArray = onArray(array => [...array].sort())
const isPlainObject = x =>
x && Object.prototype.toString.call(x) === '[object Object]'
const onObject = fn => x => (isPlainObject(x) ? fn(x) : x)
Expand Down Expand Up @@ -130,8 +131,8 @@ const fields = [
{ key: 'dependencies', over: sortObject },
{ key: 'devDependencies', over: sortObject },
{ key: 'peerDependencies', over: sortObject },
{ key: 'bundledDependencies', over: sortObject },
{ key: 'bundleDependencies', over: sortObject },
{ key: 'bundledDependencies', over: sortArray },
{ key: 'bundleDependencies', over: sortArray },
{ key: 'optionalDependencies', over: sortObject },
{ key: 'flat' },
{ key: 'resolutions', over: sortObject },
Expand Down
32 changes: 27 additions & 5 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,17 +456,39 @@ for (const field of [
'dependencies',
'devDependencies',
'peerDependencies',
'bundledDependencies',
'bundleDependencies',
'optionalDependencies',
]) {
testField(field, [
{
value: {
'sort-object-keys': '^1.1.2',
glob: '^7.1.6',
z: '2.0.0',
a: '1.0.0',
},
expect: ['glob', 'sort-object-keys'],
expect: ['a', 'z'],
},
{
value: ['z', 'a'],
expect: ['z', 'a'],
message: `Should not sort array type of ${field} field.`,
},
])
}

// bundledDependencies
for (const field of ['bundledDependencies', 'bundleDependencies']) {
testField(field, [
{
value: ['z', 'a'],
expect: ['a', 'z'],
},
// should ignore object
{
value: {
z: '2.0.0',
a: '1.0.0',
},
expect: ['z', 'a'],
message: `Should not sort object type of ${field} field.`,
},
])
}
Expand Down

0 comments on commit 0606961

Please sign in to comment.