@@ -126,13 +126,16 @@ function debounceFileChanges<T>(callback: (files: T[]) => Promise<void> | void,
126126 return function ( path : T ) {
127127 // Already tracked as changed, ignore
128128 if ( collectedPaths . includes ( path ) ) {
129+ debug ( 'Ignoring pending file change for path %s' , path ) ;
129130 return ;
130131 }
131132
133+ debug ( 'Debouncing change for path %s' , path ) ;
132134 collectedPaths . push ( path ) ;
133135
134136 clearTimeout ( timeoutId ) ;
135137 timeoutId = setTimeout ( ( ) => {
138+ debug ( 'Firing debounced file' ) ;
136139 callback ( collectedPaths ) ;
137140 collectedPaths = [ ] ;
138141 } , delayMs ) ;
@@ -226,12 +229,18 @@ export class Files {
226229 const collector = debounceFileChanges ( onFilesChanged , 500 ) ;
227230
228231 const onChange = async ( path : string ) => {
232+ debug ( 'Have file changes: %s' , path ) ;
229233 collector ( path ) ;
230234 } ;
231235 let matcher : Matcher | undefined ;
232236 if ( ignorePatterns && ignorePatterns . length ) {
233- matcher = file => {
234- return micromatch . not ( [ file ] , ignorePatterns , { dot : true } ) . length === 0 ;
237+ matcher = ( file , stats ) => {
238+ if ( ! stats ?. isFile ( ) ) {
239+ return false ;
240+ }
241+ file = path . relative ( this . options . files . projectRootDir , file ) ;
242+ const ignore = micromatch . not ( [ file ] , ignorePatterns , { dot : true } ) . length === 0 ;
243+ return ignore ;
235244 } ;
236245 }
237246 const watcher = chokidar . watch ( this . options . files . contentDir , {
@@ -244,8 +253,13 @@ export class Files {
244253 watcher . on ( 'add' , onChange ) ;
245254 watcher . on ( 'change' , onChange ) ;
246255 watcher . on ( 'unlink' , onChange ) ;
247-
248- return async ( ) => await watcher . close ( ) ;
256+ watcher . on ( 'error' , err => {
257+ debug ( 'Unexpected error during watch: %O' , err ) ;
258+ } ) ;
259+ return async ( ) => {
260+ debug ( 'Stopping watch' ) ;
261+ await watcher . close ( ) ;
262+ } ;
249263 }
250264
251265 async getChangedFiles ( ) : Promise < ProjectFile [ ] > {
0 commit comments