Skip to content

Conversation

@reebalazs
Copy link

Fixes #21

Problem

Build mode silently processes zero files when using extglob patterns like (src|__tests__) in srcDir, while watch mode works correctly with the same pattern.

Root Cause

The CLI used two different glob libraries with incompatible pattern support:

| Mode | Library | (src|__tests__) interpretation |
|------|---------|----------------------------------|
| Build | globSync from glob | Literal string (finds nothing) |
| Watch | chokidar (uses picomatch) | Extglob "OR" pattern (works) |

This caused confusing behavior where --watch would find and process files, but running without --watch would silently succeed with no output.

Example

{
  "srcDir": "./(src|__tests__)/**/*"
}
  • pgtyped-rescript -c config.json --watch → finds files in both src/ and __tests__/
  • pgtyped-rescript -c config.json → finds 0 files, exits silently

Solution

Use chokidar for file matching in both modes. This ensures consistent glob pattern interpretation regardless of whether watch mode is enabled.

Changes

  1. Replaced globSync with chokidar-based getMatchedFiles in packages/cli/src/index.ts

    • Added async getMatchedFiles() function that uses chokidar with persistent: false
    • Removed glob package dependency for file matching
  2. Added comprehensive tests in packages/cli/src/glob.rescript.test.ts

    • Tests for simple srcDir patterns
    • Tests for extglob (src|__tests__) syntax
    • Tests for brace expansion {src,__tests__} syntax
    • Tests for embedded wildcards
    • Tests for empty directory handling

Test plan

  • All existing tests pass
  • New glob pattern tests pass (5 tests)
  • Manual test: verify build mode works with extglob patterns

Test shows that parentheses syntax (src|__tests__) silently fails
with glob but works with chokidar (watch mode). The glob package
treats it as a literal string while chokidar interprets it as an
extglob pattern.
Replace globSync with chokidar-based file matching to ensure
consistent pattern handling between watch and build modes.

Chokidar (via picomatch) supports extglob patterns like (src|__tests__)
while the glob package treats them as literal strings, causing silent
failures when no files match.
Tests now verify that:
- Parentheses extglob syntax (src|__tests__) works with chokidar
- Both brace {a,b} and extglob (a|b) patterns are supported
- Documents the glob vs chokidar behavior difference
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.

Inconsistent pattern evaluation between build and watch modes

1 participant