Skip to content

Glob patterns that match no tasks now succeed silently#226

Merged
bcomnes merged 2 commits into
masterfrom
feature/silent-glob-no-match
May 18, 2026
Merged

Glob patterns that match no tasks now succeed silently#226
bcomnes merged 2 commits into
masterfrom
feature/silent-glob-no-match

Conversation

@bcomnes

@bcomnes bcomnes commented May 17, 2026

Copy link
Copy Markdown
Owner

Summary

  • Glob patterns (containing *, ?, [, or {) that match no npm scripts now exit with code 0 instead of throwing Task not found.
  • Literal task names that don't exist still throw as before.
  • Updated the '"!test-task:**" should not match to anything' test suite to expect silent success.
  • Added a new '"nonexistent:*" is a glob that matches nothing' test suite covering all four CLI entry points.

Why

Discussed in #149. A common pattern is to scaffold standardized package.json scripts up-front (e.g. "lint": "run-p 'lint:*'") before any sub-scripts exist, so new packages pass CI out of the box. The current error made that impossible without a placeholder script hack.

The owner's conclusion was to treat this as a small breaking change rather than add a flag — matching how array methods behave on empty inputs (no error, just no work done).

Reviewer notes

  • The change is entirely in lib/match-tasks.js. A GLOB_CHARS regex detects wildcard patterns; non-glob patterns that resolve to nothing still throw.
  • The built-in restart/env task allowlist is unaffected.

Closes #149

Treat a wildcard pattern (containing *, ?, [, or {) that resolves to
zero tasks as a no-op rather than an error. This mirrors how iterating
over an empty array works, and makes it safe to write `run-p 'lint:*'`
in a new package before any lint sub-scripts exist.

Literal task names that don't exist still throw "Task not found".

Closes #149
Copilot AI review requested due to automatic review settings May 17, 2026 22:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates task-pattern matching so glob-like patterns that match no npm scripts do not error, aligning behavior with common scaffolding workflows discussed in #149.

Changes:

  • Add glob-character detection to distinguish globs vs literal task names when no tasks match.
  • Skip “Task not found” errors for glob patterns that resolve to an empty match set.
  • Update/add tests to expect silent success for unmatched glob patterns across entry points.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
test/pattern.js Updates existing suite to expect silent success for an unmatched glob; adds coverage for another unmatched glob across all entry points.
lib/match-tasks.js Introduces isGlob detection and uses it to suppress unknown-task errors when a glob matches nothing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/match-tasks.js Outdated
Comment thread lib/match-tasks.js
Comment thread test/pattern.js
Comment thread test/pattern.js Outdated
- Replace the hand-rolled GLOB_CHARS regex with picomatch.scan(pattern).isGlob
  so glob detection stays consistent with picomatch's own parsing rules
  (handles escaped chars, extglobs, etc.)
- Capture stderr in the new CLI test cases and assert it's empty to
  confirm the silent-success behaviour produces no output
@bcomnes

bcomnes commented May 18, 2026

Copy link
Copy Markdown
Owner Author

I think this is generally a good change.

@bcomnes bcomnes merged commit 730c02b into master May 18, 2026
15 checks passed
@bcomnes bcomnes deleted the feature/silent-glob-no-match branch May 18, 2026 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request : Add an option to skip script not found error

2 participants