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 10
10
*/
11
11
const { parsers } = require ( 'prettier/parser-babylon' ) ;
12
12
13
+ const { dependencies } = require ( './rules/dependencies' ) ;
13
14
const { engines } = require ( './rules/engines' ) ;
14
15
const { files } = require ( './rules/files' ) ;
15
16
const { scripts } = require ( './rules/scripts' ) ;
@@ -24,6 +25,7 @@ const format = (properties) => {
24
25
props = engines ( props ) ;
25
26
props = files ( props ) ;
26
27
props = scripts ( props ) ;
28
+ props = dependencies ( props ) ;
27
29
28
30
return props ;
29
31
} ;
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 38
38
" prettier"
39
39
],
40
40
"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"
42
49
},
43
50
"typings" : " dist/index.d.ts" ,
44
51
"dependencies" : {},
45
52
"devDependencies" : {
46
- "@commitlint/cli" : " ^8.1.0" ,
47
53
"@commitlint/config-conventional" : " ^8.1.0" ,
54
+ "lint-staged" : " ^9.2.0" ,
48
55
"ava" : " ^2.2.0" ,
49
56
"eslint-config-shellscape" : " ^2.0.2" ,
50
57
"execa" : " ^2.0.3" ,
51
- "lint-staged" : " ^9.2.0" ,
52
58
"nyc" : " ^14.1.0" ,
59
+ "@commitlint/cli" : " ^8.1.0" ,
53
60
"pre-commit" : " ^1.2.2" ,
54
61
"prettier" : " ^1.18.2"
55
62
},
Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ Generated by [AVA](https://ava.li).
48
48
"prettier"␊
49
49
],␊
50
50
"peerDependencies": {␊
51
+ "eslint-config-shellscape": "^2.0.2",␊
51
52
"prettier": "^1.18.2"␊
52
53
},␊
53
54
"dependencies": {},␊
@@ -130,6 +131,7 @@ Generated by [AVA](https://ava.li).
130
131
"prettier"␊
131
132
],␊
132
133
"peerDependencies": {␊
134
+ "eslint-config-shellscape": "^2.0.2",␊
133
135
"prettier": "^1.18.2"␊
134
136
},␊
135
137
"dependencies": {},␊
You can’t perform that action at this time.
0 commit comments