-
Notifications
You must be signed in to change notification settings - Fork 477
Watch folders based on BuildState #8219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR changes the file watching strategy from watching the entire project directory recursively to watching only specific folders based on the build state. This addresses issue #8215 where users with large non-source directories (like .direnv with millions of symlinks) were hitting file watcher limits.
Changes:
- Modified
watcher.rsto compute and watch specific paths (source folders, config files, lib directory) instead of the entire project root - Added logic to re-register watches when
rescript.jsonchanges, ensuring the watch list stays synchronized with the project configuration - Added three new comprehensive tests to verify new file detection, config change handling, and non-source file filtering
- Updated documentation to explain debug logging for watch mode
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| rewatch/src/watcher.rs | Core implementation: added compute_watch_paths, register_watches, and unregister_watches functions; modified watch initialization and rebuild logic to support targeted watching |
| rewatch/tests/watch/03-watch-new-file.sh | Tests that new files created in watched source directories are detected and compiled |
| rewatch/tests/watch/04-watch-config-change.sh | Tests that config changes trigger full rebuilds and watch re-registration |
| rewatch/tests/watch/05-watch-ignores-non-source.sh | Tests that files created outside source directories are correctly ignored |
| rewatch/tests/suite.sh | Added new watch tests and stale process detection |
| AGENTS.md | Added documentation for debug logging in watch mode |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
rescript
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
This fixes the issues I had in #8215. See this comment |
|
@codex review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1760df9ca4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for source in &package.source_folders { | ||
| let dir = package.path.join(&source.dir); | ||
| if !dir.exists() { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Watch missing source dirs to avoid missed recompiles
The new watch list skips configured source folders that don’t exist at startup (if !dir.exists() { continue; }). Because the package root is only watched non-recursively and the event loop ignores non‑ReScript paths, creating that directory later (or adding files inside it) won’t emit any watched events, so new sources in that folder won’t trigger a rebuild until some unrelated full compile happens. This is a regression from the previous recursive watch and affects workflows where a listed source dir or qualified subdir is created after rewatch watch starts.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nojaf Is this a valid concern? Configuring a source folder in rescript.json, then starting a watcher, and only then actually creating the source folder?
Do we already log a warning about the configured, but non-existing source folder elsewhere?
Build/watch probably shouldn't even start if a configured source folder is missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, good catch. The current behaviour was to show a log message.
ERROR:
Could not read folder: "blah". Specified in dependency: foo, located "/Users/nojaf/Projects/foo"...
Restored this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| node -e " | ||
| const fs = require('fs'); | ||
| const config = JSON.parse(fs.readFileSync('$DEP01_CONFIG', 'utf8')); | ||
| config.sources = [{dir: 'nonexistent-folder'}, config.sources]; |
Copilot
AI
Jan 24, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The array construction on line 24 is incorrect. The expression [{dir: 'nonexistent-folder'}, config.sources] creates a two-element array where the second element is the entire original sources array, not a concatenation. This should be [{dir: 'nonexistent-folder'}, ...config.sources] (with spread operator) or [{dir: 'nonexistent-folder'}].concat(config.sources).
| config.sources = [{dir: 'nonexistent-folder'}, config.sources]; | |
| config.sources = [{dir: 'nonexistent-folder'}, ...config.sources]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In dep01/rescript.json, config.sources is a single sourceItem object ({dir: "src", subdirs: true}). So [{dir: 'nonexistent-folder'}, config.sources] produces a valid two-element array of source items — both are objects with dir. This is correct according to the schema.
Instead of watching the entire current directory, I would watch specific folders based on the build state instead.
Could fix #8215
(@cknitt should not block 13 alpha 1, would like to the reporter to test this out first)