diff --git a/build.bun.ts b/build.bun.ts index 0e534189..03810303 100644 --- a/build.bun.ts +++ b/build.bun.ts @@ -1,9 +1,15 @@ #!/usr/bin/env bun import { $ } from "bun"; +import { cpSync, mkdirSync } from "node:fs"; // Run TypeScript compiler for type declarations await $`tsc`; +// Copy schema.json (tsc is emitDeclarationOnly, Bun.build doesn't emit JSON assets). +// Needed for the "./schema.json" package export. +mkdirSync("dist/src/generated", { recursive: true }); +cpSync("src/generated/schema.json", "dist/src/generated/schema.json"); + const isDevelopment = Bun.env.NODE_ENV === "development"; // Build all JavaScript/TypeScript files @@ -25,10 +31,14 @@ function buildJs( }); } +// zod is a peerDependency — keep it external so consumers share a single +// zod instance (instanceof ZodError / schema.extend() break with duplicate copies). +const PEER_EXTERNALS = ["@modelcontextprotocol/sdk", "zod"]; + await Promise.all([ buildJs("src/app.ts", { outdir: "dist/src", - external: ["@modelcontextprotocol/sdk"], + external: PEER_EXTERNALS, }), buildJs("src/app.ts", { outdir: "dist/src", @@ -36,19 +46,19 @@ await Promise.all([ }), buildJs("src/app-bridge.ts", { outdir: "dist/src", - external: ["@modelcontextprotocol/sdk"], + external: PEER_EXTERNALS, }), buildJs("src/react/index.tsx", { outdir: "dist/src/react", - external: ["react", "react-dom", "@modelcontextprotocol/sdk"], + external: ["react", "react-dom", ...PEER_EXTERNALS], }), buildJs("src/react/index.tsx", { outdir: "dist/src/react", - external: ["react", "react-dom", "@modelcontextprotocol/sdk"], + external: ["react", "react-dom", ...PEER_EXTERNALS], naming: { entry: "react-with-deps.js" }, }), buildJs("src/server/index.ts", { outdir: "dist/src/server", - external: ["@modelcontextprotocol/sdk"], + external: PEER_EXTERNALS, }), ]);