From b99937ba2f60b6bdddf9f330fb304b7cb252f438 Mon Sep 17 00:00:00 2001 From: Antoine Leveque Date: Tue, 3 Mar 2026 11:35:10 +0100 Subject: [PATCH 1/2] Move bun/rollup binaries to devDependencies, remove postinstall script Fixes #222. Prevents npm from downloading 400MB+ of platform-specific binaries for SDK consumers. The `postinstall` script is redundant since `prepare` already handles bun setup. --- package.json | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 6a2d0faa..956b1608 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,6 @@ "examples/*" ], "scripts": { - "postinstall": "node scripts/setup-bun.mjs || echo 'setup-bun.mjs failed or not available'", "start": "npm run examples:dev", "generate:schemas": "tsx scripts/generate-schemas.ts && prettier --write \"src/generated/**/*\"", "sync:snippets": "bun scripts/sync-snippets.ts", @@ -75,7 +74,24 @@ "devDependencies": { "@boneskull/typedoc-plugin-mermaid": "^0.2.0", "@modelcontextprotocol/sdk": "1.25.2", + "@oven/bun-darwin-aarch64": "^1.2.21", + "@oven/bun-darwin-x64": "^1.2.21", + "@oven/bun-darwin-x64-baseline": "^1.2.21", + "@oven/bun-linux-aarch64": "^1.2.21", + "@oven/bun-linux-aarch64-musl": "^1.2.21", + "@oven/bun-linux-x64": "^1.2.21", + "@oven/bun-linux-x64-baseline": "^1.2.21", + "@oven/bun-linux-x64-musl": "^1.2.21", + "@oven/bun-linux-x64-musl-baseline": "^1.2.21", + "@oven/bun-windows-x64": "^1.2.21", + "@oven/bun-windows-x64-baseline": "^1.2.21", "@playwright/test": "1.57.0", + "@rollup/rollup-darwin-arm64": "^4.53.3", + "@rollup/rollup-darwin-x64": "^4.53.3", + "@rollup/rollup-linux-arm64-gnu": "^4.53.3", + "@rollup/rollup-linux-x64-gnu": "^4.53.3", + "@rollup/rollup-win32-arm64-msvc": "^4.53.3", + "@rollup/rollup-win32-x64-msvc": "^4.53.3", "@types/bun": "^1.3.2", "@types/react": "^19.2.2", "@types/react-dom": "^19.2.2", @@ -117,25 +133,6 @@ "optional": true } }, - "optionalDependencies": { - "@oven/bun-darwin-aarch64": "^1.2.21", - "@oven/bun-darwin-x64": "^1.2.21", - "@oven/bun-darwin-x64-baseline": "^1.2.21", - "@oven/bun-linux-aarch64": "^1.2.21", - "@oven/bun-linux-aarch64-musl": "^1.2.21", - "@oven/bun-linux-x64": "^1.2.21", - "@oven/bun-linux-x64-baseline": "^1.2.21", - "@oven/bun-linux-x64-musl": "^1.2.21", - "@oven/bun-linux-x64-musl-baseline": "^1.2.21", - "@oven/bun-windows-x64": "^1.2.21", - "@oven/bun-windows-x64-baseline": "^1.2.21", - "@rollup/rollup-darwin-arm64": "^4.53.3", - "@rollup/rollup-darwin-x64": "^4.53.3", - "@rollup/rollup-linux-arm64-gnu": "^4.53.3", - "@rollup/rollup-linux-x64-gnu": "^4.53.3", - "@rollup/rollup-win32-arm64-msvc": "^4.53.3", - "@rollup/rollup-win32-x64-msvc": "^4.53.3" - }, "overrides": { "seroval": "1.4.1", "seroval-plugins": "1.4.2", From 8afa81da2510ca751cfe11bc4b57537895c4b8dd Mon Sep 17 00:00:00 2001 From: Antoine Leveque Date: Tue, 3 Mar 2026 11:59:32 +0100 Subject: [PATCH 2/2] Strip dev-only platform binaries from published package, remove postinstall Fixes #222. The @oven/bun-* and @rollup/rollup-* in optionalDependencies cause ~400MB of downloads for consumers. Instead of moving them to devDependencies (breaks npm ci due to os/cpu constraints), strip them at prepack time and restore at postpack. Also remove the redundant postinstall script (prepare already handles bun setup). --- package.json | 39 +++++++++++++++++--------------- scripts/restore-package-json.mjs | 14 ++++++++++++ scripts/strip-optional-deps.mjs | 32 ++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 18 deletions(-) create mode 100644 scripts/restore-package-json.mjs create mode 100644 scripts/strip-optional-deps.mjs diff --git a/package.json b/package.json index 956b1608..c679519e 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "generate:schemas": "tsx scripts/generate-schemas.ts && prettier --write \"src/generated/**/*\"", "sync:snippets": "bun scripts/sync-snippets.ts", "build": "npm run generate:schemas && npm run sync:snippets && node scripts/run-bun.mjs build.bun.ts && node scripts/link-self.mjs", - "prepack": "npm run build", + "prepack": "npm run build && node scripts/strip-optional-deps.mjs", + "postpack": "node scripts/restore-package-json.mjs", "build:all": "npm run examples:build", "test": "bun test src", "test:e2e": "playwright test", @@ -74,24 +75,7 @@ "devDependencies": { "@boneskull/typedoc-plugin-mermaid": "^0.2.0", "@modelcontextprotocol/sdk": "1.25.2", - "@oven/bun-darwin-aarch64": "^1.2.21", - "@oven/bun-darwin-x64": "^1.2.21", - "@oven/bun-darwin-x64-baseline": "^1.2.21", - "@oven/bun-linux-aarch64": "^1.2.21", - "@oven/bun-linux-aarch64-musl": "^1.2.21", - "@oven/bun-linux-x64": "^1.2.21", - "@oven/bun-linux-x64-baseline": "^1.2.21", - "@oven/bun-linux-x64-musl": "^1.2.21", - "@oven/bun-linux-x64-musl-baseline": "^1.2.21", - "@oven/bun-windows-x64": "^1.2.21", - "@oven/bun-windows-x64-baseline": "^1.2.21", "@playwright/test": "1.57.0", - "@rollup/rollup-darwin-arm64": "^4.53.3", - "@rollup/rollup-darwin-x64": "^4.53.3", - "@rollup/rollup-linux-arm64-gnu": "^4.53.3", - "@rollup/rollup-linux-x64-gnu": "^4.53.3", - "@rollup/rollup-win32-arm64-msvc": "^4.53.3", - "@rollup/rollup-win32-x64-msvc": "^4.53.3", "@types/bun": "^1.3.2", "@types/react": "^19.2.2", "@types/react-dom": "^19.2.2", @@ -133,6 +117,25 @@ "optional": true } }, + "optionalDependencies": { + "@oven/bun-darwin-aarch64": "^1.2.21", + "@oven/bun-darwin-x64": "^1.2.21", + "@oven/bun-darwin-x64-baseline": "^1.2.21", + "@oven/bun-linux-aarch64": "^1.2.21", + "@oven/bun-linux-aarch64-musl": "^1.2.21", + "@oven/bun-linux-x64": "^1.2.21", + "@oven/bun-linux-x64-baseline": "^1.2.21", + "@oven/bun-linux-x64-musl": "^1.2.21", + "@oven/bun-linux-x64-musl-baseline": "^1.2.21", + "@oven/bun-windows-x64": "^1.2.21", + "@oven/bun-windows-x64-baseline": "^1.2.21", + "@rollup/rollup-darwin-arm64": "^4.53.3", + "@rollup/rollup-darwin-x64": "^4.53.3", + "@rollup/rollup-linux-arm64-gnu": "^4.53.3", + "@rollup/rollup-linux-x64-gnu": "^4.53.3", + "@rollup/rollup-win32-arm64-msvc": "^4.53.3", + "@rollup/rollup-win32-x64-msvc": "^4.53.3" + }, "overrides": { "seroval": "1.4.1", "seroval-plugins": "1.4.2", diff --git a/scripts/restore-package-json.mjs b/scripts/restore-package-json.mjs new file mode 100644 index 00000000..8f2bb36d --- /dev/null +++ b/scripts/restore-package-json.mjs @@ -0,0 +1,14 @@ +#!/usr/bin/env node +// Restores the original package.json after packing (saved by strip-optional-deps.mjs). + +import { copyFileSync, unlinkSync } from "fs"; +import { join, dirname } from "path"; +import { fileURLToPath } from "url"; + +const __dirname = dirname(fileURLToPath(import.meta.url)); +const pkgPath = join(__dirname, "..", "package.json"); + +copyFileSync(pkgPath + ".bak", pkgPath); +unlinkSync(pkgPath + ".bak"); + +console.log("[restore-package-json] Restored original package.json"); diff --git a/scripts/strip-optional-deps.mjs b/scripts/strip-optional-deps.mjs new file mode 100644 index 00000000..f10a2672 --- /dev/null +++ b/scripts/strip-optional-deps.mjs @@ -0,0 +1,32 @@ +#!/usr/bin/env node +// Strips dev-only platform binaries (@oven/bun-*, @rollup/rollup-*) from +// optionalDependencies before packing. Consumers don't need these. +// Original is saved to package.json.bak and restored by restore-package-json.mjs (postpack). + +import { readFileSync, writeFileSync, copyFileSync } from "fs"; +import { join, dirname } from "path"; +import { fileURLToPath } from "url"; + +const __dirname = dirname(fileURLToPath(import.meta.url)); +const pkgPath = join(__dirname, "..", "package.json"); + +copyFileSync(pkgPath, pkgPath + ".bak"); + +const DEV_ONLY_PREFIXES = ["@oven/bun-", "@rollup/rollup-"]; + +const pkg = JSON.parse(readFileSync(pkgPath, "utf8")); +const optional = pkg.optionalDependencies; +if (optional) { + const removed = []; + for (const name of Object.keys(optional)) { + if (DEV_ONLY_PREFIXES.some((p) => name.startsWith(p))) { + delete optional[name]; + removed.push(name); + } + } + if (Object.keys(optional).length === 0) delete pkg.optionalDependencies; + writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n"); + console.log( + `[strip-optional-deps] Removed ${removed.length} dev-only packages from optionalDependencies`, + ); +}