refactor: benchmark, cli, core and sharp cleanup (v11.1, second slice)
Merged
SR
10d ago+46+46+01234567890123456789-101-101-012345678901234567890123456789
Ninth PR of the v11.1.0 cleanup (R15, R16), second slice of the Cleanup Inventory: the benchmark, the CLI, core and sharp. No change to output.
Summary
packages/benchmark/src/runner.ts
- gzipSize = await getFilesizeGzippedInBytes(out) # reads + gzips the file
- gzipBytes = await getFilesizeGzippedRaw(out) # reads + gzips it again
+ gzipBytes = await getFilesizeGzippedRaw(out)
+ gzipSize = prettyBytes(gzipBytes) # same for brotli
packages/cli/src/bin/cli.ts displayCompressorsList
- three copied blocks (Recommended / Supported / Legacy)
+ for (const [label, status] of tiers) … # note printed whenever an entry has a replacement
packages/core/src/compress.ts compressArrayOfFiles
- second "Invalid input at index N" check # setup() already runs it on every path into compress()
packages/sharp/src/index.ts
- let sharpLib; getSharp() # cache on top of Node's module cache
+ (await import("sharp")).default # still lazy, inside convertImage
- Changeset: patch bumps for
benchmark,cli,coreandsharp. - Dropped from the plan: two items no longer apply on
develop.- The benchmark already reports the resolver's real error (since
d0d73b62). benchmark()is no longer a pure wrapper, because it writes the report file (since1d3dad4e).
- The benchmark already reports the resolver's real error (since
Evidence
I built develop (718af89f) and this branch and ran both on the same inputs. There are no mocks.
| Item | Old vs new |
|---|---|
node-minify benchmark … --gzip --brotli -f json | Size fields (sizeBytes, size, gzipBytes, gzipSize, brotliBytes, brotliSize) identical for terser on es5/fixture-1.js and for lightningcss and cssnano on css/fixture-1.css. A 1.1 MB file also matches, which covers the kB formatting. gzip and brotli calls per 2-compressor run drop from 4 each to 2 each. |
node-minify --help | byte-identical (diff empty) |
-i a.js -i "" | same error: Invalid input at index 1: expected non-empty string, got empty string |
-c sharp to WebP and GIF on test.png, and the animated GIF | identical sha256 |
- Core, every path checked:
compress()is only reached throughminify(), aftersetup()has validated every array entry.compressisn't exported from@node-minify/core, and the CLI callsminify.wildcardsruns after that check and returns only validated entries or glob matches. - Core tests:
- Removed: 3 tests that called the internal
compress()directly. - Added: the index-0 empty-string case through
minify(). The index-1 cases throughminify()were already there.
- Removed: 3 tests that called the internal
- Gate: build, lint, typecheck,
check-exportsand both guards pass, as do 1153 of 1153 tests. That's 1155 − 3 + 1.
Merge Danger
Door: two-way. It's a revert away.
Blast Radius: small
- Core: a caller that bypasses
minify()and reaches the internalcompress()with an unvalidated array would no longer get the earlyInvalid inputerror.compressisn't exported, so that would need a deep import. - Not in this PR:
- the Action's duplicated logic (the next and last v11.1 cleanup PR);
- a bug I found while checking this one, which fails the same way on
develop:node-minify benchmark -c esbuildon a JS file fails withYou must specify a type: js or css, because the benchmark doesn't pass the file type to esbuild.
Summary by cubic
Cleans up internal code in benchmark, cli, core, and sharp without changing any output.
benchmarknow reads, gzips, and brotli-compresses each output file once instead of twice; reported sizes are byte-identical.cliprints the recommended, supported, and legacy tiers in--helpfrom a single loop; the text is unchanged.coreno longer re-validates array entries in the internalcompressArrayOfFiles;setupalready validates every path intominify. Callers that bypassminifyand call the unexportedcompresswould no longer get the early "Invalid input" error.sharpdrops its own lazy-import cache because Node's module cache already covers it.