rrdir 12.0.2 → 12.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/index.js +18 -19
- package/package.json +7 -18
package/README.md
CHANGED
|
@@ -31,22 +31,22 @@ const entries = rrdirSync("dir");
|
|
|
31
31
|
|
|
32
32
|
`rrdir` is an async iterator which yields `entry`. `rrdirAsync` and `rrdirSync` return an Array of `entry`.
|
|
33
33
|
|
|
34
|
-
#### `dir` *String* | *
|
|
34
|
+
#### `dir` *String* | *Uint8Array*
|
|
35
35
|
|
|
36
|
-
The directory to read, either absolute or relative. Pass a `
|
|
36
|
+
The directory to read, either absolute or relative. Pass a `Uint8Array` to switch the module into `Uint8Array` mode which is required to be able to read every file, like for example files with names that are invalid UTF-8 sequences.
|
|
37
37
|
|
|
38
38
|
#### `options` *Object*
|
|
39
39
|
|
|
40
40
|
- `stats` *boolean*: Whether to include `entry.stats`. Will reduce performance. Default: `false`.
|
|
41
41
|
- `followSymlinks` *boolean*: Whether to follow symlinks for both recursion and `stat` calls. Default: `false`.
|
|
42
|
-
- `exclude` *Array*: Path globs to exclude, e.g. `["
|
|
43
|
-
- `include` *Array*: Path globs to include, e.g. `["
|
|
42
|
+
- `exclude` *Array*: Path globs to exclude, e.g. `["**.js"]`. Default: `undefined`.
|
|
43
|
+
- `include` *Array*: Path globs to include, e.g. `["**.map"]`. Default: `undefined`.
|
|
44
44
|
- `strict` *boolean*: Whether to throw immediately when reading an entry fails. Default: `false`.
|
|
45
45
|
- `insensitive` *boolean*: Whether `include` and `exclude` match case-insensitively. Default: `false`.
|
|
46
46
|
|
|
47
47
|
#### `entry` *Object*
|
|
48
48
|
|
|
49
|
-
- `path` *string* | *
|
|
49
|
+
- `path` *string* | *Uint8Array*: The path to the entry, will be relative if `dir` is given relative. If `dir` is a `Uint8Array`, this will be too. Always present.
|
|
50
50
|
- `directory` *boolean*: Boolean indicating whether the entry is a directory. `undefined` on error.
|
|
51
51
|
- `symlink` *boolean*: Boolean indicating whether the entry is a symbolic link. `undefined` on error.
|
|
52
52
|
- `stats` *Object*: A [`fs.stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats) object, present when `options.stats` is set. `undefined` on error.
|
package/index.js
CHANGED
|
@@ -3,7 +3,11 @@ import {readdirSync, statSync, lstatSync} from "node:fs";
|
|
|
3
3
|
import {sep, resolve} from "node:path";
|
|
4
4
|
import picomatch from "picomatch";
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const encoder = new TextEncoder();
|
|
7
|
+
const toUint8Array = encoder.encode.bind(encoder);
|
|
8
|
+
const decoder = new TextDecoder();
|
|
9
|
+
const toString = decoder.decode.bind(decoder);
|
|
10
|
+
const sepUint8Array = toUint8Array(sep);
|
|
7
11
|
|
|
8
12
|
const defaults = {
|
|
9
13
|
strict: false,
|
|
@@ -16,7 +20,7 @@ const defaults = {
|
|
|
16
20
|
|
|
17
21
|
function makePath(entry, dir, encoding) {
|
|
18
22
|
if (encoding === "buffer") {
|
|
19
|
-
return dir === "." ? entry.name :
|
|
23
|
+
return dir === "." ? entry.name : Uint8Array.from([...dir, ...sepUint8Array, ...entry.name]);
|
|
20
24
|
} else {
|
|
21
25
|
return dir === "." ? entry.name : `${dir}${sep}${entry.name}`;
|
|
22
26
|
}
|
|
@@ -39,15 +43,10 @@ function makeMatchers({include, exclude, insensitive}) {
|
|
|
39
43
|
|
|
40
44
|
// resolve the path to an absolute one because picomatch can not deal properly
|
|
41
45
|
// with relative paths that start with ./ or .\
|
|
42
|
-
//
|
|
43
|
-
// false
|
|
46
|
+
// https://github.com/micromatch/picomatch/issues/121
|
|
44
47
|
return {
|
|
45
|
-
includeMatcher: include?.length ?
|
|
46
|
-
|
|
47
|
-
}) : null,
|
|
48
|
-
excludeMatcher: exclude?.length ? (path => {
|
|
49
|
-
return picomatch(exclude, opts)(resolve(path));
|
|
50
|
-
}) : null,
|
|
48
|
+
includeMatcher: include?.length ? path => picomatch(include, opts)(resolve(path)) : null,
|
|
49
|
+
excludeMatcher: exclude?.length ? path => picomatch(exclude, opts)(resolve(path)) : null,
|
|
51
50
|
};
|
|
52
51
|
}
|
|
53
52
|
|
|
@@ -56,7 +55,7 @@ export async function* rrdir(dir, opts = {}, {includeMatcher, excludeMatcher, en
|
|
|
56
55
|
opts = {...defaults, ...opts};
|
|
57
56
|
({includeMatcher, excludeMatcher} = makeMatchers(opts));
|
|
58
57
|
if (/[/\\]$/.test(dir)) dir = dir.substring(0, dir.length - 1);
|
|
59
|
-
encoding =
|
|
58
|
+
encoding = dir instanceof Uint8Array ? "buffer" : undefined;
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
let dirents = [];
|
|
@@ -70,10 +69,10 @@ export async function* rrdir(dir, opts = {}, {includeMatcher, excludeMatcher, en
|
|
|
70
69
|
|
|
71
70
|
for (const dirent of dirents) {
|
|
72
71
|
const path = makePath(dirent, dir, encoding);
|
|
73
|
-
if (excludeMatcher?.(encoding === "buffer" ?
|
|
72
|
+
if (excludeMatcher?.(encoding === "buffer" ? toString(path) : path)) continue;
|
|
74
73
|
|
|
75
74
|
const isSymbolicLink = opts.followSymlinks && dirent.isSymbolicLink();
|
|
76
|
-
const encodedPath = encoding === "buffer" ?
|
|
75
|
+
const encodedPath = encoding === "buffer" ? toString(path) : path;
|
|
77
76
|
const isIncluded = !includeMatcher || includeMatcher(encodedPath);
|
|
78
77
|
let stats;
|
|
79
78
|
|
|
@@ -107,7 +106,7 @@ export async function rrdirAsync(dir, opts = {}, {includeMatcher, excludeMatcher
|
|
|
107
106
|
opts = {...defaults, ...opts};
|
|
108
107
|
({includeMatcher, excludeMatcher} = makeMatchers(opts));
|
|
109
108
|
if (/[/\\]$/.test(dir)) dir = dir.substring(0, dir.length - 1);
|
|
110
|
-
encoding =
|
|
109
|
+
encoding = dir instanceof Uint8Array ? "buffer" : undefined;
|
|
111
110
|
}
|
|
112
111
|
|
|
113
112
|
const results = [];
|
|
@@ -122,10 +121,10 @@ export async function rrdirAsync(dir, opts = {}, {includeMatcher, excludeMatcher
|
|
|
122
121
|
|
|
123
122
|
await Promise.all(dirents.map(async dirent => {
|
|
124
123
|
const path = makePath(dirent, dir, encoding);
|
|
125
|
-
if (excludeMatcher?.(encoding === "buffer" ?
|
|
124
|
+
if (excludeMatcher?.(encoding === "buffer" ? toString(path) : path)) return;
|
|
126
125
|
|
|
127
126
|
const isSymbolicLink = opts.followSymlinks && dirent.isSymbolicLink();
|
|
128
|
-
const encodedPath = encoding === "buffer" ?
|
|
127
|
+
const encodedPath = encoding === "buffer" ? toString(path) : path;
|
|
129
128
|
const isIncluded = !includeMatcher || includeMatcher(encodedPath);
|
|
130
129
|
let stats;
|
|
131
130
|
|
|
@@ -161,7 +160,7 @@ export function rrdirSync(dir, opts = {}, {includeMatcher, excludeMatcher, encod
|
|
|
161
160
|
opts = {...defaults, ...opts};
|
|
162
161
|
({includeMatcher, excludeMatcher} = makeMatchers(opts));
|
|
163
162
|
if (/[/\\]$/.test(dir)) dir = dir.substring(0, dir.length - 1);
|
|
164
|
-
encoding =
|
|
163
|
+
encoding = dir instanceof Uint8Array ? "buffer" : undefined;
|
|
165
164
|
}
|
|
166
165
|
|
|
167
166
|
const results = [];
|
|
@@ -176,10 +175,10 @@ export function rrdirSync(dir, opts = {}, {includeMatcher, excludeMatcher, encod
|
|
|
176
175
|
|
|
177
176
|
for (const dirent of dirents) {
|
|
178
177
|
const path = makePath(dirent, dir, encoding);
|
|
179
|
-
if (excludeMatcher?.(encoding === "buffer" ?
|
|
178
|
+
if (excludeMatcher?.(encoding === "buffer" ? toString(path) : path)) continue;
|
|
180
179
|
|
|
181
180
|
const isSymbolicLink = opts.followSymlinks && dirent.isSymbolicLink();
|
|
182
|
-
const encodedPath = encoding === "buffer" ?
|
|
181
|
+
const encodedPath = encoding === "buffer" ? toString(path) : path;
|
|
183
182
|
const isIncluded = !includeMatcher || includeMatcher(encodedPath);
|
|
184
183
|
let stats;
|
|
185
184
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rrdir",
|
|
3
|
-
"version": "12.0
|
|
3
|
+
"version": "12.1.0",
|
|
4
4
|
"description": "Recursive directory reader with a delightful API",
|
|
5
5
|
"author": "silverwind <me@silverwind.io>",
|
|
6
6
|
"repository": "silverwind/rrdir",
|
|
@@ -12,27 +12,16 @@
|
|
|
12
12
|
"node": ">=18"
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
|
-
"index.js"
|
|
15
|
+
"./index.js"
|
|
16
16
|
],
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"eslint": "8.
|
|
19
|
-
"eslint-config-silverwind": "
|
|
20
|
-
"updates": "15.0.
|
|
21
|
-
"versions": "
|
|
22
|
-
"vitest": "0.34.
|
|
18
|
+
"eslint": "8.52.0",
|
|
19
|
+
"eslint-config-silverwind": "79.0.4",
|
|
20
|
+
"updates": "15.0.3",
|
|
21
|
+
"versions": "12.0.0",
|
|
22
|
+
"vitest": "0.34.6",
|
|
23
23
|
"vitest-config-silverwind": "3.0.0"
|
|
24
24
|
},
|
|
25
|
-
"keywords": [
|
|
26
|
-
"recursive readdir",
|
|
27
|
-
"readdir",
|
|
28
|
-
"recursive",
|
|
29
|
-
"walk",
|
|
30
|
-
"walkdir",
|
|
31
|
-
"directory",
|
|
32
|
-
"crawl",
|
|
33
|
-
"crawler",
|
|
34
|
-
"scandir"
|
|
35
|
-
],
|
|
36
25
|
"dependencies": {
|
|
37
26
|
"picomatch": "2.3.1"
|
|
38
27
|
}
|