@allurereport/directory-watcher 3.8.2 → 3.9.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/watcher.d.ts +1 -0
- package/dist/watcher.js +42 -29
- package/package.json +2 -1
package/dist/watcher.d.ts
CHANGED
package/dist/watcher.js
CHANGED
|
@@ -46,35 +46,43 @@ export const findMatching = async (watchDirectory, existingResults, match, maxim
|
|
|
46
46
|
console.error("can't read directory", e);
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
-
const findFiles = async (watchDirectory, existingResults, onNewFile, recursive) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
49
|
+
const findFiles = async (watchDirectory, existingResults, onNewFile, recursive, maximumDepth = 10) => {
|
|
50
|
+
const scanDirectory = async (directory, isRoot, remainingDepth) => {
|
|
51
|
+
try {
|
|
52
|
+
const dir = await opendir(directory);
|
|
53
|
+
for await (const dirent of dir) {
|
|
54
|
+
const path = join(dirent.parentPath ?? dirent.path, dirent.name);
|
|
55
|
+
if (dirent.isDirectory()) {
|
|
56
|
+
if (recursive && remainingDepth > 0) {
|
|
57
|
+
await scanDirectory(path, false, remainingDepth - 1);
|
|
58
|
+
}
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (existingResults.has(path)) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
await onNewFile(path, dirent);
|
|
66
|
+
existingResults.add(path);
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
if (!isFileNotFoundError(e)) {
|
|
70
|
+
console.error("can't process file", path, e);
|
|
71
|
+
}
|
|
67
72
|
}
|
|
68
73
|
}
|
|
69
74
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
catch (e) {
|
|
76
|
+
if (isFileNotFoundError(e)) {
|
|
77
|
+
if (isRoot) {
|
|
78
|
+
existingResults.clear();
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
console.error("can't read directory", e);
|
|
75
83
|
}
|
|
76
|
-
|
|
77
|
-
|
|
84
|
+
};
|
|
85
|
+
await scanDirectory(watchDirectory, true, maximumDepth);
|
|
78
86
|
};
|
|
79
87
|
const singleIteration = async (callback, ...ac) => {
|
|
80
88
|
return setImmediate(undefined, { signal: AbortSignal.any(ac.map((c) => c.signal)) })
|
|
@@ -124,13 +132,13 @@ const watch = (initialCallback, iterationCallback, doneCallback, options = {}) =
|
|
|
124
132
|
};
|
|
125
133
|
};
|
|
126
134
|
export const newFilesInDirectoryWatcher = (directory, onNewFile, options = {}) => {
|
|
127
|
-
const { recursive = true, ignoreInitial = false, ...rest } = options;
|
|
135
|
+
const { recursive = true, maximumDepth = 10, ignoreInitial = false, ...rest } = options;
|
|
128
136
|
const indexedFiles = new Set();
|
|
129
137
|
const initialCallback = async () => {
|
|
130
|
-
await findFiles(directory, indexedFiles, ignoreInitial ? noop : onNewFile, recursive);
|
|
138
|
+
await findFiles(directory, indexedFiles, ignoreInitial ? noop : onNewFile, recursive, maximumDepth);
|
|
131
139
|
};
|
|
132
140
|
const iterationCallback = async () => {
|
|
133
|
-
await findFiles(directory, indexedFiles, onNewFile, recursive);
|
|
141
|
+
await findFiles(directory, indexedFiles, onNewFile, recursive, maximumDepth);
|
|
134
142
|
};
|
|
135
143
|
return watch(initialCallback, iterationCallback, iterationCallback, rest);
|
|
136
144
|
};
|
|
@@ -174,7 +182,12 @@ const waitUntilFileStopChanging = async (file, info, options) => {
|
|
|
174
182
|
}
|
|
175
183
|
const sinceChange = now - prev.timestamp;
|
|
176
184
|
if (sinceChange < minWait) {
|
|
177
|
-
|
|
185
|
+
const maxDelay = maxWait - (now - start);
|
|
186
|
+
if (maxDelay <= 0) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
await setTimeout(Math.min(maxDelay, minWait - sinceChange + 1));
|
|
190
|
+
continue;
|
|
178
191
|
}
|
|
179
192
|
const current = await calculateInfo(file);
|
|
180
193
|
if (!current) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@allurereport/directory-watcher",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.0",
|
|
4
4
|
"description": "File system watcher for directories",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"allure",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/node": "^20.17.9",
|
|
37
37
|
"@vitest/runner": "^2.1.9",
|
|
38
|
+
"allure-js-commons": "^3.3.3",
|
|
38
39
|
"allure-vitest": "^3.3.3",
|
|
39
40
|
"rimraf": "^6.0.1",
|
|
40
41
|
"ts-node": "^10.9.2",
|