diff --git a/index.js b/index.js index f06e0f0b..5755249a 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ const EventEmitter = require('events').EventEmitter; const fs = require('fs'); const sysPath = require('path'); const readdirp = require('readdirp'); -const anymatch = require('anymatch'); +const anymatch = require('anymatch').default; const globParent = require('glob-parent'); const isGlob = require('is-glob'); const braces = require('braces'); @@ -186,7 +186,8 @@ class WatchHelper { const {stats} = entry; if (stats && stats.isSymbolicLink()) return this.filterDir(entry); const resolvedPath = this.entryPath(entry); - const matchesGlob = this.hasGlob ? this.globFilter(resolvedPath) : true; + const matchesGlob = this.hasGlob && typeof this.globFilter === 'function' ? + this.globFilter(resolvedPath) : true; return matchesGlob && this.fsw._isntIgnored(resolvedPath, stats) && this.fsw._hasReadPermissions(stats); @@ -354,7 +355,7 @@ _normalizePaths(paths_) { * @param {Boolean=} _internal private; indicates a non-user add * @returns {FSWatcher} for chaining */ -async add(paths_, _origAdd, _internal) { +add(paths_, _origAdd, _internal) { const {cwd, disableGlobbing} = this.options; this.closed = false; @@ -401,16 +402,17 @@ async add(paths_, _origAdd, _internal) { } else { if (!this._readyCount) this._readyCount = 0; this._readyCount += paths.length; - const results = await Promise.all( + Promise.all( paths.map(async path => { const res = await this._nodeFsHandler._addToNodeFs(path, !_internal, 0, 0, _origAdd); if (res) this._emitReady(); return res; }) - ); - results.forEach((item) => { - if (!item || this.closed) return; - this.add(sysPath.dirname(item), sysPath.basename(_origAdd || item)); + ).then(results => { + if (this.closed) return; + results.filter(item => item).forEach(item => { + this.add(sysPath.dirname(item), sysPath.basename(_origAdd || item)); + }); }); } diff --git a/lib/fsevents-handler.js b/lib/fsevents-handler.js index 50b147d6..41caf811 100644 --- a/lib/fsevents-handler.js +++ b/lib/fsevents-handler.js @@ -326,7 +326,7 @@ _watchWithFsEvents(watchPath, realPath, transform, globFilter) { * @param {String} fullPath absolute path to the symlink * @param {Function} transform pre-existing path transformer * @param {Number} curDepth level of subdirectories traversed to where symlink is - * @returns {void} + * @returns {Promise} */ async _handleFsEventsSymlink(linkPath, fullPath, transform, curDepth) { // don't follow the same symlink more than once @@ -400,7 +400,7 @@ initWatch(realPath, path, wh, processPath) { * @param {Function|Boolean=} transform converts working path to what the user expects * @param {Boolean=} forceAdd ensure add is emitted * @param {Number=} priorDepth Level of subdirectories already traversed. - * @returns {void} + * @returns {Promise} */ async _addToFsEvents(path, transform, forceAdd, priorDepth) { if (this.fsw.closed) { diff --git a/package.json b/package.json index 9d57e481..b7cd4147 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "node": ">= 8" }, "dependencies": { - "anymatch": "^3.0.1", + "anymatch": "^3.0.3", "braces": "^3.0.2", "glob-parent": "^5.0.0", "is-binary-path": "^2.1.0",