addDirectory(root) {
        debug("Watcher#addDirectory", root)
        return walkDirectories(
            root,
            this.dereference,
            co.wrap(
                function*(dirPath, files) {
                    if (this.trigger == null || this.watchers.has(dirPath)) {
                        return
                    }

                    // Skip the content of symbolic links by default.
                    if (
                        !this.dereference &&
                        (yield fs.lstat(dirPath)).isSymbolicLink()
                    ) {
                        this.onAdded(dirPath)
                        return
                    }

                    // Start watching.
                    const watcher = fs
                        .watch(dirPath)
                        .on("change", (type, filename) => {
                            debug(
                                "Watcher~watcher onchange",
                                type,
                                dirPath,
                                filename
                            )
                            if (filename == null) {
                                return
                            }
                            const sourcePath = normalizePath(
                                path.join(dirPath, filename)
                            )

                            fs.stat(sourcePath).then(
                                stat => {
                                    this.classifyFileChange(
                                        files,
                                        sourcePath,
                                        stat
                                    )
                                },
                                error => {
                                    if (error.code === "ENOENT") {
                                        this.classifyFileChange(
                                            files,
                                            sourcePath,
                                            null
                                        )
                                    } else {
                                        this.onError(error)
                                    }
                                }
                            )
                        })
                        .on("error", error => {
                            debug("Watcher~watcher onerror", dirPath, error)
                            this.removeDirectory(dirPath)
                        })
                    this.watchers.set(dirPath, { watcher, files })

                    // Emit "added" events.
                    this.onAdded(dirPath)
                    for (const entry of files.entries()) {
                        const filePath = entry[0]
                        const stat = entry[1]

                        if (!stat.isDirectory()) {
                            this.onAdded(filePath)
                        }
                    }
                }.bind(this)
            )
        )
    }
/**
     * Start watching the files of the given directory.
     * @param {string} root The path to the root directory to watch.
     * @returns {Promise<void>} The promise which will go fulfilled after done.
     * @private
     */
Start watching the files of the given directory.
@param {string} root The path to the root directory to watch.
@returns {Promise} The promise which will go fulfilled after done.
@private
Start watching the files of the given directory . @param { string } root The path to the root directory to watch . @returns { Promise } The promise which will go fulfilled after done . @private
addDirectory(root) {
        debug("Watcher#addDirectory", root)
        return walkDirectories(
            root,
            this.dereference,
            co.wrap(
                function*(dirPath, files) {
                    if (this.trigger == null || this.watchers.has(dirPath)) {
                        return
                    }
                    if (
                        !this.dereference &&
                        (yield fs.lstat(dirPath)).isSymbolicLink()
                    ) {
                        this.onAdded(dirPath)
                        return
                    }
                    const watcher = fs
                        .watch(dirPath)
                        .on("change", (type, filename) => {
                            debug(
                                "Watcher~watcher onchange",
                                type,
                                dirPath,
                                filename
                            )
                            if (filename == null) {
                                return
                            }
                            const sourcePath = normalizePath(
                                path.join(dirPath, filename)
                            )
                            fs.stat(sourcePath).then(
                                stat => {
                                    this.classifyFileChange(
                                        files,
                                        sourcePath,
                                        stat
                                    )
                                },
                                error => {
                                    if (error.code === "ENOENT") {
                                        this.classifyFileChange(
                                            files,
                                            sourcePath,
                                            null
                                        )
                                    } else {
                                        this.onError(error)
                                    }
                                }
                            )
                        })
                        .on("error", error => {
                            debug("Watcher~watcher onerror", dirPath, error)
                            this.removeDirectory(dirPath)
                        })
                    this.watchers.set(dirPath, { watcher, files })
                    this.onAdded(dirPath)
                    for (const entry of files.entries()) {
                        const filePath = entry[0]
                        const stat = entry[1]
                        if (!stat.isDirectory()) {
                            this.onAdded(filePath)
                        }
                    }
                }.bind(this)
            )
        )
    }
addDirectory ( root ) { debug ( "Watcher#addDirectory" , root ) return walkDirectories ( root , this . dereference , co . wrap ( function * ( dirPath , files ) { if ( this . trigger == null || this . watchers . has ( dirPath ) ) { return } if ( ! this . dereference && ( yield fs . lstat ( dirPath ) ) . isSymbolicLink ( ) ) { this . onAdded ( dirPath ) return } const watcher = fs . watch ( dirPath ) . on ( "change" , ( type , filename ) => { debug ( "Watcher~watcher onchange" , type , dirPath , filename ) if ( filename == null ) { return } const sourcePath = normalizePath ( path . join ( dirPath , filename ) ) fs . stat ( sourcePath ) . then ( stat => { this . classifyFileChange ( files , sourcePath , stat ) } , error => { if ( error . code === "ENOENT" ) { this . classifyFileChange ( files , sourcePath , null ) } else { this . onError ( error ) } } ) } ) . on ( "error" , error => { debug ( "Watcher~watcher onerror" , dirPath , error ) this . removeDirectory ( dirPath ) } ) this . watchers . set ( dirPath , { watcher , files } ) this . onAdded ( dirPath ) for ( const entry of files . entries ( ) ) { const filePath = entry [ 0 ] const stat = entry [ 1 ] if ( ! stat . isDirectory ( ) ) { this . onAdded ( filePath ) } } } . bind ( this ) ) ) }
Start watching the files of the given directory.
Start watching the files of the given directory .
// Skip the content of symbolic links by default. // Start watching. // Emit "added" events.