rrdir 13.1.2 → 13.2.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/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -57
- package/package.json +12 -12
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Stats } from 'node:fs';
|
|
2
2
|
import { Matcher } from 'picomatch';
|
|
3
|
-
|
|
4
|
-
type
|
|
5
|
-
type
|
|
6
|
-
type RRDirOpts = {
|
|
3
|
+
export type Encoding = "utf8" | "buffer";
|
|
4
|
+
export type Dir = string | Uint8Array;
|
|
5
|
+
export type DirNodeCompatible = string | Buffer;
|
|
6
|
+
export type RRDirOpts = {
|
|
7
7
|
strict?: boolean;
|
|
8
8
|
stats?: boolean;
|
|
9
9
|
followSymlinks?: boolean;
|
|
@@ -16,7 +16,7 @@ type InternalOpts = {
|
|
|
16
16
|
excludeMatcher?: Matcher;
|
|
17
17
|
encoding?: Encoding;
|
|
18
18
|
};
|
|
19
|
-
type Entry = {
|
|
19
|
+
export type Entry = {
|
|
20
20
|
/** The path to the entry, will be relative if `dir` is given relative. If `dir` is a `Uint8Array`, this will be too. Always present. */
|
|
21
21
|
path: Dir;
|
|
22
22
|
/** Boolean indicating whether the entry is a directory. `undefined` on error. */
|
|
@@ -32,3 +32,4 @@ export declare function rrdir(dir: Dir, opts?: RRDirOpts, { includeMatcher, excl
|
|
|
32
32
|
export declare function rrdirAsync(dir: Dir, opts?: RRDirOpts, { includeMatcher, excludeMatcher, encoding }?: InternalOpts): Promise<Entry[]>;
|
|
33
33
|
export declare function rrdirSync(dir: Dir, opts?: RRDirOpts, { includeMatcher, excludeMatcher, encoding }?: InternalOpts): Entry[];
|
|
34
34
|
export {};
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","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AI,GAAE,SAAc,EAAE,EAAC,cAAc,EAAE,cAAc,EAAE,QAAQ,EAAC,GAAE,YAAiB,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,CAqDhJ;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,GAAE,SAAc,EAAE,EAAC,cAAc,EAAE,cAAc,EAAE,QAAQ,EAAC,GAAE,YAAiB,GAAG,KAAK,EAAE,CAoDhI"}
|
package/dist/index.js
CHANGED
|
@@ -45,24 +45,20 @@ async function* rrdir(dir, opts = {}, { includeMatcher, excludeMatcher, encoding
|
|
|
45
45
|
if (includeMatcher === void 0) {
|
|
46
46
|
opts = { ...defaultOpts, ...opts };
|
|
47
47
|
({ includeMatcher, excludeMatcher } = makeMatchers(opts));
|
|
48
|
-
if (typeof dir === "string" && /[/\\]$/.test(dir))
|
|
49
|
-
dir = dir.substring(0, dir.length - 1);
|
|
48
|
+
if (typeof dir === "string" && /[/\\]$/.test(dir)) dir = dir.substring(0, dir.length - 1);
|
|
50
49
|
encoding = getEncoding(dir);
|
|
51
50
|
}
|
|
52
51
|
let dirents = [];
|
|
53
52
|
try {
|
|
54
53
|
dirents = await readdir(dir, { encoding, withFileTypes: true });
|
|
55
54
|
} catch (err) {
|
|
56
|
-
if (opts.strict)
|
|
57
|
-
throw err;
|
|
55
|
+
if (opts.strict) throw err;
|
|
58
56
|
yield { path: dir, err };
|
|
59
57
|
}
|
|
60
|
-
if (!dirents.length)
|
|
61
|
-
return;
|
|
58
|
+
if (!dirents.length) return;
|
|
62
59
|
for (const dirent of dirents) {
|
|
63
60
|
const path = makePath(dirent, dir, encoding);
|
|
64
|
-
if (excludeMatcher?.(encoding === "buffer" ? toString(path) : path))
|
|
65
|
-
continue;
|
|
61
|
+
if (excludeMatcher?.(encoding === "buffer" ? toString(path) : path)) continue;
|
|
66
62
|
const isSymbolicLink = opts.followSymlinks && dirent.isSymbolicLink();
|
|
67
63
|
const encodedPath = encoding === "buffer" ? toString(path) : path;
|
|
68
64
|
const isIncluded = !includeMatcher || includeMatcher(encodedPath);
|
|
@@ -72,8 +68,7 @@ async function* rrdir(dir, opts = {}, { includeMatcher, excludeMatcher, encoding
|
|
|
72
68
|
try {
|
|
73
69
|
stats = await (opts.followSymlinks ? stat : lstat)(path);
|
|
74
70
|
} catch (err) {
|
|
75
|
-
if (opts.strict)
|
|
76
|
-
throw err;
|
|
71
|
+
if (opts.strict) throw err;
|
|
77
72
|
yield { path, err };
|
|
78
73
|
}
|
|
79
74
|
}
|
|
@@ -81,26 +76,22 @@ async function* rrdir(dir, opts = {}, { includeMatcher, excludeMatcher, encoding
|
|
|
81
76
|
}
|
|
82
77
|
let recurse = false;
|
|
83
78
|
if (isSymbolicLink) {
|
|
84
|
-
if (!stats)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (stats && stats.isDirectory())
|
|
90
|
-
recurse = true;
|
|
79
|
+
if (!stats) try {
|
|
80
|
+
stats = await stat(path);
|
|
81
|
+
} catch {
|
|
82
|
+
}
|
|
83
|
+
if (stats && stats.isDirectory()) recurse = true;
|
|
91
84
|
} else if (dirent.isDirectory()) {
|
|
92
85
|
recurse = true;
|
|
93
86
|
}
|
|
94
|
-
if (recurse)
|
|
95
|
-
yield* rrdir(path, opts, { includeMatcher, excludeMatcher, encoding });
|
|
87
|
+
if (recurse) yield* rrdir(path, opts, { includeMatcher, excludeMatcher, encoding });
|
|
96
88
|
}
|
|
97
89
|
}
|
|
98
90
|
async function rrdirAsync(dir, opts = {}, { includeMatcher, excludeMatcher, encoding } = {}) {
|
|
99
91
|
if (includeMatcher === void 0) {
|
|
100
92
|
opts = { ...defaultOpts, ...opts };
|
|
101
93
|
({ includeMatcher, excludeMatcher } = makeMatchers(opts));
|
|
102
|
-
if (typeof dir === "string" && /[/\\]$/.test(dir))
|
|
103
|
-
dir = dir.substring(0, dir.length - 1);
|
|
94
|
+
if (typeof dir === "string" && /[/\\]$/.test(dir)) dir = dir.substring(0, dir.length - 1);
|
|
104
95
|
encoding = getEncoding(dir);
|
|
105
96
|
}
|
|
106
97
|
const results = [];
|
|
@@ -108,16 +99,13 @@ async function rrdirAsync(dir, opts = {}, { includeMatcher, excludeMatcher, enco
|
|
|
108
99
|
try {
|
|
109
100
|
dirents = await readdir(dir, { encoding, withFileTypes: true });
|
|
110
101
|
} catch (err) {
|
|
111
|
-
if (opts.strict)
|
|
112
|
-
throw err;
|
|
102
|
+
if (opts.strict) throw err;
|
|
113
103
|
results.push({ path: dir, err });
|
|
114
104
|
}
|
|
115
|
-
if (!dirents.length)
|
|
116
|
-
return results;
|
|
105
|
+
if (!dirents.length) return results;
|
|
117
106
|
await Promise.all(dirents.map(async (dirent) => {
|
|
118
107
|
const path = makePath(dirent, dir, encoding);
|
|
119
|
-
if (excludeMatcher?.(encoding === "buffer" ? toString(path) : path))
|
|
120
|
-
return;
|
|
108
|
+
if (excludeMatcher?.(encoding === "buffer" ? toString(path) : path)) return;
|
|
121
109
|
const isSymbolicLink = opts.followSymlinks && dirent.isSymbolicLink();
|
|
122
110
|
const encodedPath = encoding === "buffer" ? toString(path) : path;
|
|
123
111
|
const isIncluded = !includeMatcher || includeMatcher(encodedPath);
|
|
@@ -127,8 +115,7 @@ async function rrdirAsync(dir, opts = {}, { includeMatcher, excludeMatcher, enco
|
|
|
127
115
|
try {
|
|
128
116
|
stats = await (opts.followSymlinks ? stat : lstat)(path);
|
|
129
117
|
} catch (err) {
|
|
130
|
-
if (opts.strict)
|
|
131
|
-
throw err;
|
|
118
|
+
if (opts.strict) throw err;
|
|
132
119
|
results.push({ path, err });
|
|
133
120
|
}
|
|
134
121
|
}
|
|
@@ -136,18 +123,15 @@ async function rrdirAsync(dir, opts = {}, { includeMatcher, excludeMatcher, enco
|
|
|
136
123
|
}
|
|
137
124
|
let recurse = false;
|
|
138
125
|
if (isSymbolicLink) {
|
|
139
|
-
if (!stats)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (stats && stats.isDirectory())
|
|
145
|
-
recurse = true;
|
|
126
|
+
if (!stats) try {
|
|
127
|
+
stats = await stat(path);
|
|
128
|
+
} catch {
|
|
129
|
+
}
|
|
130
|
+
if (stats && stats.isDirectory()) recurse = true;
|
|
146
131
|
} else if (dirent.isDirectory()) {
|
|
147
132
|
recurse = true;
|
|
148
133
|
}
|
|
149
|
-
if (recurse)
|
|
150
|
-
results.push(...await rrdirAsync(path, opts, { includeMatcher, excludeMatcher, encoding }));
|
|
134
|
+
if (recurse) results.push(...await rrdirAsync(path, opts, { includeMatcher, excludeMatcher, encoding }));
|
|
151
135
|
}));
|
|
152
136
|
return results;
|
|
153
137
|
}
|
|
@@ -155,8 +139,7 @@ function rrdirSync(dir, opts = {}, { includeMatcher, excludeMatcher, encoding }
|
|
|
155
139
|
if (includeMatcher === void 0) {
|
|
156
140
|
opts = { ...defaultOpts, ...opts };
|
|
157
141
|
({ includeMatcher, excludeMatcher } = makeMatchers(opts));
|
|
158
|
-
if (typeof dir === "string" && /[/\\]$/.test(dir))
|
|
159
|
-
dir = dir.substring(0, dir.length - 1);
|
|
142
|
+
if (typeof dir === "string" && /[/\\]$/.test(dir)) dir = dir.substring(0, dir.length - 1);
|
|
160
143
|
encoding = getEncoding(dir);
|
|
161
144
|
}
|
|
162
145
|
const results = [];
|
|
@@ -164,16 +147,13 @@ function rrdirSync(dir, opts = {}, { includeMatcher, excludeMatcher, encoding }
|
|
|
164
147
|
try {
|
|
165
148
|
dirents = readdirSync(dir, { encoding, withFileTypes: true });
|
|
166
149
|
} catch (err) {
|
|
167
|
-
if (opts.strict)
|
|
168
|
-
throw err;
|
|
150
|
+
if (opts.strict) throw err;
|
|
169
151
|
results.push({ path: dir, err });
|
|
170
152
|
}
|
|
171
|
-
if (!dirents.length)
|
|
172
|
-
return results;
|
|
153
|
+
if (!dirents.length) return results;
|
|
173
154
|
for (const dirent of dirents) {
|
|
174
155
|
const path = makePath(dirent, dir, encoding);
|
|
175
|
-
if (excludeMatcher?.(encoding === "buffer" ? toString(path) : path))
|
|
176
|
-
continue;
|
|
156
|
+
if (excludeMatcher?.(encoding === "buffer" ? toString(path) : path)) continue;
|
|
177
157
|
const isSymbolicLink = opts.followSymlinks && dirent.isSymbolicLink();
|
|
178
158
|
const encodedPath = encoding === "buffer" ? toString(path) : path;
|
|
179
159
|
const isIncluded = !includeMatcher || includeMatcher(encodedPath);
|
|
@@ -183,8 +163,7 @@ function rrdirSync(dir, opts = {}, { includeMatcher, excludeMatcher, encoding }
|
|
|
183
163
|
try {
|
|
184
164
|
stats = (opts.followSymlinks ? statSync : lstatSync)(path);
|
|
185
165
|
} catch (err) {
|
|
186
|
-
if (opts.strict)
|
|
187
|
-
throw err;
|
|
166
|
+
if (opts.strict) throw err;
|
|
188
167
|
results.push({ path, err });
|
|
189
168
|
}
|
|
190
169
|
}
|
|
@@ -192,18 +171,15 @@ function rrdirSync(dir, opts = {}, { includeMatcher, excludeMatcher, encoding }
|
|
|
192
171
|
}
|
|
193
172
|
let recurse = false;
|
|
194
173
|
if (isSymbolicLink) {
|
|
195
|
-
if (!stats)
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
if (stats && stats.isDirectory())
|
|
201
|
-
recurse = true;
|
|
174
|
+
if (!stats) try {
|
|
175
|
+
stats = statSync(path);
|
|
176
|
+
} catch {
|
|
177
|
+
}
|
|
178
|
+
if (stats && stats.isDirectory()) recurse = true;
|
|
202
179
|
} else if (dirent.isDirectory()) {
|
|
203
180
|
recurse = true;
|
|
204
181
|
}
|
|
205
|
-
if (recurse)
|
|
206
|
-
results.push(...rrdirSync(path, opts, { includeMatcher, excludeMatcher, encoding }));
|
|
182
|
+
if (recurse) results.push(...rrdirSync(path, opts, { includeMatcher, excludeMatcher, encoding }));
|
|
207
183
|
}
|
|
208
184
|
return results;
|
|
209
185
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rrdir",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.2.0",
|
|
4
4
|
"description": "Recursive directory reader with a delightful API",
|
|
5
5
|
"author": "silverwind <me@silverwind.io>",
|
|
6
6
|
"repository": "silverwind/rrdir",
|
|
@@ -20,17 +20,17 @@
|
|
|
20
20
|
"picomatch": "^4.0.2"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@types/node": "
|
|
24
|
-
"@types/picomatch": "
|
|
23
|
+
"@types/node": "22.10.1",
|
|
24
|
+
"@types/picomatch": "3.0.1",
|
|
25
25
|
"eslint": "8.57.0",
|
|
26
|
-
"eslint-config-silverwind": "
|
|
27
|
-
"eslint-config-silverwind-typescript": "
|
|
28
|
-
"typescript-config-silverwind": "
|
|
29
|
-
"updates": "16.0
|
|
30
|
-
"versions": "12.
|
|
31
|
-
"vite": "
|
|
32
|
-
"vite-config-silverwind": "
|
|
33
|
-
"vitest": "1.
|
|
34
|
-
"vitest-config-silverwind": "
|
|
26
|
+
"eslint-config-silverwind": "94.2.1",
|
|
27
|
+
"eslint-config-silverwind-typescript": "9.2.0",
|
|
28
|
+
"typescript-config-silverwind": "6.1.1",
|
|
29
|
+
"updates": "16.4.0",
|
|
30
|
+
"versions": "12.1.2",
|
|
31
|
+
"vite": "6.0.1",
|
|
32
|
+
"vite-config-silverwind": "3.1.0",
|
|
33
|
+
"vitest": "2.1.6",
|
|
34
|
+
"vitest-config-silverwind": "9.2.0"
|
|
35
35
|
}
|
|
36
36
|
}
|