Skip to content

Commit 0606961

Browse files
fiskerkeithamus
authored andcommittedDec 30, 2019
fix: sort bundledDependencies as array (#112)
1 parent b4de01d commit 0606961

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed
 

‎index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const globby = require('globby')
66

77
const onArray = fn => x => (Array.isArray(x) ? fn(x) : x)
88
const uniq = onArray(xs => xs.filter((x, i) => i === xs.indexOf(x)))
9+
const sortArray = onArray(array => [...array].sort())
910
const isPlainObject = x =>
1011
x && Object.prototype.toString.call(x) === '[object Object]'
1112
const onObject = fn => x => (isPlainObject(x) ? fn(x) : x)
@@ -130,8 +131,8 @@ const fields = [
130131
{ key: 'dependencies', over: sortObject },
131132
{ key: 'devDependencies', over: sortObject },
132133
{ key: 'peerDependencies', over: sortObject },
133-
{ key: 'bundledDependencies', over: sortObject },
134-
{ key: 'bundleDependencies', over: sortObject },
134+
{ key: 'bundledDependencies', over: sortArray },
135+
{ key: 'bundleDependencies', over: sortArray },
135136
{ key: 'optionalDependencies', over: sortObject },
136137
{ key: 'flat' },
137138
{ key: 'resolutions', over: sortObject },

‎test.js

+27-5
Original file line numberDiff line numberDiff line change
@@ -456,17 +456,39 @@ for (const field of [
456456
'dependencies',
457457
'devDependencies',
458458
'peerDependencies',
459-
'bundledDependencies',
460-
'bundleDependencies',
461459
'optionalDependencies',
462460
]) {
463461
testField(field, [
464462
{
465463
value: {
466-
'sort-object-keys': '^1.1.2',
467-
glob: '^7.1.6',
464+
z: '2.0.0',
465+
a: '1.0.0',
468466
},
469-
expect: ['glob', 'sort-object-keys'],
467+
expect: ['a', 'z'],
468+
},
469+
{
470+
value: ['z', 'a'],
471+
expect: ['z', 'a'],
472+
message: `Should not sort array type of ${field} field.`,
473+
},
474+
])
475+
}
476+
477+
// bundledDependencies
478+
for (const field of ['bundledDependencies', 'bundleDependencies']) {
479+
testField(field, [
480+
{
481+
value: ['z', 'a'],
482+
expect: ['a', 'z'],
483+
},
484+
// should ignore object
485+
{
486+
value: {
487+
z: '2.0.0',
488+
a: '1.0.0',
489+
},
490+
expect: ['z', 'a'],
491+
message: `Should not sort object type of ${field} field.`,
470492
},
471493
])
472494
}

0 commit comments

Comments
 (0)
Please sign in to comment.