tiny-readdir 3.0.0 → 3.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/dist/index.js +3 -3
- package/dist/types.d.ts +5 -3
- package/package.json +3 -3
- package/readme.md +3 -3
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ const readdir = (rootPath, options) => {
|
|
|
11
11
|
const maxPaths = options?.limit ?? Infinity;
|
|
12
12
|
const ignore = options?.ignore ?? [];
|
|
13
13
|
const ignores = castArray(ignore).map(ignore => isFunction(ignore) ? ignore : (targetPath) => ignore.test(targetPath));
|
|
14
|
-
const isIgnored = (targetPath) => ignores.some(ignore => ignore(targetPath));
|
|
14
|
+
const isIgnored = (targetPath, targetContext) => ignores.some(ignore => ignore(targetPath, targetContext));
|
|
15
15
|
const signal = options?.signal ?? { aborted: false };
|
|
16
16
|
const onDirents = options?.onDirents || (() => { });
|
|
17
17
|
const directories = [];
|
|
@@ -64,7 +64,7 @@ const readdir = (rootPath, options) => {
|
|
|
64
64
|
const handleStat = (rootPath, stat, depth) => {
|
|
65
65
|
if (signal.aborted)
|
|
66
66
|
return;
|
|
67
|
-
if (isIgnored(rootPath))
|
|
67
|
+
if (isIgnored(rootPath, stat))
|
|
68
68
|
return;
|
|
69
69
|
if (stat.isDirectory()) {
|
|
70
70
|
handleDirectory(rootPath, depth);
|
|
@@ -82,7 +82,7 @@ const readdir = (rootPath, options) => {
|
|
|
82
82
|
const separator = (rootPath === path.sep) ? '' : path.sep;
|
|
83
83
|
const name = dirent.name;
|
|
84
84
|
const subPath = `${rootPath}${separator}${name}`;
|
|
85
|
-
if (isIgnored(subPath))
|
|
85
|
+
if (isIgnored(subPath, dirent))
|
|
86
86
|
return;
|
|
87
87
|
if (dirent.isDirectory()) {
|
|
88
88
|
handleDirectory(subPath, depth);
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
type Callback = () => void;
|
|
2
2
|
type ArrayMaybe<T> = T[] | T;
|
|
3
3
|
type PromiseMaybe<T> = Promise<T> | T;
|
|
4
|
-
type
|
|
4
|
+
type DirentLike = {
|
|
5
5
|
isFile: () => boolean;
|
|
6
6
|
isDirectory: () => boolean;
|
|
7
7
|
isBlockDevice: () => boolean;
|
|
@@ -9,6 +9,8 @@ type Dirent = {
|
|
|
9
9
|
isSymbolicLink: () => boolean;
|
|
10
10
|
isFIFO: () => boolean;
|
|
11
11
|
isSocket: () => boolean;
|
|
12
|
+
};
|
|
13
|
+
type Dirent = DirentLike & {
|
|
12
14
|
name: string;
|
|
13
15
|
path: string;
|
|
14
16
|
};
|
|
@@ -16,7 +18,7 @@ type Options = {
|
|
|
16
18
|
depth?: number;
|
|
17
19
|
limit?: number;
|
|
18
20
|
followSymlinks?: boolean;
|
|
19
|
-
ignore?: ArrayMaybe<((targetPath: string) => boolean) | RegExp>;
|
|
21
|
+
ignore?: ArrayMaybe<((targetPath: string, targetContext: DirentLike) => boolean) | RegExp>;
|
|
20
22
|
signal?: {
|
|
21
23
|
aborted: boolean;
|
|
22
24
|
};
|
|
@@ -27,4 +29,4 @@ type Result = {
|
|
|
27
29
|
files: string[];
|
|
28
30
|
symlinks: string[];
|
|
29
31
|
};
|
|
30
|
-
export type { Callback, PromiseMaybe, Dirent, Options, Result };
|
|
32
|
+
export type { Callback, PromiseMaybe, DirentLike, Dirent, Options, Result };
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"repository": "github:fabiospampinato/tiny-readdir",
|
|
4
4
|
"description": "A simple promisified recursive readdir function.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "3.
|
|
6
|
+
"version": "3.1.0",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"exports": "./dist/index.js",
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"clean": "tsex clean",
|
|
16
16
|
"compile": "tsex compile",
|
|
17
17
|
"compile:watch": "tsex compile --watch",
|
|
18
|
-
"test": "
|
|
18
|
+
"test": "tsex test",
|
|
19
19
|
"test:watch": "tsex test --watch",
|
|
20
|
-
"prepublishOnly": "npm run compile &&
|
|
20
|
+
"prepublishOnly": "npm run compile && node test/index.js"
|
|
21
21
|
},
|
|
22
22
|
"keywords": [
|
|
23
23
|
"readdir",
|
package/readme.md
CHANGED
|
@@ -20,16 +20,16 @@ const result = await readdir ( '/foo/bar', {
|
|
|
20
20
|
depth: 20, // Maximum depth to look at
|
|
21
21
|
limit: 1_000_000, // Maximum number of files explored, useful as a stop gap in some edge cases
|
|
22
22
|
followSymlinks: true, // Whether to follow symlinks or not
|
|
23
|
-
ignore: targetPath => /node_modules/.test ( targetPath ), // Function that if returns true will ignore this particular file or a directory and its descendants
|
|
23
|
+
ignore: ( targetPath, targetContext ) => /node_modules/.test ( targetPath ), // Function that if returns true will ignore this particular file or a directory and its descendants
|
|
24
24
|
signal: aborter.signal, // Optional abort signal, useful for aborting potentially expensive operations
|
|
25
25
|
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
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
// This is how we would abort the
|
|
28
|
+
// This is how we would abort the recursive read after 10s
|
|
29
29
|
|
|
30
30
|
setTimeout ( () => aborter.abort (), 10_000 ); // Aborting if it's going to take longer than 10s
|
|
31
31
|
|
|
32
|
-
// This is the result object will look like
|
|
32
|
+
// This is what the result object will look like
|
|
33
33
|
|
|
34
34
|
result.directories; // => Array of absolute paths pointing to directories
|
|
35
35
|
result.files; // => Array of absolute paths pointing to files
|