Skip to content

Commit

Permalink
fix: unique bundledDependencies like fields (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored and keithamus committed Jan 8, 2020
1 parent 466b55d commit d02d8ef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const pipe = fns => x => fns.reduce((result, fn) => fn(result), x)
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 uniqAndSortArray = pipe([uniq, sortArray])
const isPlainObject = x =>
x && Object.prototype.toString.call(x) === '[object Object]'
const onObject = fn => x => (isPlainObject(x) ? fn(x) : x)
Expand Down Expand Up @@ -203,10 +204,10 @@ const fields = [
{ key: 'devDependencies', over: sortObject },
{ key: 'peerDependencies', over: sortObject },
{ key: 'optionalDependencies', over: sortObject },
{ key: 'bundledDependencies', over: sortArray },
{ key: 'bundleDependencies', over: sortArray },
/* vscode */ { key: 'extensionPack', over: sortArray },
/* vscode */ { key: 'extensionDependencies', over: sortArray },
{ key: 'bundledDependencies', over: uniqAndSortArray },
{ key: 'bundleDependencies', over: uniqAndSortArray },
/* vscode */ { key: 'extensionPack', over: uniqAndSortArray },
/* vscode */ { key: 'extensionDependencies', over: uniqAndSortArray },
{ key: 'flat' },
{ key: 'engines', over: sortObject },
{ key: 'engineStrict', over: sortObject },
Expand Down
3 changes: 2 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,9 @@ for (const field of [
]) {
testField(field, [
{
value: ['z', 'a'],
value: ['z', 'a', 'a'],
expect: ['a', 'z'],
message: `Should sort and unique array type of ${field} field.`,
},
// should ignore object
{
Expand Down

0 comments on commit d02d8ef

Please sign in to comment.