Skip to content

Conversation

@nojaf
Copy link
Member

@nojaf nojaf commented Jan 23, 2026

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)

@nojaf nojaf requested a review from Copilot January 23, 2026 14:32
Copy link
Contributor

Copilot AI left a 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.rs to 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.json changes, 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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 23, 2026

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@8219

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@8219

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@8219

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@8219

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@8219

@rescript/runtime

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/runtime@8219

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@8219

commit: 16293b9

@LTibbetts
Copy link

This fixes the issues I had in #8215. See this comment

@nojaf nojaf marked this pull request as ready for review January 23, 2026 20:57
@nojaf nojaf requested a review from cknitt January 23, 2026 20:58
@cknitt
Copy link
Member

cknitt commented Jan 24, 2026

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

Comment on lines 78 to 82
for source in &package.source_folders {
let dir = package.path.join(&source.dir);
if !dir.exists() {
continue;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Contributor

Copilot AI left a 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];
Copy link

Copilot AI Jan 24, 2026

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).

Suggested change
config.sources = [{dir: 'nonexistent-folder'}, config.sources];
config.sources = [{dir: 'nonexistent-folder'}, ...config.sources];

Copilot uses AI. Check for mistakes.
Copy link
Member Author

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.

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.

Rewatch: Watching too many files

3 participants