File tree Expand file tree Collapse file tree 6 files changed +120
-3
lines changed Expand file tree Collapse file tree 6 files changed +120
-3
lines changed Original file line number Diff line number Diff line change 1010*/
1111const { parsers } = require ( 'prettier/parser-babylon' ) ;
1212
13+ const { dependencies } = require ( './rules/dependencies' ) ;
1314const { engines } = require ( './rules/engines' ) ;
1415const { files } = require ( './rules/files' ) ;
1516const { scripts } = require ( './rules/scripts' ) ;
@@ -24,6 +25,7 @@ const format = (properties) => {
2425 props = engines ( props ) ;
2526 props = files ( props ) ;
2627 props = scripts ( props ) ;
28+ props = dependencies ( props ) ;
2729
2830 return props ;
2931} ;
Original file line number Diff line number Diff line change 1+ /*
2+ Copyright © 2019 Andrew Powell
3+
4+ This Source Code Form is subject to the terms of the Mozilla Public
5+ License, v. 2.0. If a copy of the MPL was not distributed with this
6+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
7+
8+ The above copyright notice and this permission notice shall be
9+ included in all copies or substantial portions of this Source Code Form.
10+ */
11+
12+ const dependencyNames = [
13+ // dependencies
14+ 'bundledDependencies' ,
15+ 'optionalDependencies' ,
16+ 'peerDependencies' ,
17+ 'dependencies' ,
18+ 'devDependencies' ,
19+ 'resolutions'
20+ ] ;
21+
22+ const process = ( props ) =>
23+ props . map ( ( prop ) => {
24+ if ( dependencyNames . includes ( prop . key . value ) ) {
25+ prop . value . properties . sort ( ( a , b ) =>
26+ a . key . value > b . key . value ? 1 : a . key . value < b . key . value ? - 1 : 0
27+ ) ;
28+ }
29+ return prop ;
30+ } ) ;
31+
32+ module . exports = { dependencies : process } ;
Original file line number Diff line number Diff line change 1+ /*
2+ Copyright © 2019 Andrew Powell
3+
4+ This Source Code Form is subject to the terms of the Mozilla Public
5+ License, v. 2.0. If a copy of the MPL was not distributed with this
6+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
7+
8+ The above copyright notice and this permission notice shall be
9+ included in all copies or substantial portions of this Source Code Form.
10+ */
11+ const primary = [
12+ // meta
13+ 'name' ,
14+ 'version' ,
15+ 'flat' ,
16+ 'private' ,
17+ 'publishConfig' ,
18+ 'description' ,
19+ 'license' ,
20+ 'repository' ,
21+ 'author' ,
22+ 'homepage' ,
23+ 'bugs' ,
24+
25+ // entry
26+ 'main' ,
27+ 'bin' ,
28+ 'module' ,
29+
30+ // constraints
31+ 'engines' ,
32+ 'cpu' ,
33+ 'os' ,
34+
35+ // content and util
36+ 'scripts' ,
37+ 'files' ,
38+ 'keywords' ,
39+
40+ // dependencies
41+ 'bundledDependencies' ,
42+ 'optionalDependencies' ,
43+ 'peerDependencies' ,
44+ 'dependencies' ,
45+ 'devDependencies' ,
46+ 'resolutions' ,
47+
48+ // types
49+ 'types' ,
50+ 'typings'
51+ ] ;
52+
53+ const sort = ( props ) => {
54+ const unknown = [ ] ;
55+ const known = props . filter ( ( prop ) => {
56+ if ( primary . includes ( prop . key . value ) ) {
57+ return true ;
58+ }
59+ unknown . push ( prop ) ;
60+ return false ;
61+ } ) ;
62+
63+ known . sort ( ( a , b ) => {
64+ const aIndex = primary . indexOf ( a . key . value ) ;
65+ const bIndex = primary . indexOf ( b . key . value ) ;
66+
67+ return aIndex > bIndex ? 1 : aIndex < bIndex ? - 1 : 0 ;
68+ } ) ;
69+ unknown . sort ( ( a , b ) => ( a . key . value > b . key . value ? 1 : a . key . value < b . key . value ? - 1 : 0 ) ) ;
70+
71+ return known . concat ( unknown ) ;
72+ } ;
73+
74+ module . exports = { sort } ;
Original file line number Diff line number Diff line change 3838 " prettier"
3939 ],
4040 "peerDependencies" : {
41- "prettier" : " ^1.18.2"
41+ "prettier" : " ^1.18.2" ,
42+ "eslint-config-shellscape" : " ^2.0.2"
43+ },
44+ "dependencies" : {
45+ "nyc" : " ^14.1.0" ,
46+ "eslint-config-shellscape" : " ^2.0.2" ,
47+ "ava" : " ^2.2.0" ,
48+ "execa" : " ^2.0.3"
4249 },
4350 "typings" : " dist/index.d.ts" ,
4451 "dependencies" : {},
4552 "devDependencies" : {
46- "@commitlint/cli" : " ^8.1.0" ,
4753 "@commitlint/config-conventional" : " ^8.1.0" ,
54+ "lint-staged" : " ^9.2.0" ,
4855 "ava" : " ^2.2.0" ,
4956 "eslint-config-shellscape" : " ^2.0.2" ,
5057 "execa" : " ^2.0.3" ,
51- "lint-staged" : " ^9.2.0" ,
5258 "nyc" : " ^14.1.0" ,
59+ "@commitlint/cli" : " ^8.1.0" ,
5360 "pre-commit" : " ^1.2.2" ,
5461 "prettier" : " ^1.18.2"
5562 },
Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ Generated by [AVA](https://ava.li).
4848 "prettier"␊
4949 ],␊
5050 "peerDependencies": {␊
51+ "eslint-config-shellscape": "^2.0.2",␊
5152 "prettier": "^1.18.2"␊
5253 },␊
5354 "dependencies": {},␊
@@ -130,6 +131,7 @@ Generated by [AVA](https://ava.li).
130131 "prettier"␊
131132 ],␊
132133 "peerDependencies": {␊
134+ "eslint-config-shellscape": "^2.0.2",␊
133135 "prettier": "^1.18.2"␊
134136 },␊
135137 "dependencies": {},␊
You can’t perform that action at this time.
0 commit comments