feat: add the imageminGenerate generator - #723
Merged
Merged
Conversation
The last capability `image-minimizer-webpack-plugin` had and this one did not. `imageminMinify` cannot write a converted image: a plugin like `imagemin-webp` produces a format the asset's name does not claim, and `processAssets` is past the point where a name can change, so it keeps the original and warns. `generate` runs while the module builds, which is where the rename is still possible. Which format gets written is the plugins' decision rather than the caller's, so unlike `sharpGenerate` this one asks for no target: it reads the format back off the bytes and renames to match, and leaves an asset its plugins did not convert under the name it had. Query and fragment survive, since they name the asset too. Tested against `imagemin-svgo` over SVG markup carrying a raster name -- the mismatch `imageminMinify` refuses, which is the one a generator exists to take -- plus the unchanged-format and query cases and the contract it declares. It joins the version table too, which now covers both generators.
🦋 Changeset detectedLatest commit: a5909fb The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #723 +/- ##
==========================================
+ Coverage 94.73% 94.76% +0.02%
==========================================
Files 4 4
Lines 1102 1108 +6
Branches 386 386
==========================================
+ Hits 1044 1050 +6
Misses 51 51
Partials 7 7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
The last capability
image-minimizer-webpack-pluginhas and this one does not, so it closes the functional gap between them.imageminMinifycannot write a converted image: a plugin likeimagemin-webpproduces a format the asset's name does not claim, andprocessAssetsis past the point where a name can change, so it keeps the original and warns.generateruns while the module builds, which is where the rename is still possible.Which format gets written is the plugins' decision rather than the caller's, so unlike
sharpGeneratethis one asks for no target: it reads the format back off the bytes and renames to match, leaving an asset its plugins did not convert under the name it had. Query and fragment survive, since they name the asset too. Everything else mirrorsimageminMinify— the sameimageminNormalizeConfig, the same ESMimport(), the same imagemin@8-Buffer / @9-Uint8Array handling, and the same declared contract.What kind of change does this PR introduce?
feat
Did you add tests for your changes?
Yes — four cases in
test/image-minify-option.test.js: the rename, the unchanged-format case, query and fragment surviving, and the contract it declares. They driveimagemin-svgoover SVG markup carrying a raster name, which is the same mismatchimageminMinifyrefuses and needs no new dependency. It also joins the minimizer-version table, which now covers both generators.Does this PR introduce a breaking change?
No — a new export, nothing existing changes.
If relevant, what needs to be documented once your changes are merged or what have you already documented?
Documented here: the
generatesection now says the two bundled generators differ in who picks the format, the note about a convertingimageminplugin points at this one, and the image-minimizer list says conversion isgenerate's job rather than a minimizer's.Use of AI
Claude Code wrote it, from
image-minimizer-webpack-plugin's ownimageminGenerateand this repo'simageminMinifyandsharpGenerateside by side, so the port keeps upstream's behaviour in this plugin's calling convention. The test reuses a trick already in the suite rather than addingimagemin-webpas a dependency, and was checked with a name filter to confirm the new cases execute rather than being skipped by the suite's package gate.🤖 Generated with Claude Code
https://claude.ai/code/session_016TQeNpahUSDUjD2Crugy5H
Generated by Claude Code