Skip to content

Commit 79744af

Browse files
authored
fix(build): copy schema.json to dist and externalize zod (#534)
Two packaging bugs: 1. The './schema.json' export pointed to dist/src/generated/schema.json but nothing copied it there (tsc is emitDeclarationOnly, Bun.build doesn't emit JSON). Consumers got ERR_MODULE_NOT_FOUND. Fix: cpSync after tsc runs. 2. zod is a peerDependency but was bundled into every entry point (~270KB each). This causes dual-instance bugs where consumer-side 'instanceof ZodError' and schema.extend() break across boundaries. Fix: add zod to external list for all non-with-deps entries. Bundle size impact: app.js 293952 -> 24561 (-91.6%) app-bridge.js 299517 -> 30112 (-89.9%) react/index.js 295558 -> 26153 (-91.2%) server/index.js 291500 -> 22135 (-92.4%) app-with-deps 321814 -> 321814 (unchanged, intentional)
1 parent 1ea1e9e commit 79744af

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

build.bun.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
#!/usr/bin/env bun
22
import { $ } from "bun";
3+
import { cpSync, mkdirSync } from "node:fs";
34

45
// Run TypeScript compiler for type declarations
56
await $`tsc`;
67

8+
// Copy schema.json (tsc is emitDeclarationOnly, Bun.build doesn't emit JSON assets).
9+
// Needed for the "./schema.json" package export.
10+
mkdirSync("dist/src/generated", { recursive: true });
11+
cpSync("src/generated/schema.json", "dist/src/generated/schema.json");
12+
713
const isDevelopment = Bun.env.NODE_ENV === "development";
814

915
// Build all JavaScript/TypeScript files
@@ -25,30 +31,34 @@ function buildJs(
2531
});
2632
}
2733

34+
// zod is a peerDependency — keep it external so consumers share a single
35+
// zod instance (instanceof ZodError / schema.extend() break with duplicate copies).
36+
const PEER_EXTERNALS = ["@modelcontextprotocol/sdk", "zod"];
37+
2838
await Promise.all([
2939
buildJs("src/app.ts", {
3040
outdir: "dist/src",
31-
external: ["@modelcontextprotocol/sdk"],
41+
external: PEER_EXTERNALS,
3242
}),
3343
buildJs("src/app.ts", {
3444
outdir: "dist/src",
3545
naming: { entry: "app-with-deps.js" },
3646
}),
3747
buildJs("src/app-bridge.ts", {
3848
outdir: "dist/src",
39-
external: ["@modelcontextprotocol/sdk"],
49+
external: PEER_EXTERNALS,
4050
}),
4151
buildJs("src/react/index.tsx", {
4252
outdir: "dist/src/react",
43-
external: ["react", "react-dom", "@modelcontextprotocol/sdk"],
53+
external: ["react", "react-dom", ...PEER_EXTERNALS],
4454
}),
4555
buildJs("src/react/index.tsx", {
4656
outdir: "dist/src/react",
47-
external: ["react", "react-dom", "@modelcontextprotocol/sdk"],
57+
external: ["react", "react-dom", ...PEER_EXTERNALS],
4858
naming: { entry: "react-with-deps.js" },
4959
}),
5060
buildJs("src/server/index.ts", {
5161
outdir: "dist/src/server",
52-
external: ["@modelcontextprotocol/sdk"],
62+
external: PEER_EXTERNALS,
5363
}),
5464
]);

0 commit comments

Comments
 (0)