1
1
const fs = require ( "fs" ) ;
2
2
const path = require ( "path" ) ;
3
3
4
+ const chalk = require ( "chalk" ) ;
5
+
4
6
const { Range } = require ( "semver" ) ;
5
7
6
8
const debug = require ( "debug" ) ( "check-package-versions" ) ;
7
9
8
10
function main ( ) {
9
11
const packages = readPackages ( ) ;
10
12
const errors = [ ] ;
13
+ const warnings = [ ] ;
11
14
12
15
for ( const candidateName in packages ) {
13
16
for ( const dependencyName in packages ) {
@@ -19,15 +22,38 @@ function main() {
19
22
} catch ( err ) {
20
23
errors . push ( err . message ) ;
21
24
}
25
+ try {
26
+ checkDependencyVersionRange (
27
+ packages [ candidateName ] ,
28
+ packages [ dependencyName ]
29
+ ) ;
30
+ } catch ( err ) {
31
+ warnings . push ( err . message ) ;
32
+ }
22
33
}
23
34
}
24
35
36
+ for ( const error of errors ) {
37
+ console . error ( chalk . red ( "Error:" ) , error ) ;
38
+ }
39
+ for ( const warning of warnings ) {
40
+ console . error ( chalk . yellow ( "Warning:" ) , warning ) ;
41
+ }
42
+
43
+ const doneColor =
44
+ errors . length > 0
45
+ ? chalk . red
46
+ : warnings . length > 0
47
+ ? chalk . yellow
48
+ : chalk . green ;
49
+ console . error (
50
+ doneColor ( "Done." ) ,
51
+ `${ errors . length } errors, ${ warnings . length } warnings found for @truffle namespace version dependencies.`
52
+ ) ;
53
+
25
54
if ( errors . length > 0 ) {
26
- console . error ( errors . join ( "\n" ) ) ;
27
55
process . exit ( 1 ) ;
28
56
}
29
-
30
- console . log ( "No errors found" ) ;
31
57
}
32
58
33
59
function getPackageNames ( ) {
@@ -77,6 +103,34 @@ function checkDependencyVersion(candidate, dependency) {
77
103
}
78
104
}
79
105
106
+ function checkDependencyVersionRange ( candidate , dependency ) {
107
+ const name = dependency . name ;
108
+ const version = dependency . version ;
109
+
110
+ for ( const depType of [
111
+ "dependencies" ,
112
+ "devDependencies" ,
113
+ "peerDependencies"
114
+ ] ) {
115
+ const deps = candidate [ depType ] ;
116
+ if ( deps && deps [ name ] ) {
117
+ const rawRange = deps [ name ] ;
118
+
119
+ if ( rawRange !== `^${ version } ` ) {
120
+ throw new Error (
121
+ `Package "${ candidate . name } " depends on "${ name } @${ rawRange } ", but range has not been updated for version ${ version } `
122
+ ) ;
123
+ } else {
124
+ debug (
125
+ `${ candidate . name } requires ${ name } @${ version } (${ rawRange } is up-to-date for version ${ version } )`
126
+ ) ;
127
+ }
128
+ } else {
129
+ debug ( `${ candidate . name } does not require ${ name } ` ) ;
130
+ }
131
+ }
132
+ }
133
+
80
134
if ( require . main === module ) {
81
135
main ( ) ;
82
136
}
0 commit comments