File size: 1,502 Bytes
e1cc3bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env node
/**
 * Checks that example package.json files reference the same version
 * of @modelcontextprotocol/ext-apps as the root package.json.
 *
 * This ensures examples stay in sync with the library version.
 */

import { readFileSync, readdirSync, statSync, existsSync } from "fs";
import { join } from "path";

const rootPkg = JSON.parse(readFileSync("package.json", "utf-8"));
const rootVersion = rootPkg.version;
const pkgName = rootPkg.name;

const expectedDep = `^${rootVersion}`;

let hasError = false;

const examplesDir = "examples";
const examples = readdirSync(examplesDir).filter((d) => {
  const pkgPath = join(examplesDir, d, "package.json");
  return statSync(join(examplesDir, d)).isDirectory() && existsSync(pkgPath);
});

for (const example of examples) {
  const pkgPath = join(examplesDir, example, "package.json");
  const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));

  const dep = pkg.dependencies?.[pkgName];
  // Allow "../.." (local dev) or the correct versioned dependency
  if (dep && dep !== expectedDep && dep !== "../..") {
    console.error(
      `❌ ${pkgPath}: expected "${pkgName}": "${expectedDep}" (or "../.."), got "${dep}"`,
    );
    hasError = true;
  }
}

if (hasError) {
  console.error(
    `\nRun the following to fix:\n  npm pkg set dependencies.${pkgName}=${expectedDep} --workspaces`,
  );
  process.exit(1);
} else {
  console.log(
    `✅ All examples reference ${pkgName}@${expectedDep} (root version: ${rootVersion})`,
  );
}