@jpp-toolkit/prettier-plugin-packagejson 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.mjs +26 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +58 -0
- package/src/index.ts +35 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Julien Papini
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Plugin } from "prettier";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
declare const testPath: (path: string) => boolean;
|
|
5
|
+
declare const parsers: Plugin['parsers'];
|
|
6
|
+
declare const options: Plugin['options'];
|
|
7
|
+
//#endregion
|
|
8
|
+
export { options, parsers, testPath };
|
|
9
|
+
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { sortPackageJson } from "@jpp-toolkit/sort-package-json";
|
|
2
|
+
import babelParsers from "prettier/parser-babel";
|
|
3
|
+
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
const parser = babelParsers.parsers["json-stringify"];
|
|
6
|
+
const testPath = (path) => /(?:^|\\|\/)package\.json$/u.test(path);
|
|
7
|
+
const parsers = { "json-stringify": {
|
|
8
|
+
...parser,
|
|
9
|
+
preprocess: async (text, options$1) => {
|
|
10
|
+
const packageSortOrder = options$1["packageSortOrder"];
|
|
11
|
+
const preprocessedText = await parser.preprocess?.(text, options$1) ?? text;
|
|
12
|
+
const sortPackageJsonOptions = Array.isArray(packageSortOrder) && packageSortOrder.length !== 0 ? { sortOrder: packageSortOrder } : void 0;
|
|
13
|
+
return testPath(options$1.filepath) ? sortPackageJson(preprocessedText, sortPackageJsonOptions) : preprocessedText;
|
|
14
|
+
}
|
|
15
|
+
} };
|
|
16
|
+
const options = { packageSortOrder: {
|
|
17
|
+
category: "Global",
|
|
18
|
+
type: "string",
|
|
19
|
+
array: true,
|
|
20
|
+
default: [{ value: [] }],
|
|
21
|
+
description: "Custom ordering array"
|
|
22
|
+
} };
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { options, parsers, testPath };
|
|
26
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["parsers: Plugin['parsers']","options","options: Plugin['options']"],"sources":["../src/index.ts"],"sourcesContent":["import { sortPackageJson } from '@jpp-toolkit/sort-package-json';\nimport type { Plugin } from 'prettier';\n// eslint-disable-next-line import-x/default\nimport babelParsers from 'prettier/parser-babel';\n\nconst parser = babelParsers.parsers['json-stringify'];\n\nexport const testPath = (path: string): boolean => /(?:^|\\\\|\\/)package\\.json$/u.test(path);\n\nexport const parsers: Plugin['parsers'] = {\n 'json-stringify': {\n ...parser,\n preprocess: async (text, options) => {\n const packageSortOrder = options['packageSortOrder'] as string[] | undefined;\n const preprocessedText = (await parser.preprocess?.(text, options)) ?? text;\n const sortPackageJsonOptions =\n Array.isArray(packageSortOrder) && packageSortOrder.length !== 0 ?\n { sortOrder: packageSortOrder }\n : undefined;\n return testPath(options.filepath) ?\n sortPackageJson(preprocessedText, sortPackageJsonOptions)\n : preprocessedText;\n },\n },\n};\n\nexport const options: Plugin['options'] = {\n packageSortOrder: {\n category: 'Global',\n type: 'string',\n array: true,\n default: [{ value: [] }],\n description: 'Custom ordering array',\n },\n};\n"],"mappings":";;;;AAKA,MAAM,SAAS,aAAa,QAAQ;AAEpC,MAAa,YAAY,SAA0B,6BAA6B,KAAK,KAAK;AAE1F,MAAaA,UAA6B,EACtC,kBAAkB;CACd,GAAG;CACH,YAAY,OAAO,MAAM,cAAY;EACjC,MAAM,mBAAmBC,UAAQ;EACjC,MAAM,mBAAoB,MAAM,OAAO,aAAa,MAAMA,UAAQ,IAAK;EACvE,MAAM,yBACF,MAAM,QAAQ,iBAAiB,IAAI,iBAAiB,WAAW,IAC3D,EAAE,WAAW,kBAAkB,GAC/B;AACR,SAAO,SAASA,UAAQ,SAAS,GACzB,gBAAgB,kBAAkB,uBAAuB,GACzD;;CAEf,EACJ;AAED,MAAaC,UAA6B,EACtC,kBAAkB;CACd,UAAU;CACV,MAAM;CACN,OAAO;CACP,SAAS,CAAC,EAAE,OAAO,EAAE,EAAE,CAAC;CACxB,aAAa;CAChB,EACJ"}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jpp-toolkit/prettier-plugin-packagejson",
|
|
3
|
+
"version": "0.0.11",
|
|
4
|
+
"description": "Prettier plugin for formatting package.json files.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"jpp",
|
|
7
|
+
"prettier",
|
|
8
|
+
"plugin",
|
|
9
|
+
"packagejson"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/jpapini/jpp-toolkit/tree/main/packages/prettier-plugin-packagejson#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/jpapini/jpp-toolkit/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/jpapini/jpp-toolkit.git",
|
|
18
|
+
"directory": "packages/prettier-plugin-packagejson"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"author": "Julien Papini <julien.papini@gmail.com> (https://github.com/jpapini)",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.mts",
|
|
26
|
+
"default": "./dist/index.mjs"
|
|
27
|
+
},
|
|
28
|
+
"./package.json": "./package.json"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"src"
|
|
33
|
+
],
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@jpp-toolkit/sort-package-json": "0.0.11"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"prettier": "3.7.4"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"prettier": "3"
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": "24",
|
|
45
|
+
"pnpm": "10"
|
|
46
|
+
},
|
|
47
|
+
"volta": {
|
|
48
|
+
"extends": "../../package.json"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"typecheck": "tsc --noEmit --pretty",
|
|
55
|
+
"dev": "build-lib --watch",
|
|
56
|
+
"build": "build-lib"
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { sortPackageJson } from '@jpp-toolkit/sort-package-json';
|
|
2
|
+
import type { Plugin } from 'prettier';
|
|
3
|
+
// eslint-disable-next-line import-x/default
|
|
4
|
+
import babelParsers from 'prettier/parser-babel';
|
|
5
|
+
|
|
6
|
+
const parser = babelParsers.parsers['json-stringify'];
|
|
7
|
+
|
|
8
|
+
export const testPath = (path: string): boolean => /(?:^|\\|\/)package\.json$/u.test(path);
|
|
9
|
+
|
|
10
|
+
export const parsers: Plugin['parsers'] = {
|
|
11
|
+
'json-stringify': {
|
|
12
|
+
...parser,
|
|
13
|
+
preprocess: async (text, options) => {
|
|
14
|
+
const packageSortOrder = options['packageSortOrder'] as string[] | undefined;
|
|
15
|
+
const preprocessedText = (await parser.preprocess?.(text, options)) ?? text;
|
|
16
|
+
const sortPackageJsonOptions =
|
|
17
|
+
Array.isArray(packageSortOrder) && packageSortOrder.length !== 0 ?
|
|
18
|
+
{ sortOrder: packageSortOrder }
|
|
19
|
+
: undefined;
|
|
20
|
+
return testPath(options.filepath) ?
|
|
21
|
+
sortPackageJson(preprocessedText, sortPackageJsonOptions)
|
|
22
|
+
: preprocessedText;
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const options: Plugin['options'] = {
|
|
28
|
+
packageSortOrder: {
|
|
29
|
+
category: 'Global',
|
|
30
|
+
type: 'string',
|
|
31
|
+
array: true,
|
|
32
|
+
default: [{ value: [] }],
|
|
33
|
+
description: 'Custom ordering array',
|
|
34
|
+
},
|
|
35
|
+
};
|