Skip to content

Commit 02737db

Browse files
authored
fix: sync local SDK build into node_modules for examples (#504)
npm workspaces hoists example dependencies to the root node_modules, but installs the published registry copy of @modelcontextprotocol/ext-apps instead of linking to the local source. This causes type-check failures when examples use features not yet published to npm. Add scripts/link-self.mjs which copies the freshly-built dist/ and package.json into the hoisted node_modules copy after each SDK build, ensuring examples always type-check against the latest local types. See: npm/feedback#774
1 parent 1728617 commit 02737db

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"start": "npm run examples:dev",
4949
"generate:schemas": "tsx scripts/generate-schemas.ts && prettier --write \"src/generated/**/*\"",
5050
"sync:snippets": "bun scripts/sync-snippets.ts",
51-
"build": "npm run generate:schemas && npm run sync:snippets && node scripts/run-bun.mjs build.bun.ts",
51+
"build": "npm run generate:schemas && npm run sync:snippets && node scripts/run-bun.mjs build.bun.ts && node scripts/link-self.mjs",
5252
"prepack": "npm run build",
5353
"build:all": "npm run examples:build",
5454
"test": "bun test src",

scripts/link-self.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Workaround: npm workspaces don't symlink the root package into node_modules
3+
* when child workspaces depend on it — it installs a stale registry copy instead.
4+
* This script syncs the freshly-built dist/ and package.json into that copy
5+
* so examples always type-check against the latest local types.
6+
* See: https://github.com/npm/feedback/discussions/774
7+
*/
8+
import { cpSync, existsSync } from "fs";
9+
10+
const target = "node_modules/@modelcontextprotocol/ext-apps";
11+
if (!existsSync(target)) process.exit(0);
12+
13+
cpSync("dist", `${target}/dist`, { recursive: true });
14+
cpSync("package.json", `${target}/package.json`);

0 commit comments

Comments
 (0)