rrdir 13.1.0 → 13.1.1
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/dist/index.js +125 -175
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,214 +1,164 @@
|
|
|
1
|
-
import { readdir, stat, lstat } from "node:fs/promises";
|
|
2
|
-
import { readdirSync, statSync
|
|
3
|
-
import { sep, resolve } from "node:path";
|
|
4
|
-
import
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const sepUint8Array = toUint8Array(sep);
|
|
10
|
-
const getEncoding = (dir) => dir instanceof Uint8Array ? "buffer" : "utf8";
|
|
11
|
-
const defaultOpts = {
|
|
12
|
-
strict: false,
|
|
13
|
-
stats: false,
|
|
14
|
-
followSymlinks: false,
|
|
1
|
+
import { readdir as U, stat as b, lstat as g } from "node:fs/promises";
|
|
2
|
+
import { readdirSync as I, statSync as $, lstatSync as E } from "node:fs";
|
|
3
|
+
import { sep as F, resolve as A } from "node:path";
|
|
4
|
+
import P from "picomatch";
|
|
5
|
+
const T = new TextEncoder(), O = T.encode.bind(T), p = new TextDecoder(), h = p.decode.bind(p), j = O(F), S = (t) => t instanceof Uint8Array ? "buffer" : "utf8", k = {
|
|
6
|
+
strict: !1,
|
|
7
|
+
stats: !1,
|
|
8
|
+
followSymlinks: !1,
|
|
15
9
|
exclude: void 0,
|
|
16
10
|
include: void 0,
|
|
17
|
-
insensitive:
|
|
11
|
+
insensitive: !1
|
|
18
12
|
};
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
return dir === "." ? name : Uint8Array.from([...dir, ...sepUint8Array, ...name]);
|
|
22
|
-
} else {
|
|
23
|
-
return dir === "." ? name : `${dir}${sep}${name}`;
|
|
24
|
-
}
|
|
13
|
+
function v({ name: t }, i, s) {
|
|
14
|
+
return s === "buffer" ? i === "." ? t : Uint8Array.from([...i, ...j, ...t]) : i === "." ? t : `${i}${F}${t}`;
|
|
25
15
|
}
|
|
26
|
-
function
|
|
16
|
+
function D(t, i, s, l) {
|
|
27
17
|
return {
|
|
28
|
-
path,
|
|
29
|
-
directory: (
|
|
30
|
-
symlink: (
|
|
31
|
-
...
|
|
18
|
+
path: i,
|
|
19
|
+
directory: (s || t).isDirectory(),
|
|
20
|
+
symlink: (s || t).isSymbolicLink(),
|
|
21
|
+
...l.stats ? { stats: s } : {}
|
|
32
22
|
};
|
|
33
23
|
}
|
|
34
|
-
function
|
|
35
|
-
const
|
|
36
|
-
dot:
|
|
37
|
-
flags:
|
|
24
|
+
function L({ include: t, exclude: i, insensitive: s }) {
|
|
25
|
+
const l = {
|
|
26
|
+
dot: !0,
|
|
27
|
+
flags: s ? "i" : void 0
|
|
38
28
|
};
|
|
39
29
|
return {
|
|
40
|
-
includeMatcher:
|
|
41
|
-
excludeMatcher:
|
|
30
|
+
includeMatcher: t?.length ? (f) => P(t, l)(A(f)) : null,
|
|
31
|
+
excludeMatcher: i?.length ? (f) => P(i, l)(A(f)) : null
|
|
42
32
|
};
|
|
43
33
|
}
|
|
44
|
-
async function*
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
({ includeMatcher, excludeMatcher } = makeMatchers(opts));
|
|
48
|
-
if (typeof dir === "string" && /[/\\]$/.test(dir))
|
|
49
|
-
dir = dir.substring(0, dir.length - 1);
|
|
50
|
-
encoding = getEncoding(dir);
|
|
51
|
-
}
|
|
52
|
-
let dirents = [];
|
|
34
|
+
async function* q(t, i = {}, { includeMatcher: s, excludeMatcher: l, encoding: f } = {}) {
|
|
35
|
+
s === void 0 && (i = { ...k, ...i }, { includeMatcher: s, excludeMatcher: l } = L(i), typeof t == "string" && /[/\\]$/.test(t) && (t = t.substring(0, t.length - 1)), f = S(t));
|
|
36
|
+
let n = [];
|
|
53
37
|
try {
|
|
54
|
-
|
|
55
|
-
} catch (
|
|
56
|
-
if (
|
|
57
|
-
throw
|
|
58
|
-
yield { path:
|
|
38
|
+
n = await U(t, { encoding: f, withFileTypes: !0 });
|
|
39
|
+
} catch (y) {
|
|
40
|
+
if (i.strict)
|
|
41
|
+
throw y;
|
|
42
|
+
yield { path: t, err: y };
|
|
59
43
|
}
|
|
60
|
-
if (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
yield { path, err };
|
|
78
|
-
}
|
|
44
|
+
if (n.length)
|
|
45
|
+
for (const y of n) {
|
|
46
|
+
const r = v(y, t, f);
|
|
47
|
+
if (l?.(f === "buffer" ? h(r) : r))
|
|
48
|
+
continue;
|
|
49
|
+
const e = i.followSymlinks && y.isSymbolicLink(), u = f === "buffer" ? h(r) : r, m = !s || s(u);
|
|
50
|
+
let c;
|
|
51
|
+
if (m) {
|
|
52
|
+
if (i.stats || e)
|
|
53
|
+
try {
|
|
54
|
+
c = await (i.followSymlinks ? b : g)(r);
|
|
55
|
+
} catch (a) {
|
|
56
|
+
if (i.strict)
|
|
57
|
+
throw a;
|
|
58
|
+
yield { path: r, err: a };
|
|
59
|
+
}
|
|
60
|
+
yield D(y, r, c, i);
|
|
79
61
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
} else if (dirent.isDirectory()) {
|
|
92
|
-
recurse = true;
|
|
62
|
+
let o = !1;
|
|
63
|
+
if (e) {
|
|
64
|
+
if (!c)
|
|
65
|
+
try {
|
|
66
|
+
c = await b(r);
|
|
67
|
+
} catch {
|
|
68
|
+
}
|
|
69
|
+
c && c.isDirectory() && (o = !0);
|
|
70
|
+
} else
|
|
71
|
+
y.isDirectory() && (o = !0);
|
|
72
|
+
o && (yield* q(r, i, { includeMatcher: s, excludeMatcher: l, encoding: f }));
|
|
93
73
|
}
|
|
94
|
-
if (recurse)
|
|
95
|
-
yield* rrdir(path, opts, { includeMatcher, excludeMatcher, encoding });
|
|
96
|
-
}
|
|
97
74
|
}
|
|
98
|
-
async function
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (typeof dir === "string" && /[/\\]$/.test(dir))
|
|
103
|
-
dir = dir.substring(0, dir.length - 1);
|
|
104
|
-
encoding = getEncoding(dir);
|
|
105
|
-
}
|
|
106
|
-
const results = [];
|
|
107
|
-
let dirents = [];
|
|
75
|
+
async function z(t, i = {}, { includeMatcher: s, excludeMatcher: l, encoding: f } = {}) {
|
|
76
|
+
s === void 0 && (i = { ...k, ...i }, { includeMatcher: s, excludeMatcher: l } = L(i), typeof t == "string" && /[/\\]$/.test(t) && (t = t.substring(0, t.length - 1)), f = S(t));
|
|
77
|
+
const n = [];
|
|
78
|
+
let y = [];
|
|
108
79
|
try {
|
|
109
|
-
|
|
110
|
-
} catch (
|
|
111
|
-
if (
|
|
112
|
-
throw
|
|
113
|
-
|
|
80
|
+
y = await U(t, { encoding: f, withFileTypes: !0 });
|
|
81
|
+
} catch (r) {
|
|
82
|
+
if (i.strict)
|
|
83
|
+
throw r;
|
|
84
|
+
n.push({ path: t, err: r });
|
|
114
85
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const path = makePath(dirent, dir, encoding);
|
|
119
|
-
if (excludeMatcher == null ? void 0 : excludeMatcher(encoding === "buffer" ? toString(path) : path))
|
|
86
|
+
return y.length && await Promise.all(y.map(async (r) => {
|
|
87
|
+
const e = v(r, t, f);
|
|
88
|
+
if (l?.(f === "buffer" ? h(e) : e))
|
|
120
89
|
return;
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (isIncluded) {
|
|
126
|
-
if (opts.stats || isSymbolicLink) {
|
|
90
|
+
const u = i.followSymlinks && r.isSymbolicLink(), m = f === "buffer" ? h(e) : e, c = !s || s(m);
|
|
91
|
+
let o;
|
|
92
|
+
if (c) {
|
|
93
|
+
if (i.stats || u)
|
|
127
94
|
try {
|
|
128
|
-
|
|
129
|
-
} catch (
|
|
130
|
-
if (
|
|
131
|
-
throw
|
|
132
|
-
|
|
95
|
+
o = await (i.followSymlinks ? b : g)(e);
|
|
96
|
+
} catch (w) {
|
|
97
|
+
if (i.strict)
|
|
98
|
+
throw w;
|
|
99
|
+
n.push({ path: e, err: w });
|
|
133
100
|
}
|
|
134
|
-
|
|
135
|
-
results.push(build(dirent, path, stats, opts));
|
|
101
|
+
n.push(D(r, e, o, i));
|
|
136
102
|
}
|
|
137
|
-
let
|
|
138
|
-
if (
|
|
139
|
-
if (!
|
|
103
|
+
let a = !1;
|
|
104
|
+
if (u) {
|
|
105
|
+
if (!o)
|
|
140
106
|
try {
|
|
141
|
-
|
|
107
|
+
o = await b(e);
|
|
142
108
|
} catch {
|
|
143
109
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if (recurse)
|
|
150
|
-
results.push(...await rrdirAsync(path, opts, { includeMatcher, excludeMatcher, encoding }));
|
|
151
|
-
}));
|
|
152
|
-
return results;
|
|
110
|
+
o && o.isDirectory() && (a = !0);
|
|
111
|
+
} else
|
|
112
|
+
r.isDirectory() && (a = !0);
|
|
113
|
+
a && n.push(...await z(e, i, { includeMatcher: s, excludeMatcher: l, encoding: f }));
|
|
114
|
+
})), n;
|
|
153
115
|
}
|
|
154
|
-
function
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (typeof dir === "string" && /[/\\]$/.test(dir))
|
|
159
|
-
dir = dir.substring(0, dir.length - 1);
|
|
160
|
-
encoding = getEncoding(dir);
|
|
161
|
-
}
|
|
162
|
-
const results = [];
|
|
163
|
-
let dirents = [];
|
|
116
|
+
function B(t, i = {}, { includeMatcher: s, excludeMatcher: l, encoding: f } = {}) {
|
|
117
|
+
s === void 0 && (i = { ...k, ...i }, { includeMatcher: s, excludeMatcher: l } = L(i), typeof t == "string" && /[/\\]$/.test(t) && (t = t.substring(0, t.length - 1)), f = S(t));
|
|
118
|
+
const n = [];
|
|
119
|
+
let y = [];
|
|
164
120
|
try {
|
|
165
|
-
|
|
166
|
-
} catch (
|
|
167
|
-
if (
|
|
168
|
-
throw
|
|
169
|
-
|
|
121
|
+
y = I(t, { encoding: f, withFileTypes: !0 });
|
|
122
|
+
} catch (r) {
|
|
123
|
+
if (i.strict)
|
|
124
|
+
throw r;
|
|
125
|
+
n.push({ path: t, err: r });
|
|
170
126
|
}
|
|
171
|
-
if (!
|
|
172
|
-
return
|
|
173
|
-
for (const
|
|
174
|
-
const
|
|
175
|
-
if (
|
|
127
|
+
if (!y.length)
|
|
128
|
+
return n;
|
|
129
|
+
for (const r of y) {
|
|
130
|
+
const e = v(r, t, f);
|
|
131
|
+
if (l?.(f === "buffer" ? h(e) : e))
|
|
176
132
|
continue;
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if (isIncluded) {
|
|
182
|
-
if (opts.stats || isSymbolicLink) {
|
|
133
|
+
const u = i.followSymlinks && r.isSymbolicLink(), m = f === "buffer" ? h(e) : e, c = !s || s(m);
|
|
134
|
+
let o;
|
|
135
|
+
if (c) {
|
|
136
|
+
if (i.stats || u)
|
|
183
137
|
try {
|
|
184
|
-
|
|
185
|
-
} catch (
|
|
186
|
-
if (
|
|
187
|
-
throw
|
|
188
|
-
|
|
138
|
+
o = (i.followSymlinks ? $ : E)(e);
|
|
139
|
+
} catch (w) {
|
|
140
|
+
if (i.strict)
|
|
141
|
+
throw w;
|
|
142
|
+
n.push({ path: e, err: w });
|
|
189
143
|
}
|
|
190
|
-
|
|
191
|
-
results.push(build(dirent, path, stats, opts));
|
|
144
|
+
n.push(D(r, e, o, i));
|
|
192
145
|
}
|
|
193
|
-
let
|
|
194
|
-
if (
|
|
195
|
-
if (!
|
|
146
|
+
let a = !1;
|
|
147
|
+
if (u) {
|
|
148
|
+
if (!o)
|
|
196
149
|
try {
|
|
197
|
-
|
|
150
|
+
o = $(e);
|
|
198
151
|
} catch {
|
|
199
152
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
if (recurse)
|
|
206
|
-
results.push(...rrdirSync(path, opts, { includeMatcher, excludeMatcher, encoding }));
|
|
153
|
+
o && o.isDirectory() && (a = !0);
|
|
154
|
+
} else
|
|
155
|
+
r.isDirectory() && (a = !0);
|
|
156
|
+
a && n.push(...B(e, i, { includeMatcher: s, excludeMatcher: l, encoding: f }));
|
|
207
157
|
}
|
|
208
|
-
return
|
|
158
|
+
return n;
|
|
209
159
|
}
|
|
210
160
|
export {
|
|
211
|
-
rrdir,
|
|
212
|
-
rrdirAsync,
|
|
213
|
-
rrdirSync
|
|
161
|
+
q as rrdir,
|
|
162
|
+
z as rrdirAsync,
|
|
163
|
+
B as rrdirSync
|
|
214
164
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rrdir",
|
|
3
|
-
"version": "13.1.
|
|
3
|
+
"version": "13.1.1",
|
|
4
4
|
"description": "Recursive directory reader with a delightful API",
|
|
5
5
|
"author": "silverwind <me@silverwind.io>",
|
|
6
6
|
"repository": "silverwind/rrdir",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"updates": "16.0.1",
|
|
30
30
|
"versions": "12.0.1",
|
|
31
31
|
"vite": "5.2.11",
|
|
32
|
-
"vite-
|
|
32
|
+
"vite-config-silverwind": "2.0.3",
|
|
33
33
|
"vitest": "1.5.0",
|
|
34
34
|
"vitest-config-silverwind": "8.0.4"
|
|
35
35
|
}
|