11#!/usr/bin/env node
22
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" ;
66
77const __filename = fileURLToPath ( import . meta. url ) ;
88const __dirname = path . dirname ( __filename ) ;
@@ -13,39 +13,39 @@ const __dirname = path.dirname(__filename);
1313 * Usage: node scripts/check-version-consistency.js
1414 */
1515
16- console . log ( ' 🔍 Checking version consistency across packages...\n' ) ;
16+ console . log ( " 🔍 Checking version consistency across packages...\n" ) ;
1717
1818// List of package.json files to check
1919const 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" ,
2424] ;
2525
2626const versions = new Map ( ) ;
2727const errors = [ ] ;
2828
2929// 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+
3333 if ( ! fs . existsSync ( fullPath ) ) {
3434 console . warn ( `⚠️ Skipping ${ packagePath } - file not found` ) ;
3535 return ;
3636 }
3737
3838 try {
39- const packageJson = JSON . parse ( fs . readFileSync ( fullPath , ' utf8' ) ) ;
39+ const packageJson = JSON . parse ( fs . readFileSync ( fullPath , " utf8" ) ) ;
4040 const version = packageJson . version ;
4141 const packageName = packageJson . name || packagePath ;
42-
42+
4343 versions . set ( packagePath , {
4444 name : packageName ,
4545 version : version ,
46- dependencies : packageJson . dependencies || { }
46+ dependencies : packageJson . dependencies || { } ,
4747 } ) ;
48-
48+
4949 console . log ( `📦 ${ packagePath } :` ) ;
5050 console . log ( ` Name: ${ packageName } ` ) ;
5151 console . log ( ` Version: ${ version } ` ) ;
@@ -55,24 +55,24 @@ packagePaths.forEach(packagePath => {
5555} ) ;
5656
5757if ( 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 } ` ) ) ;
6060 process . exit ( 1 ) ;
6161}
6262
6363// 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 ) ;
6565const uniqueVersions = [ ...new Set ( allVersions ) ] ;
6666
67- console . log ( ' \n📊 Version Summary:' ) ;
67+ console . log ( " \n📊 Version Summary:" ) ;
6868console . log ( ` Total packages: ${ versions . size } ` ) ;
6969console . log ( ` Unique versions: ${ uniqueVersions . length } ` ) ;
7070
7171if ( 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:" ) ;
7676 versions . forEach ( ( info , path ) => {
7777 console . error ( ` - ${ path } : ${ info . version } ` ) ;
7878 } ) ;
@@ -81,62 +81,68 @@ if (uniqueVersions.length > 1) {
8181}
8282
8383// Check workspace dependencies in root package.json
84- const rootPackage = versions . get ( ' package.json' ) ;
84+ const rootPackage = versions . get ( " package.json" ) ;
8585if ( rootPackage ) {
86- console . log ( ' \n🔗 Checking workspace dependencies...' ) ;
86+ console . log ( " \n🔗 Checking workspace dependencies..." ) ;
8787 const expectedVersion = rootPackage . version ;
8888 let dependencyErrors = false ;
89-
89+
9090 Object . entries ( rootPackage . dependencies ) . forEach ( ( [ dep , version ] ) => {
91- if ( dep . startsWith ( ' @modelcontextprotocol/inspector-' ) ) {
91+ if ( dep . startsWith ( " @modelcontextprotocol/inspector-" ) ) {
9292 const expectedDepVersion = `^${ expectedVersion } ` ;
9393 if ( version !== expectedDepVersion ) {
94- console . error ( ` ❌ ${ dep } : ${ version } (expected ${ expectedDepVersion } )` ) ;
94+ console . error (
95+ ` ❌ ${ dep } : ${ version } (expected ${ expectedDepVersion } )` ,
96+ ) ;
9597 dependencyErrors = true ;
9698 } else {
9799 console . log ( ` ✅ ${ dep } : ${ version } ` ) ;
98100 }
99101 }
100102 } ) ;
101-
103+
102104 if ( dependencyErrors ) {
103- errors . push ( ' Workspace dependency versions do not match package versions' ) ;
105+ errors . push ( " Workspace dependency versions do not match package versions" ) ;
104106 }
105107}
106108
107109// 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" ) ;
110112let lockFileError = false ;
111113
112114if ( ! fs . existsSync ( lockPath ) ) {
113- console . error ( ' ❌ package-lock.json not found' ) ;
115+ console . error ( " ❌ package-lock.json not found" ) ;
114116 lockFileError = true ;
115117} else {
116118 try {
117- const lockFile = JSON . parse ( fs . readFileSync ( lockPath , ' utf8' ) ) ;
119+ const lockFile = JSON . parse ( fs . readFileSync ( lockPath , " utf8" ) ) ;
118120 const lockVersion = lockFile . version ;
119121 const expectedVersion = rootPackage ?. version || uniqueVersions [ 0 ] ;
120-
122+
121123 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+ ) ;
123127 lockFileError = true ;
124128 } else {
125129 console . log ( ` ✅ package-lock.json version matches: ${ lockVersion } ` ) ;
126130 }
127-
131+
128132 // Check workspace package versions in lock file
129133 if ( lockFile . packages ) {
130134 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" } ,
134138 ] ;
135-
139+
136140 workspacePackages . forEach ( ( { path, name } ) => {
137141 const lockPkgPath = lockFile . packages [ path ] ;
138142 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+ ) ;
140146 lockFileError = true ;
141147 }
142148 } ) ;
@@ -148,22 +154,24 @@ if (!fs.existsSync(lockPath)) {
148154}
149155
150156// Final result
151- console . log ( ' \n🎯 Result:' ) ;
157+ console . log ( " \n🎯 Result:" ) ;
152158if ( uniqueVersions . length === 1 && errors . length === 0 && ! lockFileError ) {
153- console . log ( ' ✅ Version consistency check passed!' ) ;
159+ console . log ( " ✅ Version consistency check passed!" ) ;
154160 process . exit ( 0 ) ;
155161} else {
156- console . error ( ' ❌ Version consistency check failed!' ) ;
162+ console . error ( " ❌ Version consistency check failed!" ) ;
157163 if ( uniqueVersions . length > 1 ) {
158- console . error ( ' - Package versions are not consistent' ) ;
164+ console . error ( " - Package versions are not consistent" ) ;
159165 }
160166 if ( errors . length > 0 ) {
161- console . error ( ' - ' + errors . join ( ' \n - ' ) ) ;
167+ console . error ( " - " + errors . join ( " \n - " ) ) ;
162168 }
163169 if ( lockFileError ) {
164- console . error ( ' - package-lock.json is out of sync' ) ;
170+ console . error ( " - package-lock.json is out of sync" ) ;
165171 }
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+ ) ;
167175 console . error ( ' or run "npm install" to update package-lock.json' ) ;
168176 process . exit ( 1 ) ;
169- }
177+ }
0 commit comments