@@ -9,6 +9,21 @@ of semver range (e.g. `^`). There are several options for specifying which depen
9
9
a range type restriction should be applied to, including dependency type,
10
10
package name (or name regex pattern), and version range (e.g. '<1').
11
11
12
+ ``` ts
13
+ export default [
14
+ {
15
+ " package-json/restrict-dependency-ranges" : [
16
+ " error" ,
17
+ // Require that packages with 0.x.x versions are pinned
18
+ {
19
+ forVersions: " <1" ,
20
+ rangeType: " pin" ,
21
+ },
22
+ ],
23
+ },
24
+ ];
25
+ ```
26
+
12
27
If you provide multiple options and a dependency matches more than one of the
13
28
options, the last option that matches will take precedent for that dependency.
14
29
This allows you to define more general rules that apply to all dependencies (or large
@@ -23,8 +38,8 @@ or focus on some subset of dependencies.
23
38
| Name | Type | Required |
24
39
| :------------------- | :----------------------- | :------- |
25
40
| ` forDependencyTypes ` | DependencyType[ ] | |
26
- | ` forPackages ` | String [ ] | |
27
- | ` forVersions ` | String | |
41
+ | ` forPackages ` | string [ ] | |
42
+ | ` forVersions ` | string | |
28
43
| ` rangeType ` | RangeType \| RangeType[ ] | Yes |
29
44
30
45
You can provide a single options object consisting of the above, or an array
@@ -42,23 +57,81 @@ Options are
42
57
- optionalDependencies
43
58
- peerDependencies
44
59
60
+ ``` ts
61
+ export default [
62
+ {
63
+ " package-json/restrict-dependency-ranges" : [
64
+ " error" ,
65
+ // Require that all dev dependencies are pinned
66
+ {
67
+ forDependencyTypes: [" devDependencies" ],
68
+ rangeType: " pin" ,
69
+ },
70
+ ],
71
+ },
72
+ ];
73
+ ```
74
+
45
75
### ` forPackages `
46
76
47
77
This can be the exact name of a package, or a regex pattern used to match a
48
78
group of packages by name (e.g. ` @typescript-eslint/* ` ).
49
79
80
+ ``` ts
81
+ export default [
82
+ {
83
+ " package-json/restrict-dependency-ranges" : [
84
+ " error" ,
85
+ // Restrict typescript to tilde ranges
86
+ {
87
+ forPackages: " typescript" ,
88
+ rangeType: " tilde" ,
89
+ },
90
+ ],
91
+ },
92
+ ];
93
+ ```
94
+
50
95
### ` forVersions `
51
96
52
97
You can use this to apply a restriction to a specific semver range. For example,
53
98
a common use case is to pin "unstable" dependencies (packages that have
54
99
a version in the ` 0.x.x ` range). You can do this by setting ` forVersions ` to ` '<1' ` .
55
100
101
+ ``` ts
102
+ export default [
103
+ {
104
+ " package-json/restrict-dependency-ranges" : [
105
+ " error" ,
106
+ // Require that all deps should use ^
107
+ {
108
+ rangeType: " caret" ,
109
+ },
110
+ ],
111
+ },
112
+ ];
113
+ ```
114
+
56
115
### ` rangeType `
57
116
58
117
This is the only required option, and identifies which range type or types you
59
118
want to apply to packages that match any of the other match options (or all
60
119
dependencies if no other options are provided).
61
120
121
+ ``` ts
122
+ export default [
123
+ {
124
+ " package-json/restrict-dependency-ranges" : [
125
+ " error" ,
126
+ // Require that all deps should use ^
127
+ {
128
+ rangeType: " caret" ,
129
+ },
130
+ ],
131
+ },
132
+ ];
133
+ ```
134
+
62
135
## Example
63
136
64
137
``` ts
@@ -78,7 +151,7 @@ export default [
78
151
rangeType: " tilde" ,
79
152
},
80
153
81
- // Require packages that have 0.x.x versions are pinned
154
+ // Require that packages with 0.x.x versions are pinned
82
155
{
83
156
forVersions: " <1" ,
84
157
rangeType: " pin" ,
0 commit comments