Skip to content

Commit

Permalink
Fix .add() returning promise & other type issues. Update anymatch.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Jul 7, 2019
1 parent 589cb02 commit 5363bbe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
18 changes: 10 additions & 8 deletions index.js
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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));
});
});
}

Expand Down
4 changes: 2 additions & 2 deletions lib/fsevents-handler.js
Expand Up @@ -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<void>}
*/
async _handleFsEventsSymlink(linkPath, fullPath, transform, curDepth) {
// don't follow the same symlink more than once
Expand Down Expand Up @@ -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<void>}
*/
async _addToFsEvents(path, transform, forceAdd, priorDepth) {
if (this.fsw.closed) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down

0 comments on commit 5363bbe

Please sign in to comment.