Skip to content

Commit b4de01d

Browse files
fiskerkeithamus
authored andcommittedDec 28, 2019
fix: add contributors field back (#106)
* feat: add `contributors` field * style: use `sortPeopleObject` directly
1 parent b3f20ba commit b4de01d

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed
 

‎index.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const onObject = fn => x => (isPlainObject(x) ? fn(x) : x)
1212
const sortObjectBy = comparator => onObject(x => sortObjectKeys(x, comparator))
1313
const sortObject = sortObjectBy()
1414
const sortURLObject = sortObjectBy(['type', 'url'])
15-
const sortAuthorObject = sortObjectBy(['name', 'email', 'url'])
15+
const sortPeopleObject = sortObjectBy(['name', 'email', 'url'])
1616
const sortDirectories = sortObjectBy(['lib', 'bin', 'man', 'doc', 'example'])
1717

1818
// See https://docs.npmjs.com/misc/scripts
@@ -69,7 +69,11 @@ const fields = [
6969
{ key: 'repository', over: sortURLObject },
7070
{ key: 'funding', over: sortURLObject },
7171
{ key: 'license', over: sortURLObject },
72-
{ key: 'author', over: sortAuthorObject },
72+
{ key: 'author', over: sortPeopleObject },
73+
{
74+
key: 'contributors',
75+
over: onArray(contributors => contributors.map(sortPeopleObject)),
76+
},
7377
{ key: 'files', over: uniq },
7478
{ key: 'sideEffects' },
7579
{ key: 'type' },

‎test.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ for (const field of [
199199
'name',
200200
'version',
201201
'description',
202-
'contributors',
203202
'sideEffects',
204203
'files',
205204
'keywords',
@@ -345,6 +344,29 @@ testField('author', [
345344
},
346345
])
347346

347+
// contributors
348+
assert.deepStrictEqual(
349+
Object.keys(
350+
sortPackageJson({
351+
contributors: [
352+
{
353+
[UNKNOWN]: UNKNOWN,
354+
url: 'http://keithcirkel.co.uk/',
355+
name: 'Keith Cirkel',
356+
email: 'npm@keithcirkel.co.uk',
357+
},
358+
],
359+
}).contributors[0],
360+
),
361+
['name', 'email', 'url', UNKNOWN],
362+
)
363+
assert.deepStrictEqual(
364+
sortPackageJson({
365+
contributors: ['foo', 'bar', ['foo', 'bar']],
366+
}).contributors,
367+
['foo', 'bar', ['foo', 'bar']],
368+
)
369+
348370
testField('directories', [
349371
{
350372
value: {

0 commit comments

Comments
 (0)
Please sign in to comment.