zcw-shared 1.13.7 → 1.13.8
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.
|
@@ -1,27 +1,59 @@
|
|
|
1
1
|
export function walk(dir, options = {}, deps) {
|
|
2
2
|
const { fs, path } = deps;
|
|
3
|
-
const { prefix = '', extensions = ['.ts'], excludeExtensions = ['.d.ts'], excludeNames = ['index'] } = options;
|
|
3
|
+
const { prefix = '', extensions = ['.ts'], excludeExtensions = ['.d.ts'], excludeNames = ['index'], followSymlinks = false } = options;
|
|
4
4
|
let results = [];
|
|
5
5
|
if (!fs.existsSync(dir)) {
|
|
6
6
|
return results;
|
|
7
7
|
}
|
|
8
|
-
fs.readdirSync(dir)
|
|
8
|
+
const files = fs.readdirSync(dir);
|
|
9
|
+
const visitedPaths = new Set();
|
|
10
|
+
for (const file of files) {
|
|
9
11
|
const fullPath = path.join(dir, file);
|
|
10
12
|
const relPath = path.join(prefix, file);
|
|
11
|
-
|
|
13
|
+
const lstat = fs.lstatSync(fullPath);
|
|
14
|
+
const stat = followSymlinks ? fs.statSync(fullPath) : lstat;
|
|
15
|
+
if (lstat.isSymbolicLink()) {
|
|
16
|
+
if (!followSymlinks) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const realPath = fs.realpathSync(fullPath);
|
|
21
|
+
if (visitedPaths.has(realPath)) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
visitedPaths.add(realPath);
|
|
25
|
+
if (!fs.existsSync(realPath)) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (stat.isDirectory()) {
|
|
12
34
|
results = results.concat(walk(fullPath, { ...options, prefix: relPath }, deps));
|
|
13
35
|
}
|
|
14
|
-
else {
|
|
15
|
-
const
|
|
36
|
+
else if (stat.isFile()) {
|
|
37
|
+
const lastDotIndex = file.lastIndexOf('.');
|
|
38
|
+
const fileExtension = lastDotIndex > 0 ? file.substring(lastDotIndex) : '';
|
|
39
|
+
let fileName = lastDotIndex > 0 ? file.substring(0, lastDotIndex) : file;
|
|
40
|
+
if (fileName === '') {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const hasValidExtension = extensions.some(ext => {
|
|
44
|
+
if (ext === '') {
|
|
45
|
+
return fileExtension === '';
|
|
46
|
+
}
|
|
47
|
+
return file.endsWith(ext);
|
|
48
|
+
});
|
|
16
49
|
const hasExcludedExtension = excludeExtensions.some(ext => file.endsWith(ext));
|
|
17
|
-
const fileName = file.substring(0, file.lastIndexOf('.'));
|
|
18
50
|
const isExcludedName = excludeNames.includes(fileName);
|
|
19
51
|
if (hasValidExtension && !hasExcludedExtension && !isExcludedName) {
|
|
20
52
|
const posixPath = path.posix.join(prefix.split(path.sep).join(path.posix.sep), fileName);
|
|
21
53
|
results.push(posixPath);
|
|
22
54
|
}
|
|
23
55
|
}
|
|
24
|
-
}
|
|
56
|
+
}
|
|
25
57
|
return results;
|
|
26
58
|
}
|
|
27
59
|
//# sourceMappingURL=walk.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"walk.js","sourceRoot":"","sources":["../../../src/functions/utils/walk.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"walk.js","sourceRoot":"","sources":["../../../src/functions/utils/walk.ts"],"names":[],"mappings":"AAwBA,MAAM,UAAU,IAAI,CAClB,GAAW,EACX,UAMI,EAAE,EACN,IAAsB;IAEtB,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,IAAI,CAAA;IACzB,MAAM,EACJ,MAAM,GAAG,EAAE,EACX,UAAU,GAAG,CAAC,KAAK,CAAC,EACpB,iBAAiB,GAAG,CAAC,OAAO,CAAC,EAC7B,YAAY,GAAG,CAAC,OAAO,CAAC,EACxB,cAAc,GAAG,KAAK,EACvB,G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,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAC3C,QAAQ,CACT,CAAC;gBACF,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC1B,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/package.json
CHANGED
package/references/node.d.ts
CHANGED
|
@@ -35,7 +35,9 @@ export interface FileSystem {
|
|
|
35
35
|
copyFileSync(src: string, dest: string): void
|
|
36
36
|
existsSync(path: string): boolean
|
|
37
37
|
readdirSync(path: string): string[]
|
|
38
|
-
statSync(path: string): { isDirectory(): boolean; isFile(): boolean }
|
|
38
|
+
statSync(path: string): { isDirectory(): boolean; isFile(): boolean; isSymbolicLink(): boolean }
|
|
39
|
+
lstatSync(path: string): { isDirectory(): boolean; isFile(): boolean; isSymbolicLink(): boolean }
|
|
40
|
+
realpathSync(path: string): string
|
|
39
41
|
promises: {
|
|
40
42
|
cp(source: string, destination: string, options?: any): Promise<void>
|
|
41
43
|
}
|