Skip to content

Commit

Permalink
fix: add contributors field back (#106)
Browse files Browse the repository at this point in the history
* feat: add `contributors` field

* style: use `sortPeopleObject` directly
  • Loading branch information
fisker authored and keithamus committed Dec 28, 2019
1 parent b3f20ba commit b4de01d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const onObject = fn => x => (isPlainObject(x) ? fn(x) : x)
const sortObjectBy = comparator => onObject(x => sortObjectKeys(x, comparator))
const sortObject = sortObjectBy()
const sortURLObject = sortObjectBy(['type', 'url'])
const sortAuthorObject = sortObjectBy(['name', 'email', 'url'])
const sortPeopleObject = sortObjectBy(['name', 'email', 'url'])
const sortDirectories = sortObjectBy(['lib', 'bin', 'man', 'doc', 'example'])

// See https://docs.npmjs.com/misc/scripts
Expand Down Expand Up @@ -69,7 +69,11 @@ const fields = [
{ key: 'repository', over: sortURLObject },
{ key: 'funding', over: sortURLObject },
{ key: 'license', over: sortURLObject },
{ key: 'author', over: sortAuthorObject },
{ key: 'author', over: sortPeopleObject },
{
key: 'contributors',
over: onArray(contributors => contributors.map(sortPeopleObject)),
},
{ key: 'files', over: uniq },
{ key: 'sideEffects' },
{ key: 'type' },
Expand Down
24 changes: 23 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ for (const field of [
'name',
'version',
'description',
'contributors',
'sideEffects',
'files',
'keywords',
Expand Down Expand Up @@ -345,6 +344,29 @@ testField('author', [
},
])

// contributors
assert.deepStrictEqual(
Object.keys(
sortPackageJson({
contributors: [
{
[UNKNOWN]: UNKNOWN,
url: 'http://keithcirkel.co.uk/',
name: 'Keith Cirkel',
email: '[email protected]',
},
],
}).contributors[0],
),
['name', 'email', 'url', UNKNOWN],
)
assert.deepStrictEqual(
sortPackageJson({
contributors: ['foo', 'bar', ['foo', 'bar']],
}).contributors,
['foo', 'bar', ['foo', 'bar']],
)

testField('directories', [
{
value: {
Expand Down

0 comments on commit b4de01d

Please sign in to comment.