Skip to content

Commit a30a3fb

Browse files
Lint
1 parent b70cf56 commit a30a3fb

File tree

3 files changed

+107
-85
lines changed

3 files changed

+107
-85
lines changed

scripts/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ This directory contains scripts for managing version consistency across the mono
99
Updates the version across all package.json files in the monorepo and updates package-lock.json.
1010

1111
**Usage:**
12+
1213
```bash
1314
npm run update-version <new-version>
1415
# Example:
1516
npm run update-version 0.14.3
1617
```
1718

1819
This script will:
20+
1921
1. Update the version in all package.json files (root, client, server, cli)
2022
2. Update workspace dependencies in the root package.json
2123
3. Run `npm install` to update package-lock.json
@@ -26,11 +28,13 @@ This script will:
2628
Checks that all packages have consistent versions and that package-lock.json is up to date.
2729

2830
**Usage:**
31+
2932
```bash
3033
npm run check-version
3134
```
3235

3336
This script checks:
37+
3438
1. All package.json files have the same version
3539
2. Workspace dependencies in root package.json match the current version
3640
3. package-lock.json version matches package.json
@@ -41,12 +45,14 @@ This check runs automatically in CI on every PR and push to main.
4145
## CI Integration
4246

4347
The version consistency check is integrated into the GitHub Actions workflow (`.github/workflows/main.yml`) and will fail the build if:
48+
4449
- Package versions are inconsistent
4550
- package-lock.json is out of sync
4651

4752
## Common Workflows
4853

4954
### Bumping version for a release:
55+
5056
```bash
5157
# Update to new version
5258
npm run update-version 0.15.0
@@ -63,4 +69,4 @@ git tag 0.15.0
6369

6470
# Push changes and tag
6571
git push && git push --tags
66-
```
72+
```

scripts/check-version-consistency.js

Lines changed: 58 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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

77
const __filename = fileURLToPath(import.meta.url);
88
const __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
1919
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",
2424
];
2525

2626
const versions = new Map();
2727
const 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

5757
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}`));
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);
6565
const uniqueVersions = [...new Set(allVersions)];
6666

67-
console.log('\n📊 Version Summary:');
67+
console.log("\n📊 Version Summary:");
6868
console.log(` Total packages: ${versions.size}`);
6969
console.log(` Unique versions: ${uniqueVersions.length}`);
7070

7171
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:");
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");
8585
if (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");
110112
let lockFileError = false;
111113

112114
if (!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:");
152158
if (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

Comments
 (0)