Skip to content

feat: support extractComments in swcMinify#665

Open
kdy1 wants to merge 4 commits intowebpack:mainfrom
kdy1:kdy1/swc-extract-comments
Open

feat: support extractComments in swcMinify#665
kdy1 wants to merge 4 commits intowebpack:mainfrom
kdy1:kdy1/swc-extract-comments

Conversation

@kdy1
Copy link
Copy Markdown

@kdy1 kdy1 commented Apr 16, 2026

This wires extractComments into TerserPlugin.swcMinify for SWC builds that support comment extraction.

What changed:

  • normalize serializable extractComments conditions for SWC (boolean, "some", "all", string patterns, RegExp without flags, and object conditions that resolve to those forms)
  • preserve legal comments by default when extractComments: false is used with swcMinify
  • surface result.extractedComments back to the plugin so existing filename/banner handling keeps working
  • error clearly for unsupported function conditions and flagged regular expressions
  • update the README warning to document the supported subset
  • add swcMinify coverage for default extraction, object { condition, filename, banner }, disabled extraction, and unsupported function conditions
  • remove the explicit @swc/core runtime version gate and rely on the installed SWC build to accept or reject the forwarded option

Verification:

  • npm run build
  • npx jest test/minify-option.test.js --runInBand
  • npm run lint:code -- src/utils.js test/minify-option.test.js
  • npx prettier --check README.md src/utils.js test/minify-option.test.js types/utils.d.ts

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Apr 16, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

@kdy1
Copy link
Copy Markdown
Author

kdy1 commented Apr 16, 2026

Sorry I made a mistake with AI (codex).

My intention was to open this after publishing a new version of SWC.

I'll undraft this after publishing a new version.

@evenstensberg
Copy link
Copy Markdown
Member

@kdy1 could you sign the CLA?

@alexander-akait
Copy link
Copy Markdown
Member

@kdy1 feel free to ping when it was ready and we will make a release

@kdy1
Copy link
Copy Markdown
Author

kdy1 commented Apr 18, 2026

Sorry for the delay. I'm trying to deploy (again) it with https://github.com/swc-project/swc/actions/runs/24608184505

The previous run failed in a strange way.

@kdy1 kdy1 marked this pull request as ready for review April 19, 2026 13:36
@kdy1
Copy link
Copy Markdown
Author

kdy1 commented Apr 19, 2026

@alexander-akait I think this PR is good to go. Thank you for waiting 😄

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.76%. Comparing base (783427c) to head (60e2351).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #665   +/-   ##
=======================================
  Coverage   96.76%   96.76%           
=======================================
  Files           3        3           
  Lines         340      340           
  Branches      126      125    -1     
=======================================
  Hits          329      329           
  Misses         11       11           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

3 participants