au run --watch not picking up changes
See original GitHub issueI’m submitting a bug report
- Library Version: 0.30.0
Please tell us about your environment:
-
Operating System: Windows 10
-
Node Version: 6.11.0
-
NPM Version: 5.0.3
-
Browser: n/a
-
Language: TypeScript
Behavior:
au run --watch
periodically stops seeing changes. I noticed this particularly with .html files, and more-so in the deepest folder paths. Unfortunately reproduction of this issue is not reliable. I have done a lot of console.log in various libraries and believe I have a cause.
The underlying watcher library chokidar (v1.7.0) has a cache of watched directories stored in this._watched
and accessed via this._getWatchedDir
in index.js line 467. When handling a directory (nodefs-handler.js _handleDir
) it calls the above on line 352: var previous = this._getWatchedDir(wh.path);
. After an async readdirp
it uses that variable at line 373: previous.has(item)
. If that returns true then the condition which recurses the directories (via _addToNodeFs()
) is skipped. If the same folder is traversed by multiple root watches, then that call may retrieve the directory information generated when starting from a different root, and thus a later traversal will skip the folder.
I believe this explains the intermittentness and why it seemed worse at deeper paths: there is an async time delay between reading previous and using it and the probability of the path already being read increases over time. It would also explain why mostly html but occasionally ts files were affect, but scss files were not: html and ts files share directories.
The solution to this is to create one watcher object per glob rather than pass all of them together as occurs in watch.ts:
return gulpWatch(
Object.keys(watches),
{
read: false, // performance optimization: do not read actual file contents
verbose: true
},
The globs from Object.keys(watches) are passed via gulpWatch to chokidar.watch, creating only one instance of chokidar.
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (5 by maintainers)
Also, @winterlimelight thanks for getting to the bottom of this!
Nice. Thanks for reporting back @winterlimelight