Does the depth flag work as I'm expecting it to? If I watch directory '/tmp/ryan' and set a depth of 0 or 1, when files change in subdirectory /tmp/ryan/foo/bar, I'm still getting notifications. I just changed your default example in the Readme to include a depth for testing:
var chokidar = require('chokidar');
var watcher = chokidar.watch('/tmp/ryan', {ignored: /[\/\\]\./, persistent: true, depth: 1});
watcher
.on('add', function(path) {console.log('File', path, 'has been added');})
.on('addDir', function(path) {console.log('Directory', path, 'has been added');})
.on('change', function(path) {console.log('File', path, 'has been changed');})
.on('unlink', function(path) {console.log('File', path, 'has been removed');})
.on('unlinkDir', function(path) {console.log('Directory', path, 'has been removed');})
.on('error', function(error) {console.error('Error happened', error);})
.on('ready', function() {console.info('Initial scan complete. Ready for changes.')})
.on('raw', function(event, path, details) {console.info('Raw event info:', event, path, details)})
The depth feature has not been published yet. You'd need to install the git master branch version of the module to use it prior to the upcoming 1.0 release: npm i paulmillr/chokidar
Ah, I've just been wondering why depth didn't work. Hopefully we'll see it released soon!
@es128 Could you clarify if a depth of 0 or 1 means it does not recurse?
0
Setting depth: 0 for watching a folder should not watch for files added to subdirectories. However this only works for the initial scan. If subdirectories are created and files added to the watched folder after the initial scan, they will be reported nonetheless. Is this a bug?
this._watch = chokidar.watch(what, { depth: 0, ignored: /(^|[\/\\])\../ });
this._watch.on("add", path => console.log("new file", path));