Move Bun and Rollup binaries to devDependencies and skip setup when installed as dependency#451
Open
Move Bun and Rollup binaries to devDependencies and skip setup when installed as dependency#451
Conversation
…ncies Fixes #222. The @oven/bun-* and @rollup/rollup-* binaries were listed as optionalDependencies, causing npm to download 400MB+ of platform-specific binaries when consumers installed the package. These are build tools only needed by contributors, not SDK consumers. Changes: - Move all @oven/bun-* and @rollup/rollup-* packages from optionalDependencies to devDependencies so they're not installed for SDK consumers - Guard setup-bun.mjs postinstall script with INIT_CWD check to skip execution when running as an installed dependency (not in the repo itself) https://claude.ai/code/session_01YXG43Kz9LuxBygzicH1LcZ
Member
jonathanhefner
left a comment
There was a problem hiding this comment.
Claude says:
npm's
preparelifecycle hook does exactly what you want:
- Runs after
npm installin the local project (development)- Does NOT run when the package is installed as a dependency from the npm registry
- Also runs before
npm pack/npm publishThis project already has it at
package.json:65:"prepare": "node scripts/setup-bun.mjs && npm run build && husky",So the
postinstallat line 47 is completely redundant. The simpler fix for the script side is to just delete thepostinstallentry entirely and letpreparehandle bun setup. NoINIT_CWDdetection needed....
The
filesfield already excludes the script — Since"files": ["dist"], thescripts/setup-bun.mjsfile isn't even shipped in the published package. The currentpostinstallalready fails gracefully via|| echo '...'for registry consumers. The real issue is just theoptionalDependenciesbeing downloaded, not the script executing.
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
This PR moves Bun and Rollup platform-specific binaries from
optionalDependenciestodevDependencies, and adds logic to skip the Bun setup script when the package is installed as a dependency in another project.Fixes #222
Key Changes
@oven/bun-*and@rollup/rollup-*packages fromoptionalDependenciestodevDependenciessetup-bun.mjsto detect when the package is installed as a dependency (viaINIT_CWD) and skip setup in those casesresolvefrom thepathmoduleImplementation Details
The setup script now checks if
INIT_CWD(set by npm during postinstall) differs from the project root. When the package is installed as a dependency,INIT_CWDpoints to the consumer's project directory, allowing the script to exit early. This prevents unnecessary Bun binary downloads for SDK consumers who only need the package as a library, not as a build tool.The moved binaries are now treated as required dev dependencies rather than optional, ensuring consistent builds in development environments while the early-exit logic prevents them from being installed in dependent projects.