@@ -74,8 +74,11 @@ module.exports = function (globs, opts, cb) {
7474
7575 outputStream . _read = function _read ( ) { } ;
7676
77- var watcher = chokidar . watch ( globs , opts )
78- . on ( 'all' , processEvent ) ;
77+ var watcher = chokidar . watch ( globs , opts ) ;
78+
79+ opts . events . forEach ( function ( ev ) {
80+ watcher . on ( ev , processEvent . bind ( undefined , ev ) ) ;
81+ } ) ;
7982
8083 [ 'add' , 'change' , 'unlink' , 'addDir' , 'unlinkDir' , 'error' , 'ready' , 'raw' ]
8184 . forEach ( function ( ev ) {
@@ -95,21 +98,25 @@ module.exports = function (globs, opts, cb) {
9598 } ;
9699
97100 function processEvent ( event , filepath ) {
98- var glob = globs [ anymatch ( globs , filepath , true ) ] ;
101+ var glob ;
102+ var currentFilepath = filepath ;
103+ while ( ! ( glob = globs [ anymatch ( globs , currentFilepath , true ) ] ) && currentFilepath !== ( currentFilepath = path . resolve ( currentFilepath , '..' ) ) ) { } // eslint-disable-line no-empty-blocks/no-empty-blocks
99104
100105 if ( ! glob ) {
106+ util . log (
107+ util . colors . cyan ( '[gulp-watch]' ) ,
108+ util . colors . yellow ( 'wut? This shouldn\'t happen. Please open this link to report the issue:\n' ) +
109+ 'https://github.com/floatdrop/gulp-watch/issues/new?title=' +
110+ encodeURIComponent ( 'Watched unexpected filepath' ) + '&body=' +
111+ encodeURIComponent ( 'Globs: `' + JSON . stringify ( globs ) + '`\nFilepath: `' + filepath + '`\nOptions:\n```js\n' + JSON . stringify ( opts , null , 2 ) + '\n```' )
112+ ) ;
101113 return ;
102114 }
103115
104116 if ( ! baseForced ) {
105117 opts . base = glob2base ( new Glob ( glob ) ) ;
106118 }
107119
108- // React only on opts.events
109- if ( opts . events . indexOf ( event ) === - 1 ) {
110- return ;
111- }
112-
113120 // Do not stat deleted files
114121 if ( event === 'unlink' || event === 'unlinkDir' ) {
115122 opts . path = pathIsAbsolute ( filepath ) ? filepath : path . join ( opts . cwd || process . cwd ( ) , filepath ) ;
0 commit comments