Skip to content

Commit

Permalink
feat: support Visual Studio Code extension manifest (#117)
Browse files Browse the repository at this point in the history
* feat: support `Visual Studio Code extension manifest`

* fix: `categories`

* fix: `qna`

* chore: typo in comment

* chore: mark `not decided`

* fix: sort all keys

* refactor: `sortProperty` -> `overProperty`
  • Loading branch information
fisker authored and keithamus committed Jan 7, 2020
1 parent 46b5a3c commit 75ee93a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
24 changes: 24 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const sortESLintConfig = sortObjectBy([
'noInlineConfig',
'reportUnusedDisableDirectives',
])
const sortVSCodeBadgeObject = sortObjectBy(['description', 'url', 'href'])

const sortPrettierConfigKeys = onObject(config =>
sortObjectKeys(config, [
Expand Down Expand Up @@ -107,24 +108,35 @@ const sortScripts = scripts => {
return sortObjectBy(order)(scripts)
}

// fields marked `vscode` are for `Visual Studio Code extension manifest` only
// https://code.visualstudio.com/api/references/extension-manifest
// Supported fields:
// publisher, displayName, categories, galleryBanner, preview, contributes,
// activationEvents, badges, markdown, qna, extensionPack,
// extensionDependencies, icon

// field.key{string}: field name
// field.over{function}: sort field subKey
const fields = [
{ key: 'name' },
/* vscode */ { key: 'displayName' },
{ key: 'version' },
{ key: 'private' },
{ key: 'description' },
/* vscode */ { key: 'categories', over: uniq },
{ key: 'keywords', over: uniq },
{ key: 'homepage' },
{ key: 'bugs', over: sortObjectBy(['url', 'email']) },
{ key: 'repository', over: sortURLObject },
{ key: 'funding', over: sortURLObject },
{ key: 'license', over: sortURLObject },
/* vscode */ { key: 'qna' },
{ key: 'author', over: sortPeopleObject },
{
key: 'contributors',
over: onArray(contributors => contributors.map(sortPeopleObject)),
},
/* vscode */ { key: 'publisher' },
{ key: 'files', over: uniq },
{ key: 'sideEffects' },
{ key: 'type' },
Expand Down Expand Up @@ -160,6 +172,8 @@ const fields = [
},
{ key: 'scripts', over: sortScripts },
{ key: 'betterScripts', over: sortScripts },
/* vscode */ { key: 'contributes', over: sortObject },
/* vscode */ { key: 'activationEvents', over: uniq },
{ key: 'husky', over: overProperty('hooks', sortGitHooks) },
{ key: 'pre-commit' },
{ key: 'commitlint', over: sortObject },
Expand All @@ -185,13 +199,23 @@ const fields = [
{ key: 'optionalDependencies', over: sortObject },
{ key: 'bundledDependencies', over: sortArray },
{ key: 'bundleDependencies', over: sortArray },
/* vscode */ { key: 'extensionPack', over: sortArray },
/* vscode */ { key: 'extensionDependencies', over: sortArray },
{ key: 'flat' },
{ key: 'engines', over: sortObject },
{ key: 'engineStrict', over: sortObject },
{ key: 'os' },
{ key: 'cpu' },
{ key: 'preferGlobal', over: sortObject },
{ key: 'publishConfig', over: sortObject },
/* vscode */ { key: 'icon' },
/* vscode */ {
key: 'badges',
over: onArray(badge => badge.map(sortVSCodeBadgeObject)),
},
/* vscode */ { key: 'galleryBanner', over: sortObject },
/* vscode */ { key: 'preview' },
/* vscode */ { key: 'markdown' },
]

const defaultSortOrder = fields.map(({ key }) => key)
Expand Down
40 changes: 39 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ assert.deepStrictEqual(
for (const field of [
'exports',
'bin',
'contributes',
'commitlint',
'lint-staged',
'config',
Expand All @@ -199,6 +200,7 @@ for (const field of [
'engineStrict',
'preferGlobal',
'publishConfig',
'galleryBanner',
]) {
testField(field, [
{
Expand All @@ -220,11 +222,15 @@ for (const field of [
// simple disabled subKey sorting test
for (const field of [
'name',
'displayName',
'version',
'description',
'sideEffects',
'files',
'categories',
'keywords',
'qna',
'publisher',
'type',
'main',
'umd:main',
Expand All @@ -242,13 +248,17 @@ for (const field of [
'assets',
'man',
'workspaces',
'activationEvents',
'pre-commit',
'browserslist',
'eslintIgnore',
'stylelint',
'flat',
'os',
'cpu',
'icon',
'preview',
'markdown',
]) {
testField(field, [
{
Expand Down Expand Up @@ -457,6 +467,29 @@ assert.deepStrictEqual(
['foo', 'bar', ['foo', 'bar']],
)

// badges
assert.deepStrictEqual(
Object.keys(
sortPackageJson({
badges: [
{
[UNKNOWN]: UNKNOWN,
href: 'https://travis-ci.com/keithamus/sort-package-json.svg',
url: 'https://travis-ci.com/keithamus/sort-package-json',
description: 'sort-package-json build status',
},
],
}).badges[0],
),
['description', 'url', 'href', UNKNOWN],
)
assert.deepStrictEqual(
sortPackageJson({
badges: ['foo', 'bar', ['foo', 'bar']],
}).badges,
['foo', 'bar', ['foo', 'bar']],
)

testField('directories', [
{
value: {
Expand Down Expand Up @@ -567,7 +600,12 @@ for (const field of [
}

// bundledDependencies
for (const field of ['bundledDependencies', 'bundleDependencies']) {
for (const field of [
'bundledDependencies',
'bundleDependencies',
'extensionPack',
'extensionDependencies',
]) {
testField(field, [
{
value: ['z', 'a'],
Expand Down

0 comments on commit 75ee93a

Please sign in to comment.