fix(benchmark): detect the file type from each input's extension

Merged
SR
10d ago
+115-8

node-minify benchmark src/app.js -c terser,esbuild reported esbuild as failed with You must specify a type: js or css. The docs say type is auto-detected, but nothing detected it: the runner passed type to minify() only when the caller gave one.

Summary

 packages/benchmark/src/runner.ts
+  resolveType(file, type) = type ?? TYPE_BY_EXTENSION[extname(file).toLowerCase()]
+    .js .mjs .cjs .jsx → js    .css → css    .html .htm → html    other → none (as before)
   runWarmup / runIterations   # per file, so a .js and a .css in one run each get their own type
-    ...(options.type && { type: options.type })
+    ...(type && { type })
  • An explicit type (-t) still wins.
  • Docs: the type row in the docs page and the benchmark README, and the benchmark -t help text, now say the type is detected from the extension when omitted. The main command's -t help still says "required for esbuild", which stays true for minifying.
  • html: only esbuild reads type, and html-minifier, minify-html and no-compress give the same sizes with or without -t html.
  • Changeset: patch for @node-minify/benchmark and @node-minify/cli.

Evidence

Built CLI, node packages/cli/dist/bin/cli.js benchmark <file> -c … -f json, sizes in bytes:

RunBefore (develop af81b143)After
tests/fixtures/es5/fixture-1.js -c terser,esbuildterser 145; esbuild failed: You must specify a type: js or cssterser 145; esbuild 152
tests/fixtures/css/fixture-1.css -c lightningcss,esbuildlightningcss 640; esbuild failed, same errorlightningcss 640; esbuild 677
fixture-1.js -c esbuild -t css—esbuild 213 (explicit type wins over the extension)

Other compressors give identical sizes before and after: terser, swc, oxc, no-compress, lightningcss, cssnano, clean-css, html-minifier, minify-html.

Tests:

  • New runner-type.test.ts: an explicit type wins, each extension maps, unknown extensions pass no type.
  • A real-esbuild integration test, with no mocks and no type, on a .js and a .css file: both report success: true.
  • With runner.ts reverted to develop, 9 of the new tests fail.

Gate: build, lint, typecheck, check-exports and both guard scripts pass. All 1164 tests pass (develop has 1153; this adds 11).

Merge Danger

Door: two-way

Blast Radius: benchmark

Benchmark runs without -t now pass a type to compressors for known extensions. Only esbuild reads it, so the only visible change is that esbuild succeeds where it used to fail. The Action's benchmark is unchanged: it still skips esbuild when no type input is set.


Summary by cubic

Fixes node-minify benchmark failing with esbuild when no -t type is given, by detecting each input file's type from its extension (.js .mjs .cjs .jsx → js, .css → css, .html .htm → html). An explicit -t still wins, unknown extensions pass no type as before, and non-esbuild compressors produce identical sizes. Docs, CLI help, and a changeset now describe the detection.