Comparing version 6.0.1 to 6.1.0
43
index.js
@@ -5,3 +5,3 @@ "use strict"; | ||
const {readdirSync, statSync, lstatSync} = require("fs"); | ||
const {join} = require("path"); | ||
const {sep} = require("path"); | ||
const picomatch = require("picomatch"); | ||
@@ -14,3 +14,3 @@ | ||
exclude: [], | ||
include: [], | ||
include: ["**"], | ||
match: { | ||
@@ -25,12 +25,2 @@ dot: true, | ||
function isExcluded(path, matcher) { | ||
if (!matcher) return false; | ||
return matcher(path); | ||
} | ||
function isIncluded(path, entry, matcher) { | ||
if (!matcher || entry.isDirectory()) return true; | ||
return matcher(path); | ||
} | ||
function build(dirent, path, stats) { | ||
@@ -44,4 +34,4 @@ const entry = {path, directory: dirent.isDirectory(), symlink: dirent.isSymbolicLink()}; | ||
return { | ||
includeMatcher: (include && include.length) ? picomatch(include, match) : null, | ||
excludeMatcher: (exclude && exclude.length) ? picomatch(exclude, match) : null, | ||
includeMatcher: picomatch(include, match), | ||
excludeMatcher: picomatch(exclude), | ||
}; | ||
@@ -70,6 +60,5 @@ } | ||
for (const entry of entries) { | ||
const path = join(dir, entry.name); | ||
if (isExcluded(path, excludeMatcher)) continue; | ||
if (!isIncluded(path, entry, includeMatcher)) continue; | ||
await Promise.all(entries.map(async entry => { | ||
const path = `${dir}${sep}${entry.name}`; | ||
if (excludeMatcher(path)) return; | ||
@@ -86,5 +75,5 @@ let stats; | ||
results.push(build(entry, path, stats)); | ||
if (includeMatcher(path)) results.push(build(entry, path, stats)); | ||
if (entry.isDirectory()) results.push(...await rrdir(path, opts, {includeMatcher, excludeMatcher})); | ||
} | ||
})); | ||
@@ -115,5 +104,4 @@ return results; | ||
for (const entry of entries) { | ||
const path = join(dir, entry.name); | ||
if (isExcluded(path, excludeMatcher)) continue; | ||
if (!isIncluded(path, entry, includeMatcher)) continue; | ||
const path = `${dir}${sep}${entry.name}`; | ||
if (excludeMatcher(path)) continue; | ||
@@ -130,3 +118,3 @@ let stats; | ||
results.push(build(entry, path, stats)); | ||
if (includeMatcher(path)) results.push(build(entry, path, stats)); | ||
if (entry.isDirectory()) results.push(...rrdir.sync(path, opts, {includeMatcher, excludeMatcher})); | ||
@@ -158,5 +146,4 @@ } | ||
for (const entry of entries) { | ||
const path = join(dir, entry.name); | ||
if (isExcluded(path, excludeMatcher)) continue; | ||
if (!isIncluded(path, entry, includeMatcher)) continue; | ||
const path = `${dir}${sep}${entry.name}`; | ||
if (excludeMatcher && excludeMatcher(path)) continue; | ||
@@ -173,5 +160,5 @@ let stats; | ||
yield build(entry, path, stats); | ||
if (includeMatcher(path)) yield build(entry, path, stats); | ||
if (entry.isDirectory()) yield* await rrdir.stream(path, opts, {includeMatcher, excludeMatcher}); | ||
} | ||
}; |
{ | ||
"name": "rrdir", | ||
"version": "6.0.1", | ||
"version": "6.1.0", | ||
"description": "Recursive directory reader with a delightful API", | ||
@@ -5,0 +5,0 @@ "author": "silverwind <me@silverwind.io>", |
@@ -42,3 +42,3 @@ # rrdir | ||
- `options.exclude` *Array*: Full path globs to exclude. Default: `[]`. | ||
- `options.include` *Array*: Full path globs to include. Default: `[]`. | ||
- `options.include` *Array*: Full path globs to include. Default: `["**"]`. | ||
- `options.strict` *boolean*: Whether to throw immediately when reading an entry fails. Default: `false`. | ||
@@ -45,0 +45,0 @@ - `options.match` *Object*: [picomatch options](https://github.com/micromatch/picomatch#options). Default: `{dot: true}`. |
8541
129