Skip to content

Commit 9ed6476

Browse files
committed
fix: inline the plugin into a function
It seems prettier has a bug for resolving files
1 parent 7ed2375 commit 9ed6476

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

prettier-plugin-packagejson.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

prettier.config.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
1+
function prettier_plugin_packagejson() {
2+
// Modified from https://github.com/matzkoh/prettier-plugin-packagejson to use the custom sort-package.json package
3+
function requireSafe(path) {
4+
try {
5+
return require(path)
6+
} catch (error) {}
7+
}
8+
9+
const { parsers } = requireSafe("prettier/parser-babel") || requireSafe("prettier/parser-babylon")
10+
const sortPackageJson = require("sort-package-json")
11+
const parser = parsers["json-stringify"]
12+
13+
return {
14+
parsers: {
15+
"json-stringify": {
16+
...parser,
17+
preprocess(text, options) {
18+
if (parser.preprocess) {
19+
text = parser.preprocess(text, options)
20+
}
21+
22+
return options.filepath && /(^|\\|\/)package\.json$/.test(options.filepath) ? sortPackageJson(text) : text
23+
},
24+
},
25+
},
26+
}
27+
}
28+
129
module.exports = {
2-
plugins: ["prettier-plugin-jsdoc", require("./prettier-plugin-packagejson.js")],
30+
plugins: ["prettier-plugin-jsdoc", prettier_plugin_packagejson()],
331
tabWidth: 2,
432
printWidth: 120,
533
semi: false,

0 commit comments

Comments
 (0)