Skip to content

fix: use chokidar for reliable cross-platform file watching#14

Merged
kjellberg merged 1 commit into
kiqr:mainfrom
kjellbergzoey:fix/chokidar-file-watcher
Jun 7, 2026
Merged

fix: use chokidar for reliable cross-platform file watching#14
kjellberg merged 1 commit into
kiqr:mainfrom
kjellbergzoey:fix/chokidar-file-watcher

Conversation

@kjellbergzoey

Copy link
Copy Markdown
Contributor

Summary

Replaces Node's fs.watch({recursive: true}) with chokidar in src/lib/watch.ts for reliable cross-platform file watching.

Why

fs.watch's recursive option is not reliably supported across platforms. On some Linux kernels recursive watching of nested directories is unsupported or flaky, so file changes in subdirectories (e.g. src/components/Header.php) could be silently missed during kiqr watch. chokidar handles recursive watching consistently across macOS, Linux, and Windows.

What changed

  • createFileWatcher now uses chokidar.watch, listening to its native add / change / unlink events — which map directly onto the existing FileChangeCallback.
  • Public API is unchanged: same signature, same returned {stop} shape, same options (extension filtering, debounce, ignore patterns). src/commands/watch.tsx needs no changes.
  • getRelativePath is untouched.
  • Ignore patterns are applied via chokidar's ignored predicate (so it won't even descend into node_modules, .git, etc.) while preserving the existing regex/string-array ignored option.

Tests

tests/lib/watch.test.ts updated to run against real temp-dir filesystem events with chokidar timing, and a new test verifies detection of files created in nested subdirectories.

  • npm run typecheck
  • npm test ✅ (71 tests, 14 files)
  • npm run build

🤖 Generated with Claude Code

Replace Node's fs.watch({recursive:true}) with chokidar in
createFileWatcher. fs.watch recursive mode is not reliably supported
across platforms (notably nested directories on some Linux kernels),
so changes in subdirectories could be silently missed.

chokidar emits add/change/unlink events directly, which map onto the
existing FileChangeCallback, so the public API (signature, returned
{stop} shape, extension filtering, debounce, and ignore patterns) is
unchanged and src/commands/watch.tsx needs no modification.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@kjellberg
kjellberg merged commit 3cdcb73 into kiqr:main Jun 7, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants