@@ -112,34 +112,46 @@ export const hasDepVersZero = (packageJsonData: PackageJson | any, nodeName: str
112
112
* @param {String } rangeSpecifier A version range specifier
113
113
* @return {Boolean } True if the version starts with the range, false if it doesn't.
114
114
*/
115
- export const doesVersStartsWithRange = ( dependencyVersion : string , rangeSpecifier : string ) : boolean => {
115
+ export const doesVersionStartWithRange = ( dependencyVersion : string , rangeSpecifier : string ) : boolean => {
116
116
const firstCharOfStr = 0 ;
117
117
118
118
return dependencyVersion . startsWith ( rangeSpecifier , firstCharOfStr ) ;
119
119
} ;
120
120
121
+ export interface AuditDependenciesForValidRangeResponse {
122
+ onlyValidVersionsDetected : boolean ;
123
+ dependenciesWithValidVersionRange : string [ ] ;
124
+ dependenciesWithoutValidVersionRange : string [ ] ;
125
+ }
126
+
121
127
/**
122
128
* Determines whether or not all dependency version ranges match expected range
123
- * @param { object } packageJsonData Valid JSON
124
- * @param { string } nodeName Name of a node in the package.json file
125
- * @param { string } rangeSpecifier A version range specifier
126
- * @param { object } config Rule configuration
127
- * @return { boolean } False if the package has an invalid range. True if it is not or the node is missing.
129
+ * @param packageJsonData Valid JSON
130
+ * @param nodeName Name of a node in the package.json file
131
+ * @param rangeSpecifier A version range specifier
132
+ * @param config Rule configuration
133
+ * @return False if the package has an invalid range. True if it is not or the node is missing.
128
134
*/
129
- export const areVersRangesValid = (
135
+ export const auditDependenciesForValidRangeVersions = (
130
136
// eslint-disable-next-line @typescript-eslint/no-explicit-any
131
137
packageJsonData : PackageJson | any ,
132
138
nodeName : string ,
133
139
rangeSpecifier : string ,
134
140
// eslint-disable-next-line @typescript-eslint/no-explicit-any
135
141
config : any
136
- ) : boolean => {
142
+ ) : AuditDependenciesForValidRangeResponse => {
143
+ let onlyValidVersionsDetected = true ;
144
+ const dependenciesWithValidVersionRange = [ ] ;
145
+ const dependenciesWithoutValidVersionRange = [ ] ;
146
+
137
147
if ( ! packageJsonData . hasOwnProperty ( nodeName ) ) {
138
- return true ;
148
+ return {
149
+ onlyValidVersionsDetected,
150
+ dependenciesWithValidVersionRange : [ ] ,
151
+ dependenciesWithoutValidVersionRange : [ ] ,
152
+ } ;
139
153
}
140
154
141
- let rangesValid = true ;
142
-
143
155
// eslint-disable-next-line no-restricted-syntax
144
156
for ( const dependencyName in packageJsonData [ nodeName ] ) {
145
157
if ( hasExceptions ( config ) && config . exceptions . includes ( dependencyName ) ) {
@@ -149,12 +161,19 @@ export const areVersRangesValid = (
149
161
150
162
const dependencyVersion = packageJsonData [ nodeName ] [ dependencyName ] ;
151
163
152
- if ( ! doesVersStartsWithRange ( dependencyVersion , rangeSpecifier ) ) {
153
- rangesValid = false ;
164
+ if ( doesVersionStartWithRange ( dependencyVersion , rangeSpecifier ) ) {
165
+ dependenciesWithValidVersionRange . push ( dependencyName ) ;
166
+ } else {
167
+ onlyValidVersionsDetected = false ;
168
+ dependenciesWithoutValidVersionRange . push ( dependencyName ) ;
154
169
}
155
170
}
156
171
157
- return rangesValid ;
172
+ return {
173
+ onlyValidVersionsDetected,
174
+ dependenciesWithValidVersionRange,
175
+ dependenciesWithoutValidVersionRange,
176
+ } ;
158
177
} ;
159
178
160
179
export interface AuditDependenciesForInvalidRangeResponse {
@@ -200,7 +219,7 @@ export const auditDependenciesForInvalidRange = (
200
219
201
220
const dependencyVersion = packageJsonData [ nodeName ] [ dependencyName ] ;
202
221
203
- if ( doesVersStartsWithRange ( dependencyVersion , rangeSpecifier ) ) {
222
+ if ( doesVersionStartWithRange ( dependencyVersion , rangeSpecifier ) ) {
204
223
hasInvalidRangeVersions = true ;
205
224
dependenciesWithInvalidVersionRange . push ( dependencyName ) ;
206
225
} else {
0 commit comments