fix(watch): resolve relative --exclude patterns to absolute paths#805
Open
chatman-media wants to merge 1 commit into
Open
fix(watch): resolve relative --exclude patterns to absolute paths#805chatman-media wants to merge 1 commit into
chatman-media wants to merge 1 commit into
Conversation
Chokidar's normalizeIgnored() resolves relative ignore patterns to absolute paths by joining with the watcher's cwd option. For a pattern like `../sibling/**`, the resulting absolute path is then tested against absolute dep paths, which works correctly. However, relying on chokidar's implicit resolution was fragile: the behavior depends on the cwd being set consistently, and on Windows the path-separator normalization in chokidar's pipe may produce mismatches. Pre-resolving `../`- and `./`-prefixed patterns to absolute paths in tsx makes the intent explicit and platform-independent. Pure glob patterns (e.g., `**/*.ts`) that don't start with a relative directory prefix are left unchanged so they continue to match cwd-relative paths as before. Closes privatenumber#785
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.
Closes #785
Root cause
tsx watch --exclude "../reactapp/**/*.mjs"relies on chokidar to resolve the relative pattern against the watcher'scwd. Internally, chokidar'snormalizeIgnored(cwd)joins the pattern withcwdto produce an absolute path, then uses anymatch to test absolute dependency paths.While this resolution works on macOS/Linux for well-formed
../patterns, pre-resolving in tsx is more reliable and platform-independent. On Windows, path-separator normalization in chokidar's pipeline can introduce mismatches between the resolved pattern and the absolute path of a dependency. Explicit pre-resolution removes that ambiguity.Fix
In
src/watch/index.ts, exclude patterns that begin with../or./are resolved to absolute paths viapath.resolve(process.cwd(), pattern)before being passed to chokidar'signoredoption.Pure glob patterns (
**/*.ts,node_modules/**, etc.) are left unchanged so they continue to match cwd-relative paths as before.Verification
Added a regression test in
tests/specs/watch.ts(exclude (ignore) › parent/adjacent directory) that:app/index.tsimporting from../sibling/dep.tstsx watch --exclude=../sibling/** index.tsfrom theapp/directorysibling/dep.tsand asserts that no restart is triggeredThe test passes with the fix and the existing test suite (207 passing) shows no regressions.
🤖 Generated with Claude Code