refactor: benchmark, cli, core and sharp cleanup (v11.1, second slice)

Merged
SR
10d ago
+46-101

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, core and sharp.
  • 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 (since 1d3dad4e).

Evidence

I built develop (718af89f) and this branch and ran both on the same inputs. There are no mocks.

ItemOld vs new
node-minify benchmark … --gzip --brotli -f jsonSize 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 --helpbyte-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 GIFidentical sha256
  • Core, every path checked: compress() is only reached through minify(), after setup() has validated every array entry. compress isn't exported from @node-minify/core, and the CLI calls minify. wildcards runs 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 through minify() were already there.
  • Gate: build, lint, typecheck, check-exports and 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 internal compress() with an unvalidated array would no longer get the early Invalid input error. compress isn'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 esbuild on a JS file fails with You 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.

  • benchmark now reads, gzips, and brotli-compresses each output file once instead of twice; reported sizes are byte-identical.
  • cli prints the recommended, supported, and legacy tiers in --help from a single loop; the text is unchanged.
  • core no longer re-validates array entries in the internal compressArrayOfFiles; setup already validates every path into minify. Callers that bypass minify and call the unexported compress would no longer get the early "Invalid input" error.
  • sharp drops its own lazy-import cache because Node's module cache already covers it.