refactor: utils and compressor cleanup (v11.1, first slice)
Merged
SR
10d ago+150+150+012345678901234567890123456789-83-83-01234567890123456789
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 beforeensureStringContent. Numbers, objects andnullstill throw the old message, becauseensureStringContentwould let them through.FileOperationError: unchanged. A new test pins howcauseis stored today. The plan listed its "old runtime" fallback for removal, but that fallback is what keepscauseset, because the class's owncausefield resets it aftersuper(). Removing both makescausenon-enumerable, which is visible, so it moves to v12.- Docs:
packages/utils/AGENTS.mdlists the internal code that still uses deprecated exports, and the rootAGENTS.mddrops the "multi-file build" line. - Changeset: patch bumps for
utils,cssnano,oxc,minify-htmlandno-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'sresult.codeand minify-html'sBuffer#toString()always return a string, including on empty, comment-only, malformed and\u0000input.cssnano-error.test.tsis deleted: its only test mocked postcss to returncss: undefined. - Sizes: all four size helpers, the string and
Rawversions, give identical output on a JS file, a CSS file,test.png,animated.gif, a missing path and a directory. Examples:test.pnggzip 160,630 B and brotli 160,567 B. Errors are unchanged:File does not existandPath is not a valid file, same class and cause.filesize-guards.test.tspins 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.tsplus the runtime ones. - attw is green.
- The packed tarball goes from 103 files (47,441 B) to 7 files (41,637 B).
- Nothing in the repo deep-imports
FileOperationError: the new test fails if the v12 change is applied by hand.- Gate: build (including the Action bundle), lint, typecheck,
check-exportsand both guards pass, as do 1154 of 1154 tests on the first 7 commits. That's 13 more thandevelop: +8 size guards, +2cause, +4no-compressand −1 cssnano. The last commit adds one morecausetest (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 throwsno-compress compressor does not support array contentinstead ofno-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
existsSyncand the validity check, the error message changes fromFailed to validate file …: ENOENT: …toFailed to access file …: Path is not a valid file. It's still aFileOperationError. A missing file in normal use gives the same error as before. utilsdist: the 96 files outsideindexare 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,oxcandminify-htmlno longer callvalidateMinifyResultbecauserunalready validates every result and these libraries always return a string.- The gzip and brotli size helpers check files with
isValidFileAsyncinstead of the deprecated syncisValidFile. @node-minify/utilsnow builds only itsindexentry; the exports map only exposes.and nothing imported the other 24 dist files.- New tests pin the
FileOperationErrorcausebehavior and the size helpers' error messages.