is this more what you're looking for?

    // we only want directories, or symlinks to directories
    if (!this._libs.fs.statSync(dir).isDirectory()) {
        return;
    }

(..also move it after the exists() test further down...)