@@ -392,7 +392,8 @@ class DirectoryWatcher extends EventEmitter {
392392 const checkStats = ( ) => {
393393 if ( this . closed ) return ;
394394 this . _activeEvents . set ( filename , false ) ;
395- fs . lstat ( filePath , ( err , stats ) => {
395+
396+ const handleStats = ( err , stats ) => {
396397 if ( this . closed ) return ;
397398 if ( this . _activeEvents . get ( filename ) === true ) {
398399 process . nextTick ( checkStats ) ;
@@ -438,8 +439,15 @@ class DirectoryWatcher extends EventEmitter {
438439 false ,
439440 eventType
440441 ) ;
442+ if (
443+ this . watcherManager . options . followSymlinks &&
444+ stats . isSymbolicLink ( )
445+ ) {
446+ fs . stat ( filePath , handleStats ) ;
447+ }
441448 }
442- } ) ;
449+ } ;
450+ fs . lstat ( filePath , handleStats ) ;
443451 } ;
444452 process . nextTick ( checkStats ) ;
445453 } else {
@@ -625,7 +633,7 @@ class DirectoryWatcher extends EventEmitter {
625633 }
626634 } ) ;
627635 for ( const itemPath of itemPaths ) {
628- fs . lstat ( itemPath , ( err2 , stats ) => {
636+ const handleStats = ( err2 , stats ) => {
629637 if ( this . closed ) return ;
630638 if ( err2 ) {
631639 if (
@@ -652,6 +660,12 @@ class DirectoryWatcher extends EventEmitter {
652660 true ,
653661 "scan (file)"
654662 ) ;
663+ if (
664+ this . watcherManager . options . followSymlinks &&
665+ stats . isSymbolicLink ( )
666+ ) {
667+ fs . stat ( itemPath , handleStats ) ;
668+ }
655669 } else if ( stats . isDirectory ( ) ) {
656670 if ( ! initial || ! this . directories . has ( itemPath ) )
657671 this . setDirectory (
@@ -662,7 +676,8 @@ class DirectoryWatcher extends EventEmitter {
662676 ) ;
663677 }
664678 itemFinished ( ) ;
665- } ) ;
679+ } ;
680+ fs . lstat ( itemPath , handleStats ) ;
666681 }
667682 itemFinished ( ) ;
668683 } ) ;
0 commit comments