tiny-readdir 2.7.2 → 2.7.3
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/constants.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -4
- package/dist/utils.d.ts +2 -8
- package/dist/utils.js +1 -22
- package/package.json +6 -6
- package/readme.md +10 -10
- package/src/index.ts +5 -4
- package/src/utils.ts +1 -42
package/dist/constants.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Dirent, Options, ResultDirectory, ResultDirectories, Result } from './types';
|
|
1
|
+
import type { Dirent, Options, ResultDirectory, ResultDirectories, Result } from './types.js';
|
|
2
2
|
declare const readdir: (rootPath: string, options?: Options) => Promise<Result>;
|
|
3
3
|
export default readdir;
|
|
4
4
|
export type { Dirent, Options, ResultDirectory, ResultDirectories, Result };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/* IMPORT */
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
+
import makeCounterPromise from 'promise-make-counter';
|
|
4
5
|
import { NOOP_PROMISE_LIKE } from './constants.js';
|
|
5
|
-
import { castArray, isFunction
|
|
6
|
+
import { castArray, isFunction } from './utils.js';
|
|
6
7
|
/* MAIN */
|
|
7
|
-
//TODO: Streamline the type of
|
|
8
|
+
//TODO: Streamline the type of dirmaps
|
|
8
9
|
const readdir = (rootPath, options) => {
|
|
9
10
|
const followSymlinks = options?.followSymlinks ?? false;
|
|
10
11
|
const maxDepth = options?.depth ?? Infinity;
|
|
@@ -150,14 +151,14 @@ const readdir = (rootPath, options) => {
|
|
|
150
151
|
});
|
|
151
152
|
});
|
|
152
153
|
};
|
|
153
|
-
const populateResultFromSymlink =
|
|
154
|
+
const populateResultFromSymlink = (rootPath, depth) => {
|
|
154
155
|
increment();
|
|
155
156
|
fs.realpath(rootPath, (error, realPath) => {
|
|
156
157
|
if (error)
|
|
157
158
|
return decrement();
|
|
158
159
|
if (signal.aborted)
|
|
159
160
|
return decrement();
|
|
160
|
-
fs.stat(realPath,
|
|
161
|
+
fs.stat(realPath, (error, stat) => {
|
|
161
162
|
if (error)
|
|
162
163
|
return decrement();
|
|
163
164
|
if (signal.aborted)
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
declare const castArray: <T>(value: T | T[]) => T[];
|
|
1
|
+
declare const castArray: <T>(value: T[] | T) => T[];
|
|
3
2
|
declare const isFunction: (value: unknown) => value is Function;
|
|
4
|
-
|
|
5
|
-
promise: Promise<void>;
|
|
6
|
-
increment: Callback;
|
|
7
|
-
decrement: Callback;
|
|
8
|
-
};
|
|
9
|
-
export { castArray, isFunction, makeCounterPromise };
|
|
3
|
+
export { castArray, isFunction };
|
package/dist/utils.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* IMPORT */
|
|
2
|
-
import makeNakedPromise from 'promise-make-naked';
|
|
3
1
|
/* MAIN */
|
|
4
2
|
const castArray = (value) => {
|
|
5
3
|
return Array.isArray(value) ? value : [value];
|
|
@@ -7,24 +5,5 @@ const castArray = (value) => {
|
|
|
7
5
|
const isFunction = (value) => {
|
|
8
6
|
return (typeof value === 'function');
|
|
9
7
|
};
|
|
10
|
-
const makeCounterPromise = () => {
|
|
11
|
-
const { promise, resolve } = makeNakedPromise();
|
|
12
|
-
let counter = 0;
|
|
13
|
-
const increment = () => {
|
|
14
|
-
counter += 1;
|
|
15
|
-
};
|
|
16
|
-
const decrement = () => {
|
|
17
|
-
counter -= 1;
|
|
18
|
-
if (counter)
|
|
19
|
-
return;
|
|
20
|
-
resolve();
|
|
21
|
-
};
|
|
22
|
-
const init = () => {
|
|
23
|
-
increment();
|
|
24
|
-
queueMicrotask(decrement);
|
|
25
|
-
};
|
|
26
|
-
init();
|
|
27
|
-
return { promise, increment, decrement };
|
|
28
|
-
};
|
|
29
8
|
/* EXPORT */
|
|
30
|
-
export { castArray, isFunction
|
|
9
|
+
export { castArray, isFunction };
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "tiny-readdir",
|
|
3
3
|
"repository": "github:fabiospampinato/tiny-readdir",
|
|
4
4
|
"description": "A simple promisified recursive readdir function.",
|
|
5
|
-
"version": "2.7.
|
|
5
|
+
"version": "2.7.3",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"exports": "./dist/index.js",
|
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
"tiny"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"promise-make-
|
|
26
|
+
"promise-make-counter": "^1.0.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@types/node": "^
|
|
30
|
-
"fava": "^0.
|
|
31
|
-
"tsex": "^
|
|
32
|
-
"typescript": "^5.
|
|
29
|
+
"@types/node": "^18.19.39",
|
|
30
|
+
"fava": "^0.3.4",
|
|
31
|
+
"tsex": "^4.0.2",
|
|
32
|
+
"typescript": "^5.5.2"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/readme.md
CHANGED
|
@@ -24,19 +24,19 @@ const result = await readdir ( '/foo/bar', {
|
|
|
24
24
|
onDirents: dirents => console.log ( dirents ) // Optional callback that will be called as soon as new dirents are available, useful for example for discovering ".gitignore" files while searching
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
result.directories; // => Array of absolute paths pointing to directories
|
|
28
|
+
result.files; // => Array of absolute paths pointing to files
|
|
29
|
+
result.symlinks; // => Array of absolute paths pointing to symlinks
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
result.directoriesNames; // => Set of directories names found
|
|
32
|
+
result.filesNames; // => Set of files name found
|
|
33
|
+
result.symlinksNames; // => Set of symlinks names found
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
result.directoriesNamesToPaths; // => Record of directories names found to their paths
|
|
36
|
+
result.filesNamesToPaths; // => Record of files names found to their paths
|
|
37
|
+
result.symlinksNamesToPaths; // => Record of symlinks names found to their paths
|
|
38
38
|
|
|
39
|
-
setTimeout ( () => aborter.abort (),
|
|
39
|
+
setTimeout ( () => aborter.abort (), 10_000 ); // Aborting if it's going to take longer than 10s
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
## License
|
package/src/index.ts
CHANGED
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
|
|
4
4
|
import fs from 'node:fs';
|
|
5
5
|
import path from 'node:path';
|
|
6
|
+
import makeCounterPromise from 'promise-make-counter';
|
|
6
7
|
import {NOOP_PROMISE_LIKE} from './constants';
|
|
7
|
-
import {castArray, isFunction
|
|
8
|
+
import {castArray, isFunction} from './utils';
|
|
8
9
|
import type {Dirent, Options, ResultDirectory, ResultDirectories, Result} from './types';
|
|
9
10
|
|
|
10
11
|
/* MAIN */
|
|
11
12
|
|
|
12
|
-
//TODO: Streamline the type of
|
|
13
|
+
//TODO: Streamline the type of dirmaps
|
|
13
14
|
|
|
14
15
|
const readdir = ( rootPath: string, options?: Options ): Promise<Result> => {
|
|
15
16
|
|
|
@@ -201,7 +202,7 @@ const readdir = ( rootPath: string, options?: Options ): Promise<Result> => {
|
|
|
201
202
|
|
|
202
203
|
};
|
|
203
204
|
|
|
204
|
-
const populateResultFromSymlink =
|
|
205
|
+
const populateResultFromSymlink = ( rootPath: string, depth: number ): void => {
|
|
205
206
|
|
|
206
207
|
increment ();
|
|
207
208
|
|
|
@@ -211,7 +212,7 @@ const readdir = ( rootPath: string, options?: Options ): Promise<Result> => {
|
|
|
211
212
|
|
|
212
213
|
if ( signal.aborted ) return decrement ();
|
|
213
214
|
|
|
214
|
-
fs.stat ( realPath,
|
|
215
|
+
fs.stat ( realPath, ( error, stat ) => {
|
|
215
216
|
|
|
216
217
|
if ( error ) return decrement ();
|
|
217
218
|
|
package/src/utils.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
/* IMPORT */
|
|
3
|
-
|
|
4
|
-
import makeNakedPromise from 'promise-make-naked';
|
|
5
|
-
import type {Callback} from './types';
|
|
6
|
-
|
|
7
2
|
/* MAIN */
|
|
8
3
|
|
|
9
4
|
const castArray = <T> ( value: T[] | T ): T[] => {
|
|
@@ -18,42 +13,6 @@ const isFunction = ( value: unknown ): value is Function => {
|
|
|
18
13
|
|
|
19
14
|
};
|
|
20
15
|
|
|
21
|
-
const makeCounterPromise = (): { promise: Promise<void>, increment: Callback, decrement: Callback } => {
|
|
22
|
-
|
|
23
|
-
const {promise, resolve} = makeNakedPromise<void> ();
|
|
24
|
-
|
|
25
|
-
let counter = 0;
|
|
26
|
-
|
|
27
|
-
const increment = (): void => {
|
|
28
|
-
|
|
29
|
-
counter += 1;
|
|
30
|
-
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const decrement = (): void => {
|
|
34
|
-
|
|
35
|
-
counter -= 1;
|
|
36
|
-
|
|
37
|
-
if ( counter ) return;
|
|
38
|
-
|
|
39
|
-
resolve ();
|
|
40
|
-
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const init = (): void => { // Accounting for no increment/decrement calls
|
|
44
|
-
|
|
45
|
-
increment ();
|
|
46
|
-
|
|
47
|
-
queueMicrotask ( decrement );
|
|
48
|
-
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
init ();
|
|
52
|
-
|
|
53
|
-
return { promise, increment, decrement };
|
|
54
|
-
|
|
55
|
-
};
|
|
56
|
-
|
|
57
16
|
/* EXPORT */
|
|
58
17
|
|
|
59
|
-
export {castArray, isFunction
|
|
18
|
+
export {castArray, isFunction};
|