fix(core): fail when an input glob matches no file

Merged
SR
10h ago
+101-1

Summary

A wildcard input that matched nothing reached the compressors as input: []. With a $1 output, minify() resolved "" and wrote nothing, so a typo in a glob or an empty build directory looked like success.

 enhanceSettings()
   input = wildcards(requestedInput)
+  if any requested pattern contains "*" and input is now []
+    throw "No files matched input pattern: <patterns>"

The check uses *, the same test wildcards() uses to decide whether to glob.

InputBeforeAfter
"nope/**/*.js", output $1.min.jsresolves "", writes nothingthrows No files matched input pattern: nope/**/*.js
"nope/**/*.js", output all.jsthrows No content providedthrows No files matched …
["nope/*.js", "real.js"]worksworks (unchanged)
"missing.js" (no glob)unchangedunchanged
input: [], in-memory contentunchangedunchanged

Evidence

  • New setup-no-match.test.ts, 6 tests: before the fix 4 fail and 2 pass, after the fix all pass.
  • Real runs on the merged tree produce the "After" column above.
  • bun run test: 72 files, 1086 tests pass. Lint, typecheck, ci-guard-type-suppressions.sh pass.

Merge Danger

Door: two-way

Blast Radius: core, CLI, Action users

A build or workflow that relied on an empty glob succeeding will now fail. That is the intended fix, but the release notes should say so. Changeset: @node-minify/core patch.


Summary by cubic

Fails minify() when a wildcard input matches no file, so a typo'ed glob or empty build directory no longer looks like success. Previously an unmatched glob reached the compressors as input: [], resolved a $1 output to an empty string and wrote nothing, or failed with No content provided for a plain output; both cases now throw No files matched input pattern: <pattern>.

  • Uses the same * wildcard detection that wildcards() uses to decide whether to glob.
  • Explicit empty input arrays and in-memory content are unaffected, as are non-glob missing files such as missing.js.
  • Breaking for builds that relied on an empty glob succeeding; the changeset marks @node-minify/core as a patch.