1
1
#!/usr/bin/env node
2
2
3
- import fs from 'fs' ;
4
- import path from ' path' ;
5
- import { fileURLToPath } from ' url' ;
3
+ import fs from "fs" ;
4
+ import path from " path" ;
5
+ import { fileURLToPath } from " url" ;
6
6
7
7
const __filename = fileURLToPath ( import . meta. url ) ;
8
8
const __dirname = path . dirname ( __filename ) ;
@@ -13,39 +13,39 @@ const __dirname = path.dirname(__filename);
13
13
* Usage: node scripts/check-version-consistency.js
14
14
*/
15
15
16
- console . log ( ' 🔍 Checking version consistency across packages...\n' ) ;
16
+ console . log ( " 🔍 Checking version consistency across packages...\n" ) ;
17
17
18
18
// List of package.json files to check
19
19
const packagePaths = [
20
- ' package.json' ,
21
- ' client/package.json' ,
22
- ' server/package.json' ,
23
- ' cli/package.json'
20
+ " package.json" ,
21
+ " client/package.json" ,
22
+ " server/package.json" ,
23
+ " cli/package.json" ,
24
24
] ;
25
25
26
26
const versions = new Map ( ) ;
27
27
const errors = [ ] ;
28
28
29
29
// Read version from each package.json
30
- packagePaths . forEach ( packagePath => {
31
- const fullPath = path . join ( __dirname , '..' , packagePath ) ;
32
-
30
+ packagePaths . forEach ( ( packagePath ) => {
31
+ const fullPath = path . join ( __dirname , ".." , packagePath ) ;
32
+
33
33
if ( ! fs . existsSync ( fullPath ) ) {
34
34
console . warn ( `⚠️ Skipping ${ packagePath } - file not found` ) ;
35
35
return ;
36
36
}
37
37
38
38
try {
39
- const packageJson = JSON . parse ( fs . readFileSync ( fullPath , ' utf8' ) ) ;
39
+ const packageJson = JSON . parse ( fs . readFileSync ( fullPath , " utf8" ) ) ;
40
40
const version = packageJson . version ;
41
41
const packageName = packageJson . name || packagePath ;
42
-
42
+
43
43
versions . set ( packagePath , {
44
44
name : packageName ,
45
45
version : version ,
46
- dependencies : packageJson . dependencies || { }
46
+ dependencies : packageJson . dependencies || { } ,
47
47
} ) ;
48
-
48
+
49
49
console . log ( `📦 ${ packagePath } :` ) ;
50
50
console . log ( ` Name: ${ packageName } ` ) ;
51
51
console . log ( ` Version: ${ version } ` ) ;
@@ -55,24 +55,24 @@ packagePaths.forEach(packagePath => {
55
55
} ) ;
56
56
57
57
if ( errors . length > 0 ) {
58
- console . error ( ' \n❌ Errors occurred while reading package files:' ) ;
59
- errors . forEach ( error => console . error ( ` - ${ error } ` ) ) ;
58
+ console . error ( " \n❌ Errors occurred while reading package files:" ) ;
59
+ errors . forEach ( ( error ) => console . error ( ` - ${ error } ` ) ) ;
60
60
process . exit ( 1 ) ;
61
61
}
62
62
63
63
// Check if all versions match
64
- const allVersions = Array . from ( versions . values ( ) ) . map ( v => v . version ) ;
64
+ const allVersions = Array . from ( versions . values ( ) ) . map ( ( v ) => v . version ) ;
65
65
const uniqueVersions = [ ...new Set ( allVersions ) ] ;
66
66
67
- console . log ( ' \n📊 Version Summary:' ) ;
67
+ console . log ( " \n📊 Version Summary:" ) ;
68
68
console . log ( ` Total packages: ${ versions . size } ` ) ;
69
69
console . log ( ` Unique versions: ${ uniqueVersions . length } ` ) ;
70
70
71
71
if ( uniqueVersions . length > 1 ) {
72
- console . error ( ' \n❌ Version mismatch detected!' ) ;
73
- console . error ( ' Found versions: ' + uniqueVersions . join ( ', ' ) ) ;
74
-
75
- console . error ( ' \n Package versions:' ) ;
72
+ console . error ( " \n❌ Version mismatch detected!" ) ;
73
+ console . error ( " Found versions: " + uniqueVersions . join ( ", " ) ) ;
74
+
75
+ console . error ( " \n Package versions:" ) ;
76
76
versions . forEach ( ( info , path ) => {
77
77
console . error ( ` - ${ path } : ${ info . version } ` ) ;
78
78
} ) ;
@@ -81,62 +81,68 @@ if (uniqueVersions.length > 1) {
81
81
}
82
82
83
83
// Check workspace dependencies in root package.json
84
- const rootPackage = versions . get ( ' package.json' ) ;
84
+ const rootPackage = versions . get ( " package.json" ) ;
85
85
if ( rootPackage ) {
86
- console . log ( ' \n🔗 Checking workspace dependencies...' ) ;
86
+ console . log ( " \n🔗 Checking workspace dependencies..." ) ;
87
87
const expectedVersion = rootPackage . version ;
88
88
let dependencyErrors = false ;
89
-
89
+
90
90
Object . entries ( rootPackage . dependencies ) . forEach ( ( [ dep , version ] ) => {
91
- if ( dep . startsWith ( ' @modelcontextprotocol/inspector-' ) ) {
91
+ if ( dep . startsWith ( " @modelcontextprotocol/inspector-" ) ) {
92
92
const expectedDepVersion = `^${ expectedVersion } ` ;
93
93
if ( version !== expectedDepVersion ) {
94
- console . error ( ` ❌ ${ dep } : ${ version } (expected ${ expectedDepVersion } )` ) ;
94
+ console . error (
95
+ ` ❌ ${ dep } : ${ version } (expected ${ expectedDepVersion } )` ,
96
+ ) ;
95
97
dependencyErrors = true ;
96
98
} else {
97
99
console . log ( ` ✅ ${ dep } : ${ version } ` ) ;
98
100
}
99
101
}
100
102
} ) ;
101
-
103
+
102
104
if ( dependencyErrors ) {
103
- errors . push ( ' Workspace dependency versions do not match package versions' ) ;
105
+ errors . push ( " Workspace dependency versions do not match package versions" ) ;
104
106
}
105
107
}
106
108
107
109
// Check if package-lock.json is up to date
108
- console . log ( ' \n🔒 Checking package-lock.json...' ) ;
109
- const lockPath = path . join ( __dirname , '..' , ' package-lock.json' ) ;
110
+ console . log ( " \n🔒 Checking package-lock.json..." ) ;
111
+ const lockPath = path . join ( __dirname , ".." , " package-lock.json" ) ;
110
112
let lockFileError = false ;
111
113
112
114
if ( ! fs . existsSync ( lockPath ) ) {
113
- console . error ( ' ❌ package-lock.json not found' ) ;
115
+ console . error ( " ❌ package-lock.json not found" ) ;
114
116
lockFileError = true ;
115
117
} else {
116
118
try {
117
- const lockFile = JSON . parse ( fs . readFileSync ( lockPath , ' utf8' ) ) ;
119
+ const lockFile = JSON . parse ( fs . readFileSync ( lockPath , " utf8" ) ) ;
118
120
const lockVersion = lockFile . version ;
119
121
const expectedVersion = rootPackage ?. version || uniqueVersions [ 0 ] ;
120
-
122
+
121
123
if ( lockVersion !== expectedVersion ) {
122
- console . error ( ` ❌ package-lock.json version (${ lockVersion } ) does not match package.json version (${ expectedVersion } )` ) ;
124
+ console . error (
125
+ ` ❌ package-lock.json version (${ lockVersion } ) does not match package.json version (${ expectedVersion } )` ,
126
+ ) ;
123
127
lockFileError = true ;
124
128
} else {
125
129
console . log ( ` ✅ package-lock.json version matches: ${ lockVersion } ` ) ;
126
130
}
127
-
131
+
128
132
// Check workspace package versions in lock file
129
133
if ( lockFile . packages ) {
130
134
const workspacePackages = [
131
- { path : ' client' , name : ' @modelcontextprotocol/inspector-client' } ,
132
- { path : ' server' , name : ' @modelcontextprotocol/inspector-server' } ,
133
- { path : ' cli' , name : ' @modelcontextprotocol/inspector-cli' }
135
+ { path : " client" , name : " @modelcontextprotocol/inspector-client" } ,
136
+ { path : " server" , name : " @modelcontextprotocol/inspector-server" } ,
137
+ { path : " cli" , name : " @modelcontextprotocol/inspector-cli" } ,
134
138
] ;
135
-
139
+
136
140
workspacePackages . forEach ( ( { path, name } ) => {
137
141
const lockPkgPath = lockFile . packages [ path ] ;
138
142
if ( lockPkgPath && lockPkgPath . version !== expectedVersion ) {
139
- console . error ( ` ❌ ${ name } in lock file: ${ lockPkgPath . version } (expected ${ expectedVersion } )` ) ;
143
+ console . error (
144
+ ` ❌ ${ name } in lock file: ${ lockPkgPath . version } (expected ${ expectedVersion } )` ,
145
+ ) ;
140
146
lockFileError = true ;
141
147
}
142
148
} ) ;
@@ -148,22 +154,24 @@ if (!fs.existsSync(lockPath)) {
148
154
}
149
155
150
156
// Final result
151
- console . log ( ' \n🎯 Result:' ) ;
157
+ console . log ( " \n🎯 Result:" ) ;
152
158
if ( uniqueVersions . length === 1 && errors . length === 0 && ! lockFileError ) {
153
- console . log ( ' ✅ Version consistency check passed!' ) ;
159
+ console . log ( " ✅ Version consistency check passed!" ) ;
154
160
process . exit ( 0 ) ;
155
161
} else {
156
- console . error ( ' ❌ Version consistency check failed!' ) ;
162
+ console . error ( " ❌ Version consistency check failed!" ) ;
157
163
if ( uniqueVersions . length > 1 ) {
158
- console . error ( ' - Package versions are not consistent' ) ;
164
+ console . error ( " - Package versions are not consistent" ) ;
159
165
}
160
166
if ( errors . length > 0 ) {
161
- console . error ( ' - ' + errors . join ( ' \n - ' ) ) ;
167
+ console . error ( " - " + errors . join ( " \n - " ) ) ;
162
168
}
163
169
if ( lockFileError ) {
164
- console . error ( ' - package-lock.json is out of sync' ) ;
170
+ console . error ( " - package-lock.json is out of sync" ) ;
165
171
}
166
- console . error ( '\n💡 Run "npm run update-version <new-version>" to fix version inconsistencies' ) ;
172
+ console . error (
173
+ '\n💡 Run "npm run update-version <new-version>" to fix version inconsistencies' ,
174
+ ) ;
167
175
console . error ( ' or run "npm install" to update package-lock.json' ) ;
168
176
process . exit ( 1 ) ;
169
- }
177
+ }
0 commit comments