fix: Fixed --watch-file being ignored for hidden files - #3837
Open
MaxFreedomPollard wants to merge 1 commit into
Open
MaxFreedomPollard wants to merge 1 commit into
MaxFreedomPollard wants to merge 1 commit into
Conversation
Every Watchpack change event went through shouldWatchFile, which the runner binds to the source directory's FileFilter, and its base patterns ignore '**/.*'. A reload requested with --watch-file .build-finished was therefore dropped with only a debug-level log line, and the same happened for a watched zip or a file under node_modules. The --watch-file entries are now resolved up front and a change to one of them is always proxied through. The artifacts directory check and watcher-level exclusions such as --watch-ignored are unchanged.
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.
Fixes #2282.
web-ext run --watch-file .build-finishednever reloads the extension. web-ext accepts the option and then silently does nothing: every change event is dropped, with only a debug-level line to show for it. Touching a sentinel file when an external build finishes is the documented reason to use --watch-file, and sentinel files are usually hidden, so this is the common case rather than an edge case.Every change event Watchpack emits is passed through shouldWatchFile in src/watcher.js, including events for the files the user named. src/extension-runners/index.js binds shouldWatchFile to the source directory's FileFilter, and the base ignore patterns in src/util/file-filter.js include
**/.*, so proxyFileChanges discards the change and only writes "Ignoring change to:" at debug level. The same thing happens to a watched*.zipor*.xpiand to anything undernode_modules, because those patterns sit in the same list.The fix resolves the --watch-file entries once and lets a change to one of them through whatever the filter says. That also beats the user's own --ignore-files patterns for those exact paths, which seems right since naming a single file with --watch-file is the more specific instruction, but it is worth stating rather than leaving to be discovered. Everything else is left alone: the artifacts directory check in proxyFileChanges is untouched, and exclusions that apply at the watcher level, such as --watch-ignored, are untouched because those paths are never watched in the first place. That last point is also why this stays compatible with the
_metadataexclusion in open PR #3696, which lives in Watchpack's ignored list and not in the filter; #3696 also edits the same watchChange test helper, so whichever lands second needs a small rebase.Two notes on scope. The bug only bites when the watched file is inside sourceDir, since the filter resolves its patterns against sourceDir, and the default sourceDir is the current directory, which is the situation in the issue. The reporter also suggested the opposite resolution, rejecting dot files in --watch-file with an error instead; reloading looks clearly more useful, but say so if you prefer the error.
Two unit tests cover this, both in the --watch-file block and both built on the real FileFilter: one touches a watched .build-finished, one touches a watched build.zip. The shared watchChange helper hardcoded shouldWatchFile as () => true, which is why no test ever exercised this interaction, so it now takes a filter factory and the existing cases keep their old behaviour. Both new tests fail on master. The watcher unit tests, eslint and prettier --check pass on the two changed files.