refactor: utils and compressor cleanup (v11.1, first slice)

Merged
SR
10d ago
+150-83

Eighth PR of the v11.1.0 cleanup (R15, R16), first slice of the Cleanup Inventory: utils and the compressors. No change to output or reported sizes. The one visible change is a no-compress error message for array input.

Summary

 packages/{cssnano,oxc,minify-html}/src/index.ts
-  validateMinifyResult(result, "<name>")      # run() already validates every result
 packages/utils/src/getFilesize{Gzipped,Brotli}InBytes.ts
-  if (!isValidFile(file))                      # deprecated sync check
+  if (!(await isValidFileAsync(file)))
 packages/no-compress/src/index.ts
-  own Buffer / string / undefined handling
+  return { code: ensureStringContent(content, "no-compress") }
 packages/utils/package.json
-  "build": "tsdown src/*.ts"                   # 25 entries, 100 files in dist
+  "build": "tsdown src/index.ts"               # 4 files; the exports map only exposes "."
  • no-compress: a small check runs before ensureStringContent. Numbers, objects and null still throw the old message, because ensureStringContent would let them through.
  • FileOperationError: unchanged. A new test pins how cause is stored today. The plan listed its "old runtime" fallback for removal, but that fallback is what keeps cause set, because the class's own cause field resets it after super(). Removing both makes cause non-enumerable, which is visible, so it moves to v12.
  • Docs: packages/utils/AGENTS.md lists the internal code that still uses deprecated exports, and the root AGENTS.md drops the "multi-file build" line.
  • Changeset: patch bumps for utils, cssnano, oxc, minify-html and no-compress.

Evidence

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

  • CLI: 11 runs per build: cssnano, oxc and minify-html on valid input, empty input and a syntax error, plus no-compress on JS, CSS and a missing file. stdout, exit codes and output files are byte-identical.
  • The removed checks never fired: on the real libraries, cssnano's result.css, oxc's result.code and minify-html's Buffer#toString() always return a string, including on empty, comment-only, malformed and \u0000 input. cssnano-error.test.ts is deleted: its only test mocked postcss to return css: undefined.
  • Sizes: all four size helpers, the string and Raw versions, give identical output on a JS file, a CSS file, test.png, animated.gif, a missing path and a directory. Examples: test.png gzip 160,630 B and brotli 160,567 B. Errors are unchanged: File does not exist and Path is not a valid file, same class and cause. filesize-guards.test.ts pins both messages.
  • Single entry:
    • Nothing in the repo deep-imports @node-minify/utils/dist/… or a subpath.
    • The exported names are identical: 49 from index.d.ts plus the runtime ones.
    • attw is green.
    • The packed tarball goes from 103 files (47,441 B) to 7 files (41,637 B).
  • FileOperationError: the new test fails if the v12 change is applied by hand.
  • Gate: build (including the Action bundle), lint, typecheck, check-exports and both guards pass, as do 1154 of 1154 tests on the first 7 commits. That's 13 more than develop: +8 size guards, +2 cause, +4 no-compress and −1 cssnano. The last commit adds one more cause test (3 of 3 pass).

Merge Danger

Door: two-way. It's a revert away.

Blast Radius: small

  • no-compress: array input, which happens when several image files are passed, now throws no-compress compressor does not support array content instead of no-compress failed: content must be a string or Buffer but received object. The changeset names it.
  • Size helpers, file deleted mid-check: if a file disappears between existsSync and the validity check, the error message changes from Failed to validate file …: ENOENT: … to Failed to access file …: Path is not a valid file. It's still a FileOperationError. A missing file in normal use gives the same error as before.
  • utils dist: the 96 files outside index are gone. They were never reachable through the exports map, but a consumer bypassing it with a direct file path would break.
  • Not in this PR:
    • the Action's duplicated logic;
    • the benchmark's size calculation;
    • the CLI's tier blocks;
    • core's second input check.

Summary by cubic

Internal cleanup of @node-minify/utils and the compressors for v11.1 with no change to output or reported sizes. The one visible change: no-compress array input now throws no-compress compressor does not support array content instead of the old generic message.

  • cssnano, oxc and minify-html no longer call validateMinifyResult because run already validates every result and these libraries always return a string.
  • The gzip and brotli size helpers check files with isValidFileAsync instead of the deprecated sync isValidFile.
  • @node-minify/utils now builds only its index entry; the exports map only exposes . and nothing imported the other 24 dist files.
  • New tests pin the FileOperationError cause behavior and the size helpers' error messages.