@@ -7,54 +7,92 @@ const semver = require('semver');
7
7
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8
8
const hasExceptions = ( config : any ) : boolean => typeof config === 'object' && config . hasOwnProperty ( 'exceptions' ) ;
9
9
10
+ export interface AuditDependenciesWithRestrictedVersionResponse {
11
+ hasDependencyWithRestrictedVersion : boolean ;
12
+ dependenciesWithRestrictedVersion : string [ ] ;
13
+ dependenciesWithoutRestrictedVersion : string [ ] ;
14
+ }
15
+
10
16
/**
11
17
* Determines whether or not the package has a given dependency
12
- * @param { object } packageJsonData Valid JSON
13
- * @param { string } nodeName Name of a node in the package.json file
14
- * @param { string } depsToCheckFor An array of packages to check for
15
- * @return { boolean } True if the package has a dependency. False if it is not or the node is missing.
18
+ * @param packageJsonData Valid JSON
19
+ * @param nodeName Name of a node in the package.json file
20
+ * @param depsToCheckFor An array of packages to check for
21
+ * @return True if the package has a dependency. False if it is not or the node is missing.
16
22
*/
17
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
- export const hasDependency = ( packageJsonData : PackageJson | any , nodeName : string , depsToCheckFor : string [ ] ) : boolean => {
23
+ export const auditDependenciesWithRestrictedVersion = (
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+ packageJsonData : PackageJson | any ,
26
+ nodeName : string ,
27
+ depsToCheckFor : string [ ]
28
+ ) : AuditDependenciesWithRestrictedVersionResponse => {
29
+ let hasDependencyWithRestrictedVersion = false ;
30
+ const dependenciesWithRestrictedVersion = [ ] ;
31
+ const dependenciesWithoutRestrictedVersion = [ ] ;
32
+
19
33
if ( ! packageJsonData . hasOwnProperty ( nodeName ) ) {
20
- return false ;
34
+ return {
35
+ hasDependencyWithRestrictedVersion,
36
+ dependenciesWithRestrictedVersion,
37
+ dependenciesWithoutRestrictedVersion,
38
+ } ;
21
39
}
22
40
23
41
// eslint-disable-next-line no-restricted-syntax, guard-for-in
24
42
for ( const dependencyName in packageJsonData [ nodeName ] ) {
25
43
// eslint-disable-next-line no-restricted-syntax
26
44
for ( const depToCheckFor of depsToCheckFor ) {
27
45
if ( depToCheckFor === dependencyName ) {
28
- return true ;
29
- }
30
-
31
- if (
46
+ hasDependencyWithRestrictedVersion = true ;
47
+ dependenciesWithRestrictedVersion . push ( dependencyName ) ;
48
+ } else if (
32
49
depToCheckFor . endsWith ( '*' ) &&
33
50
dependencyName . startsWith ( depToCheckFor . slice ( 0 , Math . max ( 0 , depToCheckFor . length - 1 ) ) )
34
51
) {
35
- return true ;
52
+ hasDependencyWithRestrictedVersion = true ;
53
+ dependenciesWithRestrictedVersion . push ( dependencyName ) ;
54
+ } else {
55
+ dependenciesWithoutRestrictedVersion . push ( dependencyName ) ;
36
56
}
37
57
}
38
58
}
39
59
40
- return false ;
60
+ return {
61
+ hasDependencyWithRestrictedVersion,
62
+ dependenciesWithRestrictedVersion,
63
+ dependenciesWithoutRestrictedVersion,
64
+ } ;
41
65
} ;
42
66
67
+ export interface AuditDependenciesWithRestrictedPrereleaseVersionResponse {
68
+ hasDependencyWithRestrictedPrereleaseVersion : boolean ;
69
+ dependenciesWithRestrictedPrereleaseVersion : string [ ] ;
70
+ dependenciesWithoutRestrictedPrereleaseVersion : string [ ] ;
71
+ }
72
+
43
73
/**
44
74
* Determines whether or not the package has a pre-release version of a given dependency
45
- * @param { object } packageJsonData Valid JSON
46
- * @param { string } nodeName Name of a node in the package.json file
47
- * @param { string } depsToCheckFor An array of packages to check for
48
- * @return { boolean } True if the package has a pre-release version of a dependency. False if it is not or the node is missing.
75
+ * @param packageJsonData Valid JSON
76
+ * @param nodeName Name of a node in the package.json file
77
+ * @param depsToCheckFor An array of packages to check for
78
+ * @return True if the package has a pre-release version of a dependency. False if it is not or the node is missing.
49
79
*/
50
- export const hasDepPrereleaseVers = (
80
+ export const auditDependenciesWithRestrictedPrereleaseVersion = (
51
81
// eslint-disable-next-line @typescript-eslint/no-explicit-any
52
82
packageJsonData : PackageJson | any ,
53
83
nodeName : string ,
54
84
depsToCheckFor : string [ ]
55
- ) : boolean => {
85
+ ) : AuditDependenciesWithRestrictedPrereleaseVersionResponse => {
86
+ let hasDependencyWithRestrictedPrereleaseVersion = false ;
87
+ const dependenciesWithRestrictedPrereleaseVersion = [ ] ;
88
+ const dependenciesWithoutRestrictedPrereleaseVersion = [ ] ;
89
+
56
90
if ( ! packageJsonData . hasOwnProperty ( nodeName ) ) {
57
- return false ;
91
+ return {
92
+ hasDependencyWithRestrictedPrereleaseVersion,
93
+ dependenciesWithRestrictedPrereleaseVersion,
94
+ dependenciesWithoutRestrictedPrereleaseVersion,
95
+ } ;
58
96
}
59
97
60
98
// eslint-disable-next-line no-restricted-syntax
@@ -63,12 +101,19 @@ export const hasDepPrereleaseVers = (
63
101
const dependencyVersion = packageJsonData [ nodeName ] [ dependencyName ] ;
64
102
65
103
if ( dependencyVersion . includes ( '-beta' ) || dependencyVersion . includes ( '-rc' ) ) {
66
- return true ;
104
+ hasDependencyWithRestrictedPrereleaseVersion = true ;
105
+ dependenciesWithRestrictedPrereleaseVersion . push ( dependencyName ) ;
106
+ } else {
107
+ dependenciesWithoutRestrictedPrereleaseVersion . push ( dependencyName ) ;
67
108
}
68
109
}
69
110
}
70
111
71
- return false ;
112
+ return {
113
+ hasDependencyWithRestrictedPrereleaseVersion,
114
+ dependenciesWithRestrictedPrereleaseVersion,
115
+ dependenciesWithoutRestrictedPrereleaseVersion,
116
+ } ;
72
117
} ;
73
118
74
119
export interface AuditDependenciesWithMajorVersionOfZeroResponse {
0 commit comments