From 7d943ef1f2a1c5f0d4a2f306b382ef3a23e44d40 Mon Sep 17 00:00:00 2001 From: wannabesrevenge Date: Sun, 25 Mar 2018 22:00:58 -0500 Subject: [PATCH] Stop walk from descending into next directory Added ability to stop the walk from descending into a given directory. You use this by calling in either the 'directory' or 'name' event handler. This will prevent the directory from being traversed. --- lib/node-type-emitter.js | 6 +++++- lib/walk.js | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/node-type-emitter.js b/lib/node-type-emitter.js index 9a1e01c..2d9a236 100644 --- a/lib/node-type-emitter.js +++ b/lib/node-type-emitter.js @@ -47,7 +47,11 @@ function emitSingleEvents(emitter, path, stats, next, self) { var num = 1 + emitter.listeners(stats.type).length + emitter.listeners("node").length; - function nextWhenReady() { + function nextWhenReady(flag) { + if (flag) { + stats.flag = flag; + flagSet = flag; + } num -= 1; if (0 === num) { next.call(self); } } diff --git a/lib/walk.js b/lib/walk.js index 93c40ed..ee8ade5 100644 --- a/lib/walk.js +++ b/lib/walk.js @@ -14,6 +14,7 @@ function appendToDirs(stat) { /*jshint validthis:true*/ + if(stat.flag && stat.flag === NO_DESCEND) { return; } this.push(stat.name); }