Fix: Use chokidar for consistent glob pattern matching in build mode#23
Open
reebalazs wants to merge 4 commits intozth:rescriptfrom
Open
Fix: Use chokidar for consistent glob pattern matching in build mode#23reebalazs wants to merge 4 commits intozth:rescriptfrom
reebalazs wants to merge 4 commits intozth:rescriptfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #21
Problem
Build mode silently processes zero files when using extglob patterns like
(src|__tests__)insrcDir, 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 |
globSyncfromglob| Literal string (finds nothing) || Watch |
chokidar(uses picomatch) | Extglob "OR" pattern (works) |This caused confusing behavior where
--watchwould find and process files, but running without--watchwould silently succeed with no output.Example
{ "srcDir": "./(src|__tests__)/**/*" }pgtyped-rescript -c config.json --watch→ finds files in bothsrc/and__tests__/pgtyped-rescript -c config.json→ finds 0 files, exits silentlySolution
Use chokidar for file matching in both modes. This ensures consistent glob pattern interpretation regardless of whether watch mode is enabled.
Changes
Replaced
globSyncwith chokidar-basedgetMatchedFilesinpackages/cli/src/index.tsgetMatchedFiles()function that uses chokidar withpersistent: falseglobpackage dependency for file matchingAdded comprehensive tests in
packages/cli/src/glob.rescript.test.ts(src|__tests__)syntax{src,__tests__}syntaxTest plan