Strip dev-only platform binaries from published package, remove postinstall#516
Draft
gh0stonio wants to merge 2 commits intomodelcontextprotocol:mainfrom
Draft
Strip dev-only platform binaries from published package, remove postinstall#516gh0stonio wants to merge 2 commits intomodelcontextprotocol:mainfrom
gh0stonio wants to merge 2 commits intomodelcontextprotocol:mainfrom
Conversation
Fixes modelcontextprotocol#222. Prevents npm from downloading 400MB+ of platform-specific binaries for SDK consumers. The `postinstall` script is redundant since `prepare` already handles bun setup.
…nstall Fixes modelcontextprotocol#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).
3 tasks
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #222
Prevents
@oven/bun-*and@rollup/rollup-*platform binaries (~400MB) from being installed by SDK consumers, while keeping them available for contributors.Builds on the investigation from #451, thanks @ochafik!
Context
At Datadog we're building on MCP Apps and this
optionalDependenciesbloat is blocking our CI pipelines, which motivated picking this up.Why moving to
devDependenciesdoesn't work#451 moved the binaries from
optionalDependenciestodevDependencies. The problem is these packages declareos/cpuconstraints in their ownpackage.json. InoptionalDependencies, npm silently skips platform mismatches. IndevDependencies,npm cifails hard (e.g. macOS ARM errors on@oven/bun-linux-x64).Removing them entirely doesn't work either: contributors need the
@oven/bun-*packages installed beforeprepareruns so thatsetup-bun.mjscan find and link the bun binary for the build step.Approach
The binaries must stay in
optionalDependenciesfor contributor installs to work, but they must not appear in the publishedpackage.json. The solution uses npm lifecycle hooks to strip them at publish time:prepack(runs beforenpm pack/npm publish): backs uppackage.json, then removes only@oven/bun-*and@rollup/rollup-*entries fromoptionalDependencies(other optional deps are preserved)postpack(runs after): restores the originalpackage.jsonfrom backupAlso removes the
postinstallscript, which is redundant withprepare(line 64) that already runssetup-bun.mjs. The script isn't even shipped in the published package ("files": ["dist"]), so as noted in the #451 review, noINIT_CWDdetection is needed.This is a bit hacky but has the lowest impact on the contributor workflow. No build scripts or setup logic are changed.
Test plan
Verified from a clean state (
rm -rf node_modules && npm ci):npm cisucceedsnpm run build/npm run build:allsucceednpm testpasses (85/85)npm run test:e2epassesnpm run prettierpassestypedocpassesnpm packproduces a tarball with nooptionalDependenciesin itspackage.jsonpackage.jsonis correctly restored after pack (17optionalDependenciesentries)@oven/bun-*or@rollup/rollup-*