tiny-readdir 2.3.0 → 2.5.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/constants.d.ts +5 -0
- package/dist/constants.js +9 -0
- package/dist/index.js +27 -6
- package/dist/types.d.ts +17 -1
- package/package.json +1 -1
- package/readme.md +6 -1
- package/src/constants.ts +16 -0
- package/src/index.ts +31 -6
- package/src/types.ts +21 -3
- package/test/index.js +46 -10
package/dist/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/* IMPORT */
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
+
import { NOOP_PROMISE_LIKE } from './constants.js';
|
|
4
5
|
import { isFunction, makeCounterPromise } from './utils.js';
|
|
5
6
|
/* MAIN */
|
|
7
|
+
//TODO: Streamline the type of dirnmaps
|
|
6
8
|
const readdir = (rootPath, options) => {
|
|
7
9
|
const followSymlinks = options?.followSymlinks ?? false;
|
|
8
10
|
const maxDepth = options?.depth ?? Infinity;
|
|
@@ -10,16 +12,20 @@ const readdir = (rootPath, options) => {
|
|
|
10
12
|
const ignore = options?.ignore ?? (() => false);
|
|
11
13
|
const isIgnored = isFunction(ignore) ? ignore : (targetPath) => ignore.test(targetPath);
|
|
12
14
|
const signal = options?.signal ?? { aborted: false };
|
|
15
|
+
const onDirents = options?.onDirents || (() => { });
|
|
13
16
|
const directories = [];
|
|
14
17
|
const directoriesNames = new Set();
|
|
18
|
+
const directoriesNamesToPaths = {};
|
|
15
19
|
const files = [];
|
|
16
20
|
const filesNames = new Set();
|
|
21
|
+
const filesNamesToPaths = {};
|
|
17
22
|
const symlinks = [];
|
|
18
23
|
const symlinksNames = new Set();
|
|
24
|
+
const symlinksNamesToPaths = {};
|
|
19
25
|
const map = {};
|
|
20
26
|
const visited = new Set();
|
|
21
|
-
const resultEmpty = { directories: [], directoriesNames: new Set(), files: [], filesNames: new Set(), symlinks: [], symlinksNames: new Set(), map: {} };
|
|
22
|
-
const result = { directories, directoriesNames, files, filesNames, symlinks, symlinksNames, map };
|
|
27
|
+
const resultEmpty = { directories: [], directoriesNames: new Set(), directoriesNamesToPaths: {}, files: [], filesNames: new Set(), filesNamesToPaths: {}, symlinks: [], symlinksNames: new Set(), symlinksNamesToPaths: {}, map: {} };
|
|
28
|
+
const result = { directories, directoriesNames, directoriesNamesToPaths, files, filesNames, filesNamesToPaths, symlinks, symlinksNames, symlinksNamesToPaths, map };
|
|
23
29
|
const { promise, increment, decrement } = makeCounterPromise();
|
|
24
30
|
let foundPaths = 0;
|
|
25
31
|
const handleDirectory = (dirmap, subPath, name, depth) => {
|
|
@@ -30,8 +36,12 @@ const readdir = (rootPath, options) => {
|
|
|
30
36
|
foundPaths += 1;
|
|
31
37
|
dirmap.directories.push(subPath);
|
|
32
38
|
dirmap.directoriesNames.add(name);
|
|
39
|
+
// dirmap.directoriesNamesToPaths.propertyIsEnumerable(name) || ( dirmap.directoriesNamesToPaths[name] = [] );
|
|
40
|
+
// dirmap.directoriesNamesToPaths[name].push ( subPath );
|
|
33
41
|
directories.push(subPath);
|
|
34
42
|
directoriesNames.add(name);
|
|
43
|
+
directoriesNamesToPaths.propertyIsEnumerable(name) || (directoriesNamesToPaths[name] = []);
|
|
44
|
+
directoriesNamesToPaths[name].push(subPath);
|
|
35
45
|
visited.add(subPath);
|
|
36
46
|
if (depth >= maxDepth)
|
|
37
47
|
return;
|
|
@@ -47,8 +57,12 @@ const readdir = (rootPath, options) => {
|
|
|
47
57
|
foundPaths += 1;
|
|
48
58
|
dirmap.files.push(subPath);
|
|
49
59
|
dirmap.filesNames.add(name);
|
|
60
|
+
// dirmap.filesNamesToPaths.propertyIsEnumerable(name) || ( dirmap.filesNamesToPaths[name] = [] );
|
|
61
|
+
// dirmap.filesNamesToPaths[name].push ( subPath );
|
|
50
62
|
files.push(subPath);
|
|
51
63
|
filesNames.add(name);
|
|
64
|
+
filesNamesToPaths.propertyIsEnumerable(name) || (filesNamesToPaths[name] = []);
|
|
65
|
+
filesNamesToPaths[name].push(subPath);
|
|
52
66
|
visited.add(subPath);
|
|
53
67
|
};
|
|
54
68
|
const handleSymlink = (dirmap, subPath, name, depth) => {
|
|
@@ -59,8 +73,12 @@ const readdir = (rootPath, options) => {
|
|
|
59
73
|
foundPaths += 1;
|
|
60
74
|
dirmap.symlinks.push(subPath);
|
|
61
75
|
dirmap.symlinksNames.add(name);
|
|
76
|
+
// dirmap.symlinksNamesToPaths.propertyIsEnumerable(name) || ( dirmap.symlinksNamesToPaths[name] = [] );
|
|
77
|
+
// dirmap.symlinksNamesToPaths[name].push ( subPath );
|
|
62
78
|
symlinks.push(subPath);
|
|
63
79
|
symlinksNames.add(name);
|
|
80
|
+
symlinksNamesToPaths.propertyIsEnumerable(name) || (symlinksNamesToPaths[name] = []);
|
|
81
|
+
symlinksNamesToPaths[name].push(subPath);
|
|
64
82
|
visited.add(subPath);
|
|
65
83
|
if (!followSymlinks)
|
|
66
84
|
return;
|
|
@@ -123,9 +141,12 @@ const readdir = (rootPath, options) => {
|
|
|
123
141
|
return decrement();
|
|
124
142
|
if (!dirents.length)
|
|
125
143
|
return decrement();
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
144
|
+
const promise = onDirents(dirents) || NOOP_PROMISE_LIKE;
|
|
145
|
+
promise.then(() => {
|
|
146
|
+
const dirmap = map[rootPath] = { directories: [], directoriesNames: new Set(), directoriesNamesToPaths: {}, files: [], filesNames: new Set(), filesNamesToPaths: {}, symlinks: [], symlinksNames: new Set(), symlinksNamesToPaths: {} };
|
|
147
|
+
handleDirents(dirmap, rootPath, dirents, depth);
|
|
148
|
+
decrement();
|
|
149
|
+
});
|
|
129
150
|
});
|
|
130
151
|
};
|
|
131
152
|
const populateResultFromSymlink = async (rootPath, depth) => {
|
|
@@ -141,7 +162,7 @@ const readdir = (rootPath, options) => {
|
|
|
141
162
|
if (signal.aborted)
|
|
142
163
|
return decrement();
|
|
143
164
|
const name = path.basename(realPath);
|
|
144
|
-
const dirmap = map[rootPath] = { directories: [], directoriesNames: new Set(), files: [], filesNames: new Set(), symlinks: [], symlinksNames: new Set() };
|
|
165
|
+
const dirmap = map[rootPath] = { directories: [], directoriesNames: new Set(), directoriesNamesToPaths: {}, files: [], filesNames: new Set(), filesNamesToPaths: {}, symlinks: [], symlinksNames: new Set(), symlinksNamesToPaths: {} };
|
|
145
166
|
handleStat(dirmap, realPath, name, stat, depth);
|
|
146
167
|
decrement();
|
|
147
168
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
type Callback = () => void;
|
|
2
|
+
type PromiseMaybe<T> = Promise<T> | T;
|
|
3
|
+
type Dirent = {
|
|
4
|
+
isFile: () => boolean;
|
|
5
|
+
isDirectory: () => boolean;
|
|
6
|
+
isBlockDevice: () => boolean;
|
|
7
|
+
isCharacterDevice: () => boolean;
|
|
8
|
+
isSymbolicLink: () => boolean;
|
|
9
|
+
isFIFO: () => boolean;
|
|
10
|
+
isSocket: () => boolean;
|
|
11
|
+
name: string;
|
|
12
|
+
path: string;
|
|
13
|
+
};
|
|
2
14
|
type Options = {
|
|
3
15
|
depth?: number;
|
|
4
16
|
limit?: number;
|
|
@@ -7,14 +19,18 @@ type Options = {
|
|
|
7
19
|
signal?: {
|
|
8
20
|
aborted: boolean;
|
|
9
21
|
};
|
|
22
|
+
onDirents?: (dirents: Dirent[]) => PromiseMaybe<undefined>;
|
|
10
23
|
};
|
|
11
24
|
type ResultDirectory = {
|
|
12
25
|
directories: string[];
|
|
13
26
|
directoriesNames: Set<string>;
|
|
27
|
+
directoriesNamesToPaths: Record<string, string[]>;
|
|
14
28
|
files: string[];
|
|
15
29
|
filesNames: Set<string>;
|
|
30
|
+
filesNamesToPaths: Record<string, string[]>;
|
|
16
31
|
symlinks: string[];
|
|
17
32
|
symlinksNames: Set<string>;
|
|
33
|
+
symlinksNamesToPaths: Record<string, string[]>;
|
|
18
34
|
};
|
|
19
35
|
type ResultDirectories = {
|
|
20
36
|
[path: string]: ResultDirectory;
|
|
@@ -22,4 +38,4 @@ type ResultDirectories = {
|
|
|
22
38
|
type Result = ResultDirectory & {
|
|
23
39
|
map: ResultDirectories;
|
|
24
40
|
};
|
|
25
|
-
export type { Callback, Options, ResultDirectory, ResultDirectories, Result };
|
|
41
|
+
export type { Callback, PromiseMaybe, Dirent, Options, ResultDirectory, ResultDirectories, Result };
|
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.
|
|
5
|
+
"version": "2.5.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"exports": "./dist/index.js",
|
package/readme.md
CHANGED
|
@@ -20,7 +20,8 @@ const result = await readdir ( '/foo/bar', {
|
|
|
20
20
|
limit: 1_000_000, // Maximum number of files explored, useful as a stop gap in some edge cases
|
|
21
21
|
followSymlinks: true, // Whether to follow symlinks or not
|
|
22
22
|
ignore: targetPath => /node_modules/.test ( targetPath ), // Function that if returns true will ignore this particular file or a directory and its descendants
|
|
23
|
-
signal: aborter.signal // Optional abort signal, useful for aborting potentially expensive operations
|
|
23
|
+
signal: aborter.signal, // Optional abort signal, useful for aborting potentially expensive operations
|
|
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
|
|
24
25
|
});
|
|
25
26
|
|
|
26
27
|
console.log ( result.directories ); // => Array of absolute paths pointing to directories
|
|
@@ -31,6 +32,10 @@ console.log ( result.directoriesNames ); // => Set of directories names found
|
|
|
31
32
|
console.log ( result.filesNames ); // => Set of files name found
|
|
32
33
|
console.log ( result.symlinksNames ); // => Set of symlinks names found
|
|
33
34
|
|
|
35
|
+
console.log ( result.directoriesNamesToPaths ); // => Record of directories names found to their paths
|
|
36
|
+
console.log ( result.filesNamesToPaths ); // => Record of files names found to their paths
|
|
37
|
+
console.log ( result.symlinksNamesToPaths ); // => Record of symlinks names found to their paths
|
|
38
|
+
|
|
34
39
|
setTimeout ( () => aborter.abort (), 10000 ); // Aborting if it's going to take longer than 10s
|
|
35
40
|
```
|
|
36
41
|
|
package/src/constants.ts
ADDED
package/src/index.ts
CHANGED
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
|
|
4
4
|
import fs from 'node:fs';
|
|
5
5
|
import path from 'node:path';
|
|
6
|
+
import {NOOP_PROMISE_LIKE} from './constants';
|
|
6
7
|
import {isFunction, makeCounterPromise} from './utils';
|
|
7
8
|
import type {Options, ResultDirectory, ResultDirectories, Result} from './types';
|
|
8
9
|
|
|
9
10
|
/* MAIN */
|
|
10
11
|
|
|
12
|
+
//TODO: Streamline the type of dirnmaps
|
|
13
|
+
|
|
11
14
|
const readdir = ( rootPath: string, options?: Options ): Promise<Result> => {
|
|
12
15
|
|
|
13
16
|
const followSymlinks = options?.followSymlinks ?? false;
|
|
@@ -16,16 +19,20 @@ const readdir = ( rootPath: string, options?: Options ): Promise<Result> => {
|
|
|
16
19
|
const ignore = options?.ignore ?? (() => false);
|
|
17
20
|
const isIgnored = isFunction ( ignore ) ? ignore : ( targetPath: string ) => ignore.test ( targetPath );
|
|
18
21
|
const signal = options?.signal ?? { aborted: false };
|
|
22
|
+
const onDirents = options?.onDirents || (() => {});
|
|
19
23
|
const directories: string[] = [];
|
|
20
24
|
const directoriesNames: Set<string> = new Set ();
|
|
25
|
+
const directoriesNamesToPaths: Record<string, string[]> = {};
|
|
21
26
|
const files: string[] = [];
|
|
22
27
|
const filesNames: Set<string> = new Set ();
|
|
28
|
+
const filesNamesToPaths: Record<string, string[]> = {};
|
|
23
29
|
const symlinks: string[] = [];
|
|
24
30
|
const symlinksNames: Set<string> = new Set ();
|
|
31
|
+
const symlinksNamesToPaths: Record<string, string[]> = {};
|
|
25
32
|
const map: ResultDirectories = {};
|
|
26
33
|
const visited = new Set<string> ();
|
|
27
|
-
const resultEmpty: Result = { directories: [], directoriesNames: new Set (), files: [], filesNames: new Set (), symlinks: [], symlinksNames: new Set (), map: {} };
|
|
28
|
-
const result: Result = { directories, directoriesNames, files, filesNames, symlinks, symlinksNames, map };
|
|
34
|
+
const resultEmpty: Result = { directories: [], directoriesNames: new Set (), directoriesNamesToPaths: {}, files: [], filesNames: new Set (), filesNamesToPaths: {}, symlinks: [], symlinksNames: new Set (), symlinksNamesToPaths: {}, map: {} };
|
|
35
|
+
const result: Result = { directories, directoriesNames, directoriesNamesToPaths, files, filesNames, filesNamesToPaths, symlinks, symlinksNames, symlinksNamesToPaths, map };
|
|
29
36
|
const {promise, increment, decrement} = makeCounterPromise ();
|
|
30
37
|
|
|
31
38
|
let foundPaths = 0;
|
|
@@ -39,8 +46,12 @@ const readdir = ( rootPath: string, options?: Options ): Promise<Result> => {
|
|
|
39
46
|
foundPaths += 1;
|
|
40
47
|
dirmap.directories.push ( subPath );
|
|
41
48
|
dirmap.directoriesNames.add ( name );
|
|
49
|
+
// dirmap.directoriesNamesToPaths.propertyIsEnumerable(name) || ( dirmap.directoriesNamesToPaths[name] = [] );
|
|
50
|
+
// dirmap.directoriesNamesToPaths[name].push ( subPath );
|
|
42
51
|
directories.push ( subPath );
|
|
43
52
|
directoriesNames.add ( name );
|
|
53
|
+
directoriesNamesToPaths.propertyIsEnumerable(name) || ( directoriesNamesToPaths[name] = [] );
|
|
54
|
+
directoriesNamesToPaths[name].push ( subPath );
|
|
44
55
|
visited.add ( subPath );
|
|
45
56
|
|
|
46
57
|
if ( depth >= maxDepth ) return;
|
|
@@ -60,8 +71,12 @@ const readdir = ( rootPath: string, options?: Options ): Promise<Result> => {
|
|
|
60
71
|
foundPaths += 1;
|
|
61
72
|
dirmap.files.push ( subPath );
|
|
62
73
|
dirmap.filesNames.add ( name );
|
|
74
|
+
// dirmap.filesNamesToPaths.propertyIsEnumerable(name) || ( dirmap.filesNamesToPaths[name] = [] );
|
|
75
|
+
// dirmap.filesNamesToPaths[name].push ( subPath );
|
|
63
76
|
files.push ( subPath );
|
|
64
77
|
filesNames.add ( name );
|
|
78
|
+
filesNamesToPaths.propertyIsEnumerable(name) || ( filesNamesToPaths[name] = [] );
|
|
79
|
+
filesNamesToPaths[name].push ( subPath );
|
|
65
80
|
visited.add ( subPath );
|
|
66
81
|
|
|
67
82
|
};
|
|
@@ -75,8 +90,12 @@ const readdir = ( rootPath: string, options?: Options ): Promise<Result> => {
|
|
|
75
90
|
foundPaths += 1;
|
|
76
91
|
dirmap.symlinks.push ( subPath );
|
|
77
92
|
dirmap.symlinksNames.add ( name );
|
|
93
|
+
// dirmap.symlinksNamesToPaths.propertyIsEnumerable(name) || ( dirmap.symlinksNamesToPaths[name] = [] );
|
|
94
|
+
// dirmap.symlinksNamesToPaths[name].push ( subPath );
|
|
78
95
|
symlinks.push ( subPath );
|
|
79
96
|
symlinksNames.add ( name );
|
|
97
|
+
symlinksNamesToPaths.propertyIsEnumerable(name) || ( symlinksNamesToPaths[name] = [] );
|
|
98
|
+
symlinksNamesToPaths[name].push ( subPath );
|
|
80
99
|
visited.add ( subPath );
|
|
81
100
|
|
|
82
101
|
if ( !followSymlinks ) return;
|
|
@@ -165,11 +184,17 @@ const readdir = ( rootPath: string, options?: Options ): Promise<Result> => {
|
|
|
165
184
|
|
|
166
185
|
if ( !dirents.length ) return decrement ();
|
|
167
186
|
|
|
168
|
-
const
|
|
187
|
+
const promise = onDirents ( dirents ) || NOOP_PROMISE_LIKE;
|
|
188
|
+
|
|
189
|
+
promise.then ( () => {
|
|
190
|
+
|
|
191
|
+
const dirmap = map[rootPath] = { directories: [], directoriesNames: new Set (), directoriesNamesToPaths: {}, files: [], filesNames: new Set (), filesNamesToPaths: {}, symlinks: [], symlinksNames: new Set (), symlinksNamesToPaths: {} };
|
|
169
192
|
|
|
170
|
-
|
|
193
|
+
handleDirents ( dirmap, rootPath, dirents, depth );
|
|
171
194
|
|
|
172
|
-
|
|
195
|
+
decrement ();
|
|
196
|
+
|
|
197
|
+
});
|
|
173
198
|
|
|
174
199
|
});
|
|
175
200
|
|
|
@@ -192,7 +217,7 @@ const readdir = ( rootPath: string, options?: Options ): Promise<Result> => {
|
|
|
192
217
|
if ( signal.aborted ) return decrement ();
|
|
193
218
|
|
|
194
219
|
const name = path.basename ( realPath );
|
|
195
|
-
const dirmap = map[rootPath] = { directories: [], directoriesNames: new Set (), files: [], filesNames: new Set (), symlinks: [], symlinksNames: new Set () };
|
|
220
|
+
const dirmap = map[rootPath] = { directories: [], directoriesNames: new Set (), directoriesNamesToPaths: {}, files: [], filesNames: new Set (), filesNamesToPaths: {}, symlinks: [], symlinksNames: new Set (), symlinksNamesToPaths: {} };
|
|
196
221
|
|
|
197
222
|
handleStat ( dirmap, realPath, name, stat, depth );
|
|
198
223
|
|
package/src/types.ts
CHANGED
|
@@ -3,23 +3,41 @@
|
|
|
3
3
|
|
|
4
4
|
type Callback = () => void;
|
|
5
5
|
|
|
6
|
+
type PromiseMaybe<T> = Promise<T> | T;
|
|
7
|
+
|
|
6
8
|
/* MAIN */
|
|
7
9
|
|
|
10
|
+
type Dirent = {
|
|
11
|
+
isFile: () => boolean,
|
|
12
|
+
isDirectory: () => boolean,
|
|
13
|
+
isBlockDevice: () => boolean,
|
|
14
|
+
isCharacterDevice: () => boolean,
|
|
15
|
+
isSymbolicLink: () => boolean,
|
|
16
|
+
isFIFO: () => boolean,
|
|
17
|
+
isSocket: () => boolean,
|
|
18
|
+
name: string,
|
|
19
|
+
path: string
|
|
20
|
+
};
|
|
21
|
+
|
|
8
22
|
type Options = {
|
|
9
23
|
depth?: number,
|
|
10
24
|
limit?: number,
|
|
11
25
|
followSymlinks?: boolean,
|
|
12
26
|
ignore?: (( targetPath: string ) => boolean) | RegExp,
|
|
13
|
-
signal?: { aborted: boolean }
|
|
27
|
+
signal?: { aborted: boolean },
|
|
28
|
+
onDirents?: ( dirents: Dirent[] ) => PromiseMaybe<undefined>
|
|
14
29
|
};
|
|
15
30
|
|
|
16
31
|
type ResultDirectory = {
|
|
17
32
|
directories: string[],
|
|
18
33
|
directoriesNames: Set<string>,
|
|
34
|
+
directoriesNamesToPaths: Record<string, string[]>,
|
|
19
35
|
files: string[],
|
|
20
36
|
filesNames: Set<string>,
|
|
37
|
+
filesNamesToPaths: Record<string, string[]>,
|
|
21
38
|
symlinks: string[],
|
|
22
|
-
symlinksNames: Set<string
|
|
39
|
+
symlinksNames: Set<string>,
|
|
40
|
+
symlinksNamesToPaths: Record<string, string[]>
|
|
23
41
|
};
|
|
24
42
|
|
|
25
43
|
type ResultDirectories = {
|
|
@@ -32,4 +50,4 @@ type Result = ResultDirectory & {
|
|
|
32
50
|
|
|
33
51
|
/* EXPORT */
|
|
34
52
|
|
|
35
|
-
export type {Callback, Options, ResultDirectory, ResultDirectories, Result};
|
|
53
|
+
export type {Callback, PromiseMaybe, Dirent, Options, ResultDirectory, ResultDirectories, Result};
|
package/test/index.js
CHANGED
|
@@ -46,66 +46,90 @@ describe ( 'Tiny Readdir', it => {
|
|
|
46
46
|
const expected = {
|
|
47
47
|
directories: [folder1Path, folder2Path, folder1DeepPath, root2Path],
|
|
48
48
|
directoriesNames: new Set ( [folder1Path, folder2Path, folder1DeepPath, root2Path].map ( toBasename ) ),
|
|
49
|
+
directoriesNamesToPaths: { folder1: [folder1Path], folder2: [folder2Path], deep: [folder1DeepPath], root2: [root2Path] },
|
|
49
50
|
files: [file1aPath, file1bPath, file2Path, fileDeep1Path],
|
|
50
51
|
filesNames: new Set ( [file1aPath, file1bPath, file2Path, fileDeep1Path].map ( toBasename ) ),
|
|
52
|
+
filesNamesToPaths: { 'file1a.txt': [file1aPath], 'file1b.txt': [file1bPath], 'file2.txt': [file2Path], 'file1.txt': [fileDeep1Path] },
|
|
51
53
|
symlinks: [symlink1FromPath, symlink2FromPath],
|
|
52
54
|
symlinksNames: new Set ( [symlink1FromPath, symlink2FromPath].map ( toBasename ) ),
|
|
55
|
+
symlinksNamesToPaths: { symlink: [symlink1FromPath, symlink2FromPath] },
|
|
53
56
|
map: {
|
|
54
57
|
[root1Path]: {
|
|
55
58
|
directories: [folder1Path, folder2Path],
|
|
56
59
|
directoriesNames: new Set ( [folder1Path, folder2Path].map ( toBasename ) ),
|
|
60
|
+
directoriesNamesToPaths: {},
|
|
57
61
|
files: [],
|
|
58
62
|
filesNames: new Set (),
|
|
63
|
+
filesNamesToPaths: {},
|
|
59
64
|
symlinks: [symlink1FromPath],
|
|
60
|
-
symlinksNames: new Set ( [symlink1FromPath].map ( toBasename ) )
|
|
65
|
+
symlinksNames: new Set ( [symlink1FromPath].map ( toBasename ) ),
|
|
66
|
+
symlinksNamesToPaths: {}
|
|
61
67
|
},
|
|
62
68
|
[root2Path]: {
|
|
63
69
|
directories: [],
|
|
64
70
|
directoriesNames: new Set (),
|
|
71
|
+
directoriesNamesToPaths: {},
|
|
65
72
|
files: [],
|
|
66
73
|
filesNames: new Set (),
|
|
74
|
+
filesNamesToPaths: {},
|
|
67
75
|
symlinks: [symlink2FromPath],
|
|
68
|
-
symlinksNames: new Set ( [symlink2FromPath].map ( toBasename ) )
|
|
76
|
+
symlinksNames: new Set ( [symlink2FromPath].map ( toBasename ) ),
|
|
77
|
+
symlinksNamesToPaths: {}
|
|
69
78
|
},
|
|
70
79
|
[folder1Path]: {
|
|
71
80
|
directories: [folder1DeepPath],
|
|
72
81
|
directoriesNames: new Set ( [folder1DeepPath].map ( toBasename ) ),
|
|
82
|
+
directoriesNamesToPaths: {},
|
|
73
83
|
files: [file1aPath, file1bPath],
|
|
74
84
|
filesNames: new Set ( [file1aPath, file1bPath].map ( toBasename ) ),
|
|
85
|
+
filesNamesToPaths: {},
|
|
75
86
|
symlinks: [],
|
|
76
|
-
symlinksNames: new Set ()
|
|
87
|
+
symlinksNames: new Set (),
|
|
88
|
+
symlinksNamesToPaths: {}
|
|
77
89
|
},
|
|
78
90
|
[folder2Path]: {
|
|
79
91
|
directories: [],
|
|
80
92
|
directoriesNames: new Set (),
|
|
93
|
+
directoriesNamesToPaths: {},
|
|
81
94
|
files: [file2Path],
|
|
82
95
|
filesNames: new Set ( [file2Path].map ( toBasename ) ),
|
|
96
|
+
filesNamesToPaths: {},
|
|
83
97
|
symlinks: [],
|
|
84
|
-
symlinksNames: new Set ()
|
|
98
|
+
symlinksNames: new Set (),
|
|
99
|
+
symlinksNamesToPaths: {}
|
|
85
100
|
},
|
|
86
101
|
[folder1DeepPath]: {
|
|
87
102
|
directories: [],
|
|
88
103
|
directoriesNames: new Set (),
|
|
104
|
+
directoriesNamesToPaths: {},
|
|
89
105
|
files: [fileDeep1Path],
|
|
90
106
|
filesNames: new Set ( [fileDeep1Path].map ( toBasename ) ),
|
|
107
|
+
filesNamesToPaths: {},
|
|
91
108
|
symlinks: [],
|
|
92
|
-
symlinksNames: new Set ()
|
|
109
|
+
symlinksNames: new Set (),
|
|
110
|
+
symlinksNamesToPaths: {}
|
|
93
111
|
},
|
|
94
112
|
[symlink1FromPath]: {
|
|
95
113
|
directories: [root2Path],
|
|
96
114
|
directoriesNames: new Set ( [root2Path].map ( toBasename ) ),
|
|
115
|
+
directoriesNamesToPaths: {},
|
|
97
116
|
files: [],
|
|
98
117
|
filesNames: new Set (),
|
|
118
|
+
filesNamesToPaths: {},
|
|
99
119
|
symlinks: [],
|
|
100
|
-
symlinksNames: new Set ()
|
|
120
|
+
symlinksNames: new Set (),
|
|
121
|
+
symlinksNamesToPaths: {}
|
|
101
122
|
},
|
|
102
123
|
[symlink2FromPath]: {
|
|
103
124
|
directories: [],
|
|
104
125
|
directoriesNames: new Set (),
|
|
126
|
+
directoriesNamesToPaths: {},
|
|
105
127
|
files: [],
|
|
106
128
|
filesNames: new Set (),
|
|
129
|
+
filesNamesToPaths: {},
|
|
107
130
|
symlinks: [],
|
|
108
|
-
symlinksNames: new Set ()
|
|
131
|
+
symlinksNames: new Set (),
|
|
132
|
+
symlinksNamesToPaths: {}
|
|
109
133
|
}
|
|
110
134
|
}
|
|
111
135
|
};
|
|
@@ -157,34 +181,46 @@ describe ( 'Tiny Readdir', it => {
|
|
|
157
181
|
const expected = {
|
|
158
182
|
directories: [folder1Path, folder2Path],
|
|
159
183
|
directoriesNames: new Set ( [folder1Path, folder2Path].map ( toBasename ) ),
|
|
184
|
+
directoriesNamesToPaths: { folder1: [folder1Path], folder2: [folder2Path] },
|
|
160
185
|
files: [],
|
|
161
186
|
filesNames: new Set (),
|
|
187
|
+
filesNamesToPaths: {},
|
|
162
188
|
symlinks: [symlink1FromPath],
|
|
163
189
|
symlinksNames: new Set ( [symlink1FromPath].map ( toBasename ) ),
|
|
190
|
+
symlinksNamesToPaths: { symlink: [symlink1FromPath] },
|
|
164
191
|
map: {
|
|
165
192
|
[root1Path]: {
|
|
166
193
|
directories: [folder1Path, folder2Path],
|
|
167
194
|
directoriesNames: new Set ( [folder1Path, folder2Path].map ( toBasename ) ),
|
|
195
|
+
directoriesNamesToPaths: {},
|
|
168
196
|
files: [],
|
|
169
197
|
filesNames: new Set (),
|
|
198
|
+
filesNamesToPaths: {},
|
|
170
199
|
symlinks: [symlink1FromPath],
|
|
171
|
-
symlinksNames: new Set ( [symlink1FromPath].map ( toBasename ) )
|
|
200
|
+
symlinksNames: new Set ( [symlink1FromPath].map ( toBasename ) ),
|
|
201
|
+
symlinksNamesToPaths: {}
|
|
172
202
|
},
|
|
173
203
|
[folder1Path]: {
|
|
174
204
|
directories: [],
|
|
175
205
|
directoriesNames: new Set (),
|
|
206
|
+
directoriesNamesToPaths: {},
|
|
176
207
|
files: [],
|
|
177
208
|
filesNames: new Set (),
|
|
209
|
+
filesNamesToPaths: {},
|
|
178
210
|
symlinks: [],
|
|
179
|
-
symlinksNames: new Set ()
|
|
211
|
+
symlinksNames: new Set (),
|
|
212
|
+
symlinksNamesToPaths: {}
|
|
180
213
|
},
|
|
181
214
|
[folder2Path]: {
|
|
182
215
|
directories: [],
|
|
183
216
|
directoriesNames: new Set (),
|
|
217
|
+
directoriesNamesToPaths: {},
|
|
184
218
|
files: [],
|
|
185
219
|
filesNames: new Set (),
|
|
220
|
+
filesNamesToPaths: {},
|
|
186
221
|
symlinks: [],
|
|
187
|
-
symlinksNames: new Set ()
|
|
222
|
+
symlinksNames: new Set (),
|
|
223
|
+
symlinksNamesToPaths: {}
|
|
188
224
|
}
|
|
189
225
|
}
|
|
190
226
|
};
|