fix: extracted comments should be behind the shebang#12380
Conversation
✅ Deploy Preview for rspack canceled.
|
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue where extracted comments (license headers) were incorrectly placed before the shebang line in minified JavaScript files. The fix ensures that when both a shebang (#!/usr/bin/env node) and extracted comments exist, the shebang remains on the first line followed by the banner containing extracted comments.
Key Changes:
- Modified the minimizer to detect and extract shebangs before prepending comment banners
- Restructured the source concatenation logic to handle shebang positioning correctly
- Added comprehensive test coverage for CJS and ESM output formats with extracted comments
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/rspack_plugin_swc_js_minimizer/src/lib.rs | Implements shebang detection and proper ordering logic - extracts shebang from minified code when banner exists and prepends it before the banner |
| tests/rspack-test/configCases/rslib/hashbang-and-extract-comments/test.js | Adds test cases to verify shebang appears at the first line for CJS and ESM outputs |
| tests/rspack-test/configCases/rslib/hashbang-and-extract-comments/test.config.js | Configures test runner to use bundle3.js as the test executor |
| tests/rspack-test/configCases/rslib/hashbang-and-extract-comments/rspack.config.js | Sets up three compilation configurations (CJS, ESM without EsmLibraryPlugin, ESM with EsmLibraryPlugin) with extractComments enabled |
| tests/rspack-test/configCases/rslib/hashbang-and-extract-comments/index.js | Provides test source file with shebang that imports module with license comments |
| tests/rspack-test/configCases/rslib/hashbang-and-extract-comments/a.js | Provides module with various license comment formats to test comment extraction |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
📦 Binary Size-limit
❌ Size increased by 1.75KB from 47.69MB to 47.69MB (⬆️0.00%) |
Rsdoctor Bundle Diff AnalysisFound 5 project(s) in monorepo. 📁 react-10kPath:
📦 Download Diff Report: react-10k Bundle Diff 📁 react-1kPath:
📦 Download Diff Report: react-1k Bundle Diff 📁 ui-componentsPath:
📦 Download Diff Report: ui-components Bundle Diff 📁 romePath:
📦 Download Diff Report: rome Bundle Diff 📁 react-5kPath:
📦 Download Diff Report: react-5k Bundle Diff Generated by Rsdoctor GitHub Action |
CodSpeed Performance ReportMerging #12380 will not alter performanceComparing Summary
|
Summary
Currently, rspack may produce the code where extracted comments are on the first line before shebang:
/*! LICENSE */ #!/usr/bin/env nodeWe should check if the first line is shebang, and find the property place to insert extracted comments.
Ref: https://github.com/webpack/terser-webpack-plugin/blob/30182a343893ef2b56d755260d697d9aa7db4060/src/index.js#L603-L616
cc @Timeless0911 for visibility.
Checklist