Skip to content

Replace platform-specific optionalDependencies with bun devDependency#518

Merged
ochafik merged 2 commits intomodelcontextprotocol:mainfrom
gh0stonio:antoine.leveque/fix-optional-deps-222-v3
Mar 6, 2026
Merged

Replace platform-specific optionalDependencies with bun devDependency#518
ochafik merged 2 commits intomodelcontextprotocol:mainfrom
gh0stonio:antoine.leveque/fix-optional-deps-222-v3

Conversation

@gh0stonio
Copy link
Contributor

@gh0stonio gh0stonio commented Mar 3, 2026

Note: See #516 for a lower-impact alternative that keeps optionalDependencies and strips them at publish time via prepack/postpack. A bit more hacky but doesn't change the contributor setup at all.

Summary

Fixes #222

Replaces the 17 platform-specific optionalDependencies (@oven/bun-*, @rollup/rollup-*) with a single bun devDependency, and removes setup-bun.mjs entirely.

Builds on the investigation from #451, thanks @ochafik!

Context

At Datadog we're building on MCP Apps and this optionalDependencies bloat (~400MB of platform binaries) is blocking our CI pipelines, which motivated picking this up.

Problem

The repo listed 11 @oven/bun-* and 6 @rollup/rollup-* platform-specific packages in optionalDependencies. npm's optionalDependencies are installed for all consumers (they're "optional" in that npm doesn't fail if installation fails, not that they're skipped). This caused ~400MB of unnecessary downloads for anyone installing the SDK.

Why the previous approaches don't work

Approach

Instead of working around the problem, fix the root cause — the dependencies were declared at the wrong level:

@rollup/rollup-* — remove them

The SDK build uses bun (build.bun.ts), not rollup. These entries were added in 556a857f as a workaround for an npm bug where rollup's nested optionalDependencies weren't being fetched for the example workspaces (which use vite).

Verified that @rollup/rollup-darwin-arm64 now resolves correctly via vite without the top-level entries (tested with npm 10.9.2). If the bug resurfaces on older npm versions, contributors would see example build failures — the fix is simply to update npm. This only affects example workspace builds, not the SDK itself.

@oven/bun-* — replace with "bun": "^1.2.21" in devDependencies

The bun npm meta-package handles platform detection internally (via its own scoped optionalDependencies) and registers the binary in node_modules/.bin/bun automatically. As a devDependency, it's only installed for contributors, never for consumers.

Remove setup-bun.mjs

This script existed because the raw @oven/bun-* platform packages don't have a bin field — they just contain the binary file. The script had to manually detect the platform, find the right package in node_modules/@oven/bun-*, and symlink the binary to .bin/bun. With the bun meta-package, all of that is handled automatically by npm. The script is no longer needed.

Remove postinstall, simplify prepare

Based on this comment #451 (review) from @jonathanhefner.

  • postinstall (node scripts/setup-bun.mjs || ...) was redundant with prepare which already ran the same script, and setup-bun.mjs wasn't even shipped in the published package ("files": ["dist"])
  • prepare simplified from "node scripts/setup-bun.mjs && npm run build && husky" to "npm run build && husky"

Test plan

Verified from a clean state (rm -rf node_modules && npm ci):

  • npm ci succeeds
  • npm run build / npm run build:all succeed
  • npm test passes (85/85)
  • npm run test:e2e passes
  • npm run prettier passes
  • typedoc passes
  • npm pack produces a tarball with no optionalDependencies
  • @rollup/rollup-darwin-arm64 resolves correctly via vite without top-level entries (npm 10.9.2)
  • Consumer install from tarball: 92 packages / 26MB, zero @oven/bun-* or @rollup/rollup-*

Fixes modelcontextprotocol#222. The bun meta-package handles platform detection internally.
Rollup resolves its own platform binaries transitively. Removes ~400MB
of bloat for SDK consumers. Simplifies setup-bun.mjs accordingly.
No longer needed since the bun npm package handles binary
installation and PATH registration automatically.
@gh0stonio gh0stonio marked this pull request as ready for review March 3, 2026 14:00
Copy link
Contributor

@ochafik ochafik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @gh0stonio !!

@ochafik ochafik merged commit 62c7520 into modelcontextprotocol:main Mar 6, 2026
13 of 15 checks passed
@gh0stonio gh0stonio deleted the antoine.leveque/fix-optional-deps-222-v3 branch March 6, 2026 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(optional)Dependencies on Bun and Rollup adds 400+ MB to the install size

2 participants