import * as chokidar from 'chokidar' ; import { ConsoleInterface } from './console' ; import { FileWatcher , FileWatcherEventHandler , FileWatcherEventType , FileWatcherProvider } from './fileSystem' ; const _isMacintosh = process . platform === 'darwin' ; const _isLinux = process . platform === 'linux' ; export class ChokidarFileWatcherProvider implements FileWatcherProvider { constructor ( private _console ? ) { } createFileWatcher ( paths , listener ) { return this . _createFileSystemWatcher ( paths ) . on ( 'all' , listener ) ; } private _createFileSystemWatcher ( paths ) { const watcherOptions = { ignoreInitial : true , ignorePermissionErrors : true , followSymlinks : true , interval : 1000 , binaryInterval : 1000 , disableGlobbing : true , awaitWriteFinish : { stabilityThreshold : 1000 , pollInterval : 1000 , } , } ; if ( _isMacintosh ) { watcherOptions . usePolling = false ; } const excludes = [ '**/__pycache__/**' ] ; if ( _isMacintosh || _isLinux ) { if ( paths . some ( ( path ) => path === '' || path === '/' ) ) { excludes . push ( '/dev/**' ) ; if ( _isLinux ) { excludes . push ( '/proc/**' , '/sys/**' ) ; } } } watcherOptions . ignored = excludes ; const watcher = chokidar . watch ( paths , watcherOptions ) ; watcher . on ( 'error' , ( _ ) => { this . _console ?. error ( 'Error returned from file system watcher.' ) ; } ) ; if ( _isMacintosh && ! watcher . options . useFsEvents ) { this . _console ?. info ( 'Watcher could not use native fsevents library. File system watcher disabled.' ) ; } return watcher ; } onFileChange ( _1 , _2 ) { } }