Skip to content

fix: watching files outside cwd #5375

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mark-wiemer
Copy link
Member

PR Checklist

Overview

In #5256 we changed the watched path from watchFiles to . (cwd). Nobody commented on this, and it broke this behavior. Reverting that line fixes the reported issue in the provided repro

@mark-wiemer mark-wiemer changed the title Fix: watching files outside cwd fix: watching files outside cwd Jun 12, 2025
@mark-wiemer
Copy link
Member Author

Draft until:

  • tests added
  • understand why we may have wanted to make the reverted change in the first place (or confident that it was a mistake)

@mark-wiemer
Copy link
Member Author

@mochajs/maintenance-crew would appreciate your insights here, looks like this was a recently-introduced bug but I'm certainly no expert :)

@voxpelli
Copy link
Member

I'm no expert on this either but it looks sensible as a fix

@voxpelli voxpelli requested a review from Copilot June 12, 2025 07:44
Copilot

This comment was marked as outdated.

@voxpelli voxpelli requested a review from Copilot June 12, 2025 07:44
Copy link

@Copilot 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 restores the original watched path logic so that file patterns specified via --watch-files can include files outside the current working directory.

Comments suppressed due to low confidence (2)

lib/cli/watch-run.js:210

  • Add or update tests to ensure that files outside the current working directory are being watched correctly, verifying the behavior introduced by this change.
const watcher = chokidar.watch(watchFiles, {

lib/cli/watch-run.js:210

  • [nitpick] Ensure that watchFiles is normalized to a string or array of strings accepted by chokidar; if it's a single glob string, consider wrapping it in an array for consistent behavior.
const watcher = chokidar.watch(watchFiles, {

@@ -207,7 +207,7 @@ const createWatcher = (
const tracker = new GlobFilesTracker(watchFiles, watchIgnore);
tracker.regenerate();

const watcher = chokidar.watch('.', {
const watcher = chokidar.watch(watchFiles, {
ignoreInitial: true
Copy link
Preview

Copilot AI Jun 12, 2025

Choose a reason for hiding this comment

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

Consider forwarding the watchIgnore patterns to chokidar.watch via the ignored option to prevent watching ignored files at all, improving efficiency.

Suggested change
ignoreInitial: true
ignoreInitial: true,
ignored: watchIgnore

Copilot uses AI. Check for mistakes.

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.

🐛 Bug: watching files outside of CWD is broken
2 participants