Skip to content

Commit b70cf56

Browse files
feat: add version management scripts and CI check
- Added update-version.js script to automate version bumps across all packages - Added check-version-consistency.js script to verify version consistency - Integrated version check into CI workflow - Scripts check package.json versions AND package-lock.json sync - Added npm scripts: `npm run update-version` and `npm run check-version` - Added documentation in scripts/README.md This ensures version consistency across the monorepo and prevents accidental version mismatches or outdated lock files. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 752a415 commit b70cf56

File tree

5 files changed

+337
-1
lines changed

5 files changed

+337
-1
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ jobs:
2626
# - run: npm ci
2727
- run: npm install --no-package-lock
2828

29+
- name: Check version consistency
30+
run: npm run check-version
31+
2932
- name: Check linting
3033
working-directory: ./client
3134
run: npm run lint

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
"prettier-check": "prettier --check .",
3939
"lint": "prettier --check . && cd client && npm run lint",
4040
"prepare": "npm run build",
41-
"publish-all": "npm publish --workspaces --access public && npm publish --access public"
41+
"publish-all": "npm publish --workspaces --access public && npm publish --access public",
42+
"update-version": "node scripts/update-version.js",
43+
"check-version": "node scripts/check-version-consistency.js"
4244
},
4345
"dependencies": {
4446
"@modelcontextprotocol/inspector-cli": "^0.14.1",

scripts/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Version Management Scripts
2+
3+
This directory contains scripts for managing version consistency across the monorepo.
4+
5+
## Scripts
6+
7+
### update-version.js
8+
9+
Updates the version across all package.json files in the monorepo and updates package-lock.json.
10+
11+
**Usage:**
12+
```bash
13+
npm run update-version <new-version>
14+
# Example:
15+
npm run update-version 0.14.3
16+
```
17+
18+
This script will:
19+
1. Update the version in all package.json files (root, client, server, cli)
20+
2. Update workspace dependencies in the root package.json
21+
3. Run `npm install` to update package-lock.json
22+
4. Provide next steps for committing and tagging
23+
24+
### check-version-consistency.js
25+
26+
Checks that all packages have consistent versions and that package-lock.json is up to date.
27+
28+
**Usage:**
29+
```bash
30+
npm run check-version
31+
```
32+
33+
This script checks:
34+
1. All package.json files have the same version
35+
2. Workspace dependencies in root package.json match the current version
36+
3. package-lock.json version matches package.json
37+
4. Workspace packages in package-lock.json have the correct versions
38+
39+
This check runs automatically in CI on every PR and push to main.
40+
41+
## CI Integration
42+
43+
The version consistency check is integrated into the GitHub Actions workflow (`.github/workflows/main.yml`) and will fail the build if:
44+
- Package versions are inconsistent
45+
- package-lock.json is out of sync
46+
47+
## Common Workflows
48+
49+
### Bumping version for a release:
50+
```bash
51+
# Update to new version
52+
npm run update-version 0.15.0
53+
54+
# Verify everything is correct
55+
npm run check-version
56+
57+
# Commit the changes
58+
git add -A
59+
git commit -m "chore: bump version to 0.15.0"
60+
61+
# Create a tag
62+
git tag 0.15.0
63+
64+
# Push changes and tag
65+
git push && git push --tags
66+
```

scripts/check-version-consistency.js

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

scripts/update-version.js

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env node
2+
3+
import fs from 'fs';
4+
import path from 'path';
5+
import { execSync } from 'child_process';
6+
import { fileURLToPath } from 'url';
7+
8+
const __filename = fileURLToPath(import.meta.url);
9+
const __dirname = path.dirname(__filename);
10+
11+
/**
12+
* Updates version across all package.json files in the monorepo
13+
* Usage: node scripts/update-version.js <new-version>
14+
* Example: node scripts/update-version.js 0.14.2
15+
*/
16+
17+
const newVersion = process.argv[2];
18+
19+
if (!newVersion) {
20+
console.error('❌ Please provide a version number');
21+
console.error('Usage: node scripts/update-version.js <new-version>');
22+
console.error('Example: node scripts/update-version.js 0.14.2');
23+
process.exit(1);
24+
}
25+
26+
// Validate version format
27+
const versionRegex = /^\d+\.\d+\.\d+(-[\w.]+)?$/;
28+
if (!versionRegex.test(newVersion)) {
29+
console.error('❌ Invalid version format. Please use semantic versioning (e.g., 1.2.3 or 1.2.3-beta.1)');
30+
process.exit(1);
31+
}
32+
33+
console.log(`🔄 Updating all packages to version ${newVersion}...`);
34+
35+
// List of package.json files to update
36+
const packagePaths = [
37+
'package.json',
38+
'client/package.json',
39+
'server/package.json',
40+
'cli/package.json'
41+
];
42+
43+
const updatedFiles = [];
44+
45+
// Update version in each package.json
46+
packagePaths.forEach(packagePath => {
47+
const fullPath = path.join(__dirname, '..', packagePath);
48+
49+
if (!fs.existsSync(fullPath)) {
50+
console.warn(`⚠️ Skipping ${packagePath} - file not found`);
51+
return;
52+
}
53+
54+
try {
55+
const packageJson = JSON.parse(fs.readFileSync(fullPath, 'utf8'));
56+
const oldVersion = packageJson.version;
57+
packageJson.version = newVersion;
58+
59+
// Update workspace dependencies in root package.json
60+
if (packagePath === 'package.json' && packageJson.dependencies) {
61+
Object.keys(packageJson.dependencies).forEach(dep => {
62+
if (dep.startsWith('@modelcontextprotocol/inspector-')) {
63+
packageJson.dependencies[dep] = `^${newVersion}`;
64+
}
65+
});
66+
}
67+
68+
fs.writeFileSync(fullPath, JSON.stringify(packageJson, null, 2) + '\n');
69+
updatedFiles.push(packagePath);
70+
console.log(`✅ Updated ${packagePath} from ${oldVersion} to ${newVersion}`);
71+
} catch (error) {
72+
console.error(`❌ Failed to update ${packagePath}:`, error.message);
73+
process.exit(1);
74+
}
75+
});
76+
77+
console.log('\n📝 Summary:');
78+
console.log(`Updated ${updatedFiles.length} files to version ${newVersion}`);
79+
80+
// Update package-lock.json
81+
console.log('\n🔒 Updating package-lock.json...');
82+
try {
83+
execSync('npm install', { stdio: 'inherit' });
84+
console.log('✅ package-lock.json updated successfully');
85+
} catch (error) {
86+
console.error('❌ Failed to update package-lock.json:', error.message);
87+
console.error('Please run "npm install" manually');
88+
process.exit(1);
89+
}
90+
91+
console.log('\n✨ Version update complete!');
92+
console.log('\nNext steps:');
93+
console.log('1. Review the changes: git diff');
94+
console.log('2. Commit the changes: git add -A && git commit -m "chore: bump version to ' + newVersion + '"');
95+
console.log('3. Create a git tag: git tag v' + newVersion);
96+
console.log('4. Push changes and tag: git push && git push --tags');

0 commit comments

Comments
 (0)