Skip to content

feat: let a minify function format and place the extractComments banner - #752

Merged
alexander-akait merged 5 commits into
mainfrom
feat/format-banner
Oct 2, 2026
Merged

alexander-akait merged 5 commits into
mainfrom
feat/format-banner

Conversation

@alexander-akait

@alexander-akait alexander-akait commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Summary

The extractComments banner is always written as /*! … */ at the top of the asset. That works for JS and CSS, but webpack's HTML minifier is going to extract license comments too, and in an HTML document that line is visible text placed before the doctype.

A minify function can now define two optional helpers, like getTypes or getStage:

  • formatBanner(banner) returns the comment to write, for example <!-- ${banner} -->.
  • getBannerPosition() returns "start" (the default) or "end". With "end" the banner is appended with nothing in between, so the doctype stays first.

Without the helpers nothing changes. The output of webpack's HTML minimizer test case:

<!-- before -->
/*! For license information please see page.html.LICENSE.txt */
<!doctype html>…
<!-- after -->
<!doctype html>…<!-- For license information please see page.html.LICENSE.txt -->

What kind of change does this PR introduce?

feat

Did you add tests for your changes?

Yes, two cases in test/minify-option.test.js: one for formatBanner, one for getBannerPosition returning "end".

Does this PR introduce a breaking change?

No. Both helpers are optional.

If relevant, what needs to be documented once your changes are merged or what have you already documented?

Documented in the README under extractComments → banner. A changeset is included.

Use of AI

Written with Claude Code at the author's direction: the author chose the design (an HTML-style banner, placed at the end), and Claude implemented it, wrote the tests and ran the build, tests and lint.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PodT59cXaxm4YzC9WBHr6P


Generated by Claude Code

Summary by CodeRabbit

  • New Features
    • Extracted-comment banners can use a custom format, such as HTML comments, and appear at the start or end of minimized output.
    • By default, banners retain the block-comment format and appear at the start. A shebang remains at the beginning when a banner is placed at the end.
    • Errors while formatting a banner are reported for the affected asset, and processing stops.
    • Different banner formatting helpers can affect chunk naming.
  • Documentation
    • Updated banner guidance with examples of custom formatting and end-of-output placement, and notes on cache and chunk-hash behavior.

A `formatBanner` helper on the minify function replaces the `/*! … */`
wrapper, so an HTML minimizer can write `<!-- … -->`: a `/*!` line is
text in a document, and before the doctype it switches to quirks mode.
A `getBannerPosition` helper returning `"end"` appends the banner instead
of prepending it, so an HTML document keeps its doctype first.
@changeset-bot

changeset-bot Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b1b1034

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
minimizer-webpack-plugin Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov

codecov Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.67%. Comparing base (7c7c64c) to head (b1b1034).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #752      +/-   ##
==========================================
+ Coverage   97.64%   97.67%   +0.02%     
==========================================
  Files           5        5              
  Lines        1697     1718      +21     
  Branches      652      664      +12     
==========================================
+ Hits         1657     1678      +21     
  Misses         39       39              
  Partials        1        1              

☔ View full report in Codecov by Harness.
📢 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.

The same lockfile change as #750, so npm audit passes in Lint.
@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: f23937a3-84ab-4cbb-a9cf-1fa6d0a9214b

📥 Commits

Reviewing files that changed from the base of the PR and between cc63bde and b1b1034.

📒 Files selected for processing (1)
  • README.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • README.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.


Walkthrough

The plugin adds optional minimizer helpers to format extracted-comment banners and select their position. It uses the first declared helper for each option, with the default banner format and start position when helpers are not declared. A banner placed at the end follows the minimized source, and the plugin preserves a shebang at the start. Helper exceptions are reported against the asset. Minimizer identity includes the stringified banner helpers when they are declared.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to b1b10

The banner documentation matches the implemented behavior. No issue identified in this review prevents merging after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to cc63b

The hooks operate within trusted build configuration and existing asset-writing authority. The main concern is that stateful helpers can reuse outdated cached banners or skip a helper that would now fail. No new attacker-controlled execution boundary was established.

Retained concerns

  • Low · reliability · inferred: Banner-helper identity records source text rather than captured or bound state. If that state changes without a corresponding version change, otherwise identical builds can reuse stale banner output and bypass a helper that would now throw. This is a conditional cache and failure-containment gap, not a demonstrated authorization bypass.
Security review details

Security Blast Radius

  • inferred — The demonstrated exposure is selected assets and their cached outputs within a configured webpack compilation. The inspected hook path establishes neither a new tenant boundary nor a request-facing execution endpoint; external HTML-serving consumers remain outside the supplied scope.

Trust Boundaries and Controls

  • observed — Existing asset-name matching, minimizer filtering, and generated or already-processed asset checks remain upstream of hook selection. The new helpers reuse matched minimizers rather than deriving executable code from extracted comments.

Resilience and Maintainability Implications

  • inferred — Failure containment is sound for stable helper behavior on cache misses. Cached output bypasses helper invocation, so behavior changed through unversioned captured state can evade current error handling. The existing version hook provides a caller-controlled means to invalidate that output.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding optional helpers that format and place the extractComments banner.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 3…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 01d009ca-9c8d-4a4e-afef-00b4194a742c

📥 Commits

Reviewing files that changed from the base of the PR and between 7c7c64c and 6419638.

⛔ Files ignored due to path filters (2)
  • package-lock.json is excluded by !**/package-lock.json
  • test/__snapshots__/minify-option.test.js.snap is excluded by !**/*.snap
📒 Files selected for processing (5)
  • .changeset/format-banner.md
  • README.md
  • src/index.js
  • test/minify-option.test.js
  • types/index.d.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Comment thread src/index.js
Comment thread src/index.js Outdated
Comment thread src/index.js Outdated
…ache on it

An end banner now keeps the shebang it was split from, a formatBanner or
getBannerPosition that throws becomes an error of that asset rather than
rejecting processAssets, and a declared helper's source joins the cache
and chunk-hash identity.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: ee7e621d-aa0d-475d-8730-31d83cd8e1b3

📥 Commits

Reviewing files that changed from the base of the PR and between 6419638 and cc63bde.

📒 Files selected for processing (2)
  • src/index.js
  • test/minify-option.test.js

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

Comment thread src/index.js
@alexander-akait
alexander-akait merged commit 3ec4aca into main Oct 2, 2026
31 checks passed
@alexander-akait
alexander-akait deleted the feat/format-banner branch October 2, 2026 15:47
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.

1 participant