refactor(action): share minify-and-measure and reporting between modes

Merged
SR
10d ago
+157-150

Tenth and last PR of the v11.1.0 cleanup (R15, R16), third slice of the Cleanup Inventory: the GitHub Action. No change to behavior.

Summary

 packages/action/src/minify.ts
+  minifyAndMeasure({ compressor, inputPath, outputPath, file, type, options, includeGzip })
+    resolve compressor → stat → time minify() → stat → reduction → gzip? → FileResult
   runMinification (explicit)   → minifyAndMeasure(...)
 packages/action/src/index.ts
-  getFileSize / toRepositoryPath                      # copy of minify.ts
-  runAutoMode: inline resolve/stat/minify/stat/gzip  # copy of runMinification
+  runAutoMode: minifyAndMeasure(...) + compressor label
+  reportResult(result, inputs, summarize)            # outputs → summary → PR comment → annotations
+  failOnThreshold(result, inputs)
   runExplicitMode: reportResult → benchmark → failOnThreshold → info   # same order as before
   runAutoMode:     reportResult →             failOnThreshold → info
 packages/action/src/discover.ts
-  DEFAULT_IGNORES = [ … ]                             # identical copy
+  import { DEFAULT_IGNORES } from "@node-minify/utils"
 packages/action/src/inputs.ts
-  benchmark-compressors: inline split/trim/filter IIFE
+  [...new Set(parseCommaSeparated(input))] || DEFAULT_BENCHMARK_COMPRESSORS
  • Explicit mode still resolves the compressor before reading the input, and passes options only when non-empty.
  • Both final log lines are unchanged.
  • Changeset: patch for @node-minify/action.

Evidence

I built develop (af81b143) and this branch, then ran the built packages/action/dist/index.js from each one, with INPUT_*, GITHUB_OUTPUT and GITHUB_STEP_SUMMARY set, in a fresh project per scenario.

Before / after: stdout, exit code, outputs file, step summary and the dist/ files (size + sha) are identical in all 16 scenarios, once timings and the random output delimiter are masked:

  • explicit terser with gzip and annotations
  • explicit with benchmark, benchmark-compressors: "terser, esbuild ,terser,"
  • explicit with benchmark, default compressors
  • explicit with a failing min-reduction, with and without benchmark
  • explicit with JSON options and no gzip
  • explicit esbuild on CSS
  • explicit with a removed compressor (yui), an unknown compressor, a missing input
  • auto with gzip on a project with .js/.css/.html/.json, a node_modules/ file and a *.min.js (5 processed, 2 ignored)
  • auto with a failing threshold
  • auto with one broken file (2 warnings, exit 0) and with every file broken (exit 1)
  • auto dry-run, and auto with no matching files

The only other difference seen was one run of the default benchmark picking terser instead of oxc. This is timing noise: speed is 40% of the recommendation score. Over 6 runs each, both builds picked oxc 5 times and terser once.

benchmark-compressors parsing: old and new parseInputs() give the same list for "", "terser", " terser , esbuild ", "terser,terser", ",,", " , ", "a,b,a" and "terser, esbuild ,terser,".

Gate: build, lint, typecheck, check-exports and both guard scripts pass. All 1153 tests pass, the same as develop, including 213 in the Action package.

Not run end to end: the PR comment path, which needs a real pull request event. Its call order is unchanged in the diff and covered by unit tests.

Merge Danger

Door: two-way

Internal refactor, revert is clean.

Blast Radius: Action

Any slip would show up in the Action's outputs, summary or PR comment. The bundle comparison above covers outputs and summary.


Summary by cubic

Refactors the @node-minify/action package so explicit and auto modes share one per-file minify-and-measure step and one reporting sequence, with no change to behavior.

  • Extracts minifyAndMeasure used by both runMinification and runAutoMode, so the compressor is still resolved before any file is read; its paths may be relative to the cwd.
  • Extracts reportResult and failOnThreshold used by both modes, preserving the original call order (outputs, summary, PR comment, annotations, thresholds).
  • Uses DEFAULT_IGNORES from @node-minify/utils instead of a local copy.
  • Parses benchmark-compressors with the same parseCommaSeparated helper used by other comma-separated inputs.
  • Adds a patch changeset for @node-minify/action.

Verified by running the built action from both branches across 16 scenarios: stdout, exit codes, outputs, step summaries, and generated dist files are identical.