Skip to content

Commit acca570

Browse files
committed
fix: use custom sort-package-json to put keywords in the end
1 parent 047d6b2 commit acca570

File tree

4 files changed

+58
-18
lines changed

4 files changed

+58
-18
lines changed

package.json

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
{
22
"name": "prettier-config-atomic",
3-
"main": "./prettier.config.js",
43
"version": "2.0.6",
5-
"files": [
6-
"prettier.config.js"
7-
],
8-
"author": "Amin Yahyaabadi",
94
"description": "The Prettier configuration used in atom-community",
10-
"keywords": [
11-
"prettier",
12-
"prettier-config",
13-
"prettier-preset",
14-
"format",
15-
"beautify"
16-
],
175
"repository": "https://github.com/atom-community/prettier-config-atomic",
186
"license": "MIT",
7+
"author": "Amin Yahyaabadi",
8+
"main": "./prettier.config.js",
9+
"files": [
10+
"prettier.config.js"
11+
],
1912
"scripts": {
13+
"bump": "ncu -u",
2014
"format": "prettier --write .",
21-
"test.format": "prettier . --check",
2215
"lint": "eslint . --fix",
23-
"test.lint": "eslint .",
24-
"bump": "ncu -u"
16+
"test.format": "prettier . --check",
17+
"test.lint": "eslint ."
2518
},
2619
"dependencies": {
2720
"prettier": "^2.4.1",
2821
"prettier-plugin-jsdoc": "^0.3.24",
29-
"prettier-plugin-packagejson": "^2.2.13"
22+
"prettier-plugin-packagejson": "^2.2.13",
23+
"sort-package-json": "github:aminya/sort-package-json"
3024
},
3125
"devDependencies": {
3226
"eslint": "^7.32.0",
3327
"eslint-config-atomic": "^1.16.3"
34-
}
28+
},
29+
"keywords": [
30+
"prettier",
31+
"prettier-config",
32+
"prettier-preset",
33+
"format",
34+
"beautify"
35+
]
3536
}

pnpm-lock.yaml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prettier-plugin-packagejson.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Modified from https://github.com/matzkoh/prettier-plugin-packagejson to use the custom sort-package.json package
2+
function requireSafe(path) {
3+
try {
4+
return require(path)
5+
} catch (error) {}
6+
}
7+
8+
const { parsers } = requireSafe("prettier/parser-babel") || requireSafe("prettier/parser-babylon")
9+
const sortPackageJson = require("sort-package-json")
10+
const parser = parsers["json-stringify"]
11+
12+
exports.parsers = {
13+
"json-stringify": {
14+
...parser,
15+
preprocess(text, options) {
16+
if (parser.preprocess) {
17+
text = parser.preprocess(text, options)
18+
}
19+
20+
return options.filepath && /(^|\\|\/)package\.json$/.test(options.filepath) ? sortPackageJson(text) : text
21+
},
22+
},
23+
}

prettier.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
plugins: ["prettier-plugin-jsdoc", "prettier-plugin-packagejson"],
2+
plugins: ["prettier-plugin-jsdoc", require("./prettier-plugin-packagejson.js")],
33
tabWidth: 2,
44
printWidth: 120,
55
semi: false,

0 commit comments

Comments
 (0)