fix: ensure lib is built before examples:build (#185)
* fix: ensure lib is built before examples:build Add preexamples:build hook to automatically run `npm run build` before `examples:build`. This ensures examples always type-check against the latest library code, catching breaking changes during development. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * 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 <noreply@anthropic.com> * chore: regenerate package-lock.json for cross-platform compatibility --------- Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
parent
e078250adf
commit
f8e31eb97f
1 changed files with 338 additions and 95 deletions
49
scripts/check-versions.mjs
Normal file
49
scripts/check-versions.mjs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#!/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})`,
|
||||
);
|
||||
}
|
||||
Loading…
Reference in a new issue