-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix: preserve legal comments in bundler to match esbuild behavior #21870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
robobun
wants to merge
5
commits into
main
Choose a base branch
from
claude/fix-legal-comments-preservation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
Bun.build now preserves legal comments like esbuild does: - Comments starting with /*! or //! (already supported) - Comments containing @license, @preserve, or @copyright (new) This fixes GitHub issue #9795 by making Bun's bundler behavior consistent with esbuild's legal comment preservation. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Collaborator
Author
Adds the --legal-comments CLI option with values: - none: Disable legal comment preservation - inline: Keep legal comments inline in code (default for non-bundling) - eof: Move legal comments to end of file (default for bundling) - linked: Extract to separate .LEGAL.txt file with link - external: Extract to separate .LEGAL.txt file without link This provides full esbuild CLI compatibility for legal comment handling. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Adds full JavaScript API support for the legalComments option:
- Bun.build({ legalComments: "none" | "inline" | "eof" | "linked" | "external" })
- Proper enum validation with helpful error messages for invalid values
- Integration with bundler configuration pipeline
- Comprehensive test coverage in bun-build-api.test.ts
Example usage:
```javascript
await Bun.build({
entrypoints: ["src/index.js"],
legalComments: "eof", // Move legal comments to end of file
outdir: "dist"
});
```
This completes the esbuild compatibility for legal comment handling
in both CLI and JavaScript API.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
pfgithub
suggested changes
Aug 14, 2025
Contributor
pfgithub
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected_version needs to be updated in RuntimeTranspilerCache.zig
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
@license,@preserve, or@copyright(in addition to existing/*!and//!support)--legal-commentsCLI option for full esbuild compatibilitylegalCommentsoption toBun.build()JavaScript APIFeatures
Legal Comment Preservation
Before this change:
After this change:
Legal comment patterns now preserved:
/*!style comments (already supported)//!style comments (already supported)@license(new)@preserve(new)@copyright(new)CLI Option Support
NEW:
--legal-commentsoption with esbuild-compatible values:--legal-comments=none- Disable legal comment preservation--legal-comments=inline- Keep legal comments inline in code--legal-comments=eof- Move legal comments to end of file (default)--legal-comments=linked- Extract to separate.LEGAL.txtfile with link--legal-comments=external- Extract to separate.LEGAL.txtfile without linkExample CLI usage:
JavaScript API Support
NEW:
legalCommentsoption inBun.build():Features:
Test plan
bun-build-api.test.tsComplete esbuild compatibility: Both CLI and JavaScript API now fully match esbuild's legal comment handling behavior.
Closes #9795
🤖 Generated with Claude Code