Skip to content

Commit 2076303

Browse files
ochafikclaude
andcommitted
feat: add version consistency check for examples
Add scripts/check-versions.mjs to verify that example package.json files reference the correct version of @modelcontextprotocol/ext-apps. - Allows "../.." (local dev) or "^{root-version}" as valid dependencies - Runs in CI before npm install to catch mismatches early - Available locally via `npm run check:versions` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 0b7ad58 commit 2076303

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ jobs:
3636
shell: bash
3737
run: '! grep -E "\"resolved\": \"https?://" package-lock.json | grep -v registry.npmjs.org'
3838

39+
- name: Verify example dependency versions
40+
shell: bash
41+
run: node scripts/check-versions.mjs
42+
3943
- uses: actions/setup-node@v4
4044
with:
4145
node-version: "20"

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
"docs": "typedoc",
5858
"docs:watch": "typedoc --watch",
5959
"prettier": "prettier -u \"**/*.{js,jsx,ts,tsx,mjs,json,md,yml,yaml}\" --check",
60-
"prettier:fix": "prettier -u \"**/*.{js,jsx,ts,tsx,mjs,json,md,yml,yaml}\" --write"
60+
"prettier:fix": "prettier -u \"**/*.{js,jsx,ts,tsx,mjs,json,md,yml,yaml}\" --write",
61+
"check:versions": "node scripts/check-versions.mjs"
6162
},
6263
"author": "Olivier Chafik",
6364
"devDependencies": {

scripts/check-versions.mjs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env node
2+
/**
3+
* Checks that example package.json files reference the same version
4+
* of @modelcontextprotocol/ext-apps as the root package.json.
5+
*
6+
* This ensures examples stay in sync with the library version.
7+
*/
8+
9+
import { readFileSync, readdirSync, statSync, existsSync } from "fs";
10+
import { join } from "path";
11+
12+
const rootPkg = JSON.parse(readFileSync("package.json", "utf-8"));
13+
const rootVersion = rootPkg.version;
14+
const pkgName = rootPkg.name;
15+
16+
const expectedDep = `^${rootVersion}`;
17+
18+
let hasError = false;
19+
20+
const examplesDir = "examples";
21+
const examples = readdirSync(examplesDir).filter((d) => {
22+
const pkgPath = join(examplesDir, d, "package.json");
23+
return statSync(join(examplesDir, d)).isDirectory() && existsSync(pkgPath);
24+
});
25+
26+
for (const example of examples) {
27+
const pkgPath = join(examplesDir, example, "package.json");
28+
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
29+
30+
const dep = pkg.dependencies?.[pkgName];
31+
// Allow "../.." (local dev) or the correct versioned dependency
32+
if (dep && dep !== expectedDep && dep !== "../..") {
33+
console.error(
34+
`❌ ${pkgPath}: expected "${pkgName}": "${expectedDep}" (or "../.."), got "${dep}"`,
35+
);
36+
hasError = true;
37+
}
38+
}
39+
40+
if (hasError) {
41+
console.error(
42+
`\nRun the following to fix:\n npm pkg set dependencies.${pkgName}=${expectedDep} --workspaces`,
43+
);
44+
process.exit(1);
45+
} else {
46+
console.log(
47+
`✅ All examples reference ${pkgName}@${expectedDep} (root version: ${rootVersion})`,
48+
);
49+
}

0 commit comments

Comments
 (0)