@holoscript/std 7.0.0 → 7.0.1
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/README.md +8 -0
- package/dist/chunk-DGUM43GV.js +11 -0
- package/dist/{chunk-PFX2JM4X.js → chunk-FAMOLKH3.js} +2 -1
- package/dist/{chunk-PFX2JM4X.js.map → chunk-FAMOLKH3.js.map} +1 -1
- package/dist/{chunk-DZHAVOCH.js → chunk-SOKH6FJ7.js} +31 -6
- package/dist/chunk-SOKH6FJ7.js.map +1 -0
- package/dist/collections.cjs +1 -0
- package/dist/collections.cjs.map +1 -1
- package/dist/collections.js +2 -2
- package/dist/fs/fs.d.ts.map +1 -1
- package/dist/fs/index.cjs +221 -8510
- package/dist/fs/index.cjs.map +1 -1
- package/dist/fs/index.js +832 -118
- package/dist/fs/index.js.map +1 -1
- package/dist/fs/sandbox.d.ts +49 -0
- package/dist/fs/sandbox.d.ts.map +1 -0
- package/dist/index.cjs +3494 -12672
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -7
- package/dist/index.js.map +1 -1
- package/dist/math.cjs +18 -3
- package/dist/math.cjs.map +1 -1
- package/dist/math.js +2 -2
- package/dist/string.js +1 -1
- package/dist/time.js +1 -1
- package/dist/traits/EconomicPrimitives.js +1 -1
- package/dist/traits/EconomicTraits.js +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +19 -9
- package/dist/__tests__/EconomicPrimitives.test.d.ts +0 -2
- package/dist/__tests__/EconomicPrimitives.test.d.ts.map +0 -1
- package/dist/__tests__/EconomicTraits.test.d.ts +0 -2
- package/dist/__tests__/EconomicTraits.test.d.ts.map +0 -1
- package/dist/__tests__/SimulationLabPrimitives.test.d.ts +0 -2
- package/dist/__tests__/SimulationLabPrimitives.test.d.ts.map +0 -1
- package/dist/__tests__/collections.test.d.ts +0 -2
- package/dist/__tests__/collections.test.d.ts.map +0 -1
- package/dist/__tests__/events.test.d.ts +0 -2
- package/dist/__tests__/events.test.d.ts.map +0 -1
- package/dist/__tests__/index.test.d.ts +0 -2
- package/dist/__tests__/index.test.d.ts.map +0 -1
- package/dist/__tests__/materials.test.d.ts +0 -2
- package/dist/__tests__/materials.test.d.ts.map +0 -1
- package/dist/__tests__/math.test.d.ts +0 -2
- package/dist/__tests__/math.test.d.ts.map +0 -1
- package/dist/__tests__/physics.test.d.ts +0 -2
- package/dist/__tests__/physics.test.d.ts.map +0 -1
- package/dist/__tests__/spatial.test.d.ts +0 -2
- package/dist/__tests__/spatial.test.d.ts.map +0 -1
- package/dist/__tests__/standard-library-fundamentals.test.d.ts +0 -2
- package/dist/__tests__/standard-library-fundamentals.test.d.ts.map +0 -1
- package/dist/__tests__/string-and-time-utilities.test.d.ts +0 -2
- package/dist/__tests__/string-and-time-utilities.test.d.ts.map +0 -1
- package/dist/__tests__/string-decoupled.test.d.ts +0 -2
- package/dist/__tests__/string-decoupled.test.d.ts.map +0 -1
- package/dist/__tests__/string.test.d.ts +0 -2
- package/dist/__tests__/string.test.d.ts.map +0 -1
- package/dist/__tests__/time.test.d.ts +0 -2
- package/dist/__tests__/time.test.d.ts.map +0 -1
- package/dist/chunk-DZHAVOCH.js.map +0 -1
- package/dist/chunk-PR4QN5HX.js +0 -43
- package/dist/chunk-XBA4ARST.js +0 -9313
- package/dist/chunk-XBA4ARST.js.map +0 -1
- package/dist/fs/__tests__/file-watch-system.test.d.ts +0 -2
- package/dist/fs/__tests__/file-watch-system.test.d.ts.map +0 -1
- package/dist/fs/__tests__/path-utilities.test.d.ts +0 -2
- package/dist/fs/__tests__/path-utilities.test.d.ts.map +0 -1
- package/dist/fs/__tests__/path.test.d.ts +0 -2
- package/dist/fs/__tests__/path.test.d.ts.map +0 -1
- package/dist/string.basic.test.d.ts +0 -5
- package/dist/string.basic.test.d.ts.map +0 -1
- package/dist/string.test.d.ts +0 -5
- package/dist/string.test.d.ts.map +0 -1
- package/dist/traits/__tests__/ARTraits.test.d.ts +0 -2
- package/dist/traits/__tests__/ARTraits.test.d.ts.map +0 -1
- package/dist/traits/__tests__/EconomicPrimitives.test.d.ts +0 -2
- package/dist/traits/__tests__/EconomicPrimitives.test.d.ts.map +0 -1
- package/dist/traits/__tests__/EconomicTraits.test.d.ts +0 -2
- package/dist/traits/__tests__/EconomicTraits.test.d.ts.map +0 -1
- package/error-utf8.log +0 -6
- package/error.log +0 -0
- package/src/__tests__/EconomicPrimitives.test.ts +0 -690
- package/src/__tests__/EconomicTraits.test.ts +0 -425
- package/src/__tests__/SimulationLabPrimitives.test.ts +0 -415
- package/src/__tests__/collections.test.ts +0 -182
- package/src/__tests__/events.test.ts +0 -135
- package/src/__tests__/index.test.ts +0 -14
- package/src/__tests__/materials.test.ts +0 -84
- package/src/__tests__/math.test.ts +0 -246
- package/src/__tests__/physics.test.ts +0 -83
- package/src/__tests__/spatial.test.ts +0 -333
- package/src/__tests__/standard-library-fundamentals.test.ts +0 -1318
- package/src/__tests__/string-and-time-utilities.test.ts +0 -1070
- package/src/__tests__/string-decoupled.test.ts +0 -13
- package/src/__tests__/string.test.ts +0 -164
- package/src/__tests__/time.test.ts +0 -110
- package/src/collections.ts +0 -850
- package/src/events.ts +0 -88
- package/src/fs/__tests__/file-watch-system.test.ts +0 -675
- package/src/fs/__tests__/path-utilities.test.ts +0 -375
- package/src/fs/__tests__/path.test.ts +0 -287
- package/src/fs/fs.ts +0 -692
- package/src/fs/index.ts +0 -194
- package/src/fs/path.ts +0 -310
- package/src/fs/watch.ts +0 -413
- package/src/index.ts +0 -476
- package/src/materials.ts +0 -109
- package/src/math.ts +0 -674
- package/src/physics.ts +0 -141
- package/src/spatial.ts +0 -320
- package/src/string.basic.test.ts +0 -14
- package/src/string.test.ts +0 -335
- package/src/string.ts +0 -531
- package/src/time.ts +0 -621
- package/src/traits/ARTraits.ts +0 -103
- package/src/traits/EconomicPrimitives.ts +0 -755
- package/src/traits/EconomicTraits.ts +0 -552
- package/src/traits/IoTTraits.ts +0 -102
- package/src/traits/SimulationLabPrimitives.ts +0 -650
- package/src/traits/SimulationLabTraits.ts +0 -191
- package/src/traits/VRRTraits.ts +0 -326
- package/src/traits/__tests__/ARTraits.test.ts +0 -8
- package/src/traits/__tests__/EconomicPrimitives.test.ts +0 -14
- package/src/traits/__tests__/EconomicTraits.test.ts +0 -16
- package/src/types.ts +0 -418
- package/std_error.log +0 -5
- package/tsconfig.json +0 -18
- package/tsup.config.ts +0 -20
- package/vitest.config.ts +0 -10
- /package/dist/{chunk-PR4QN5HX.js.map → chunk-DGUM43GV.js.map} +0 -0
package/src/fs/watch.ts
DELETED
|
@@ -1,413 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @holoscript/fs - File Watch Module
|
|
3
|
-
*
|
|
4
|
-
* File and directory watching utilities for HoloScript Plus programs.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import chokidar, { type FSWatcher, type WatchOptions as ChokidarOptions } from 'chokidar';
|
|
8
|
-
import { EventEmitter } from 'events';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Watch event types
|
|
12
|
-
*/
|
|
13
|
-
export type WatchEventType =
|
|
14
|
-
| 'add'
|
|
15
|
-
| 'change'
|
|
16
|
-
| 'unlink'
|
|
17
|
-
| 'addDir'
|
|
18
|
-
| 'unlinkDir'
|
|
19
|
-
| 'error'
|
|
20
|
-
| 'ready';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Watch event
|
|
24
|
-
*/
|
|
25
|
-
export interface WatchEvent {
|
|
26
|
-
type: WatchEventType;
|
|
27
|
-
path: string;
|
|
28
|
-
stats?: {
|
|
29
|
-
size: number;
|
|
30
|
-
mtime: Date;
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Watch options
|
|
36
|
-
*/
|
|
37
|
-
export interface WatchOptions {
|
|
38
|
-
/** Glob patterns to ignore */
|
|
39
|
-
ignored?: string | string[];
|
|
40
|
-
/** Use polling instead of native events */
|
|
41
|
-
usePolling?: boolean;
|
|
42
|
-
/** Polling interval in ms */
|
|
43
|
-
interval?: number;
|
|
44
|
-
/** Emit events for initial files */
|
|
45
|
-
emitInitial?: boolean;
|
|
46
|
-
/** Follow symlinks */
|
|
47
|
-
followSymlinks?: boolean;
|
|
48
|
-
/** Watch depth */
|
|
49
|
-
depth?: number;
|
|
50
|
-
/** Persistent watch */
|
|
51
|
-
persistent?: boolean;
|
|
52
|
-
/** Debounce delay in ms */
|
|
53
|
-
debounce?: number;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Watch callback
|
|
58
|
-
*/
|
|
59
|
-
export type WatchCallback = (event: WatchEvent) => void | Promise<void>;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* File watcher class
|
|
63
|
-
*/
|
|
64
|
-
export class FileWatcher extends EventEmitter {
|
|
65
|
-
private watcher: FSWatcher | null = null;
|
|
66
|
-
private paths: string[];
|
|
67
|
-
private options: WatchOptions;
|
|
68
|
-
private debounceTimers: Map<string, NodeJS.Timeout> = new Map();
|
|
69
|
-
|
|
70
|
-
constructor(paths: string | string[], options: WatchOptions = {}) {
|
|
71
|
-
super();
|
|
72
|
-
this.paths = Array.isArray(paths) ? paths : [paths];
|
|
73
|
-
this.options = {
|
|
74
|
-
ignored: options.ignored || ['**/node_modules/**', '**/.git/**'],
|
|
75
|
-
usePolling: options.usePolling || false,
|
|
76
|
-
interval: options.interval || 100,
|
|
77
|
-
emitInitial: options.emitInitial ?? true,
|
|
78
|
-
followSymlinks: options.followSymlinks ?? true,
|
|
79
|
-
depth: options.depth,
|
|
80
|
-
persistent: options.persistent ?? true,
|
|
81
|
-
debounce: options.debounce || 0,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Start watching
|
|
87
|
-
*/
|
|
88
|
-
start(): this {
|
|
89
|
-
if (this.watcher) {
|
|
90
|
-
return this;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const chokidarOpts: ChokidarOptions = {
|
|
94
|
-
ignored: this.options.ignored,
|
|
95
|
-
persistent: this.options.persistent,
|
|
96
|
-
followSymlinks: this.options.followSymlinks,
|
|
97
|
-
depth: this.options.depth,
|
|
98
|
-
usePolling: this.options.usePolling,
|
|
99
|
-
interval: this.options.interval,
|
|
100
|
-
ignoreInitial: !this.options.emitInitial,
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
this.watcher = chokidar.watch(this.paths, chokidarOpts);
|
|
104
|
-
|
|
105
|
-
this.watcher.on('add', (path, stats) => this.handleEvent('add', path, stats));
|
|
106
|
-
this.watcher.on('change', (path, stats) => this.handleEvent('change', path, stats));
|
|
107
|
-
this.watcher.on('unlink', (path) => this.handleEvent('unlink', path));
|
|
108
|
-
this.watcher.on('addDir', (path, stats) => this.handleEvent('addDir', path, stats));
|
|
109
|
-
this.watcher.on('unlinkDir', (path) => this.handleEvent('unlinkDir', path));
|
|
110
|
-
this.watcher.on('error', (error) => this.emit('error', error));
|
|
111
|
-
this.watcher.on('ready', () => this.emit('ready'));
|
|
112
|
-
|
|
113
|
-
return this;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Stop watching
|
|
118
|
-
*/
|
|
119
|
-
async stop(): Promise<void> {
|
|
120
|
-
if (this.watcher) {
|
|
121
|
-
await this.watcher.close();
|
|
122
|
-
this.watcher = null;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
for (const timer of this.debounceTimers.values()) {
|
|
126
|
-
clearTimeout(timer);
|
|
127
|
-
}
|
|
128
|
-
this.debounceTimers.clear();
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Add paths to watch
|
|
133
|
-
*/
|
|
134
|
-
add(paths: string | string[]): this {
|
|
135
|
-
const pathsArray = Array.isArray(paths) ? paths : [paths];
|
|
136
|
-
this.paths.push(...pathsArray);
|
|
137
|
-
this.watcher?.add(pathsArray);
|
|
138
|
-
return this;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Remove paths from watch
|
|
143
|
-
*/
|
|
144
|
-
unwatch(paths: string | string[]): this {
|
|
145
|
-
const pathsArray = Array.isArray(paths) ? paths : [paths];
|
|
146
|
-
this.paths = this.paths.filter((p) => !pathsArray.includes(p));
|
|
147
|
-
this.watcher?.unwatch(pathsArray);
|
|
148
|
-
return this;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Get watched paths
|
|
153
|
-
*/
|
|
154
|
-
getWatched(): Record<string, string[]> {
|
|
155
|
-
return this.watcher?.getWatched() || {};
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Check if watcher is ready
|
|
160
|
-
*/
|
|
161
|
-
get isReady(): boolean {
|
|
162
|
-
return this.watcher !== null;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Register event handler
|
|
167
|
-
*/
|
|
168
|
-
on(
|
|
169
|
-
event: 'add' | 'change' | 'unlink' | 'addDir' | 'unlinkDir' | 'all',
|
|
170
|
-
listener: (event: WatchEvent) => void
|
|
171
|
-
): this;
|
|
172
|
-
on(event: 'error', listener: (error: Error) => void): this;
|
|
173
|
-
on(event: 'ready', listener: () => void): this;
|
|
174
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
175
|
-
on(event: string, listener: (...args: any[]) => void): this {
|
|
176
|
-
return super.on(event, listener);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
private handleEvent(
|
|
180
|
-
type: WatchEventType,
|
|
181
|
-
path: string,
|
|
182
|
-
stats?: { size: number; mtime: Date }
|
|
183
|
-
): void {
|
|
184
|
-
const event: WatchEvent = {
|
|
185
|
-
type,
|
|
186
|
-
path,
|
|
187
|
-
stats: stats
|
|
188
|
-
? {
|
|
189
|
-
size: stats.size,
|
|
190
|
-
mtime: stats.mtime,
|
|
191
|
-
}
|
|
192
|
-
: undefined,
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
if (this.options.debounce && this.options.debounce > 0) {
|
|
196
|
-
// Debounce the event
|
|
197
|
-
if (this.debounceTimers.has(path)) {
|
|
198
|
-
clearTimeout(this.debounceTimers.get(path));
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
this.debounceTimers.set(
|
|
202
|
-
path,
|
|
203
|
-
setTimeout(() => {
|
|
204
|
-
this.debounceTimers.delete(path);
|
|
205
|
-
this.emitEvent(event);
|
|
206
|
-
}, this.options.debounce)
|
|
207
|
-
);
|
|
208
|
-
} else {
|
|
209
|
-
this.emitEvent(event);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
private emitEvent(event: WatchEvent): void {
|
|
214
|
-
this.emit(event.type, event);
|
|
215
|
-
this.emit('all', event);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Watch files/directories
|
|
221
|
-
*/
|
|
222
|
-
export function watch(paths: string | string[], options?: WatchOptions): FileWatcher {
|
|
223
|
-
return new FileWatcher(paths, options).start();
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Watch and run callback on changes
|
|
228
|
-
*/
|
|
229
|
-
export function watchCallback(
|
|
230
|
-
paths: string | string[],
|
|
231
|
-
callback: WatchCallback,
|
|
232
|
-
options?: WatchOptions
|
|
233
|
-
): FileWatcher {
|
|
234
|
-
const watcher = watch(paths, options);
|
|
235
|
-
|
|
236
|
-
watcher.on('all', async (event) => {
|
|
237
|
-
try {
|
|
238
|
-
await callback(event);
|
|
239
|
-
} catch (error) {
|
|
240
|
-
watcher.emit('error', error);
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
return watcher;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Watch for specific file types
|
|
249
|
-
*/
|
|
250
|
-
export function watchFileTypes(
|
|
251
|
-
dir: string,
|
|
252
|
-
extensions: string[],
|
|
253
|
-
callback: WatchCallback,
|
|
254
|
-
options?: WatchOptions
|
|
255
|
-
): FileWatcher {
|
|
256
|
-
const patterns = extensions.map((ext) => {
|
|
257
|
-
const e = ext.startsWith('.') ? ext : `.${ext}`;
|
|
258
|
-
return `${dir}/**/*${e}`;
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
return watchCallback(patterns, callback, options);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Watch a single file
|
|
266
|
-
*/
|
|
267
|
-
export function watchFile(
|
|
268
|
-
path: string,
|
|
269
|
-
callback: WatchCallback,
|
|
270
|
-
options?: WatchOptions
|
|
271
|
-
): FileWatcher {
|
|
272
|
-
return watchCallback(path, callback, { ...options, depth: 0 });
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Watch and debounce - only emit after changes have stopped for a duration
|
|
277
|
-
*/
|
|
278
|
-
export function watchDebounced(
|
|
279
|
-
paths: string | string[],
|
|
280
|
-
callback: WatchCallback,
|
|
281
|
-
debounceMs = 300,
|
|
282
|
-
options?: WatchOptions
|
|
283
|
-
): FileWatcher {
|
|
284
|
-
return watchCallback(paths, callback, { ...options, debounce: debounceMs });
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* One-shot watch - stop after first event
|
|
289
|
-
*/
|
|
290
|
-
export async function watchOnce(
|
|
291
|
-
paths: string | string[],
|
|
292
|
-
options?: WatchOptions
|
|
293
|
-
): Promise<WatchEvent> {
|
|
294
|
-
return new Promise((resolve, reject) => {
|
|
295
|
-
const watcher = watch(paths, { ...options, emitInitial: false });
|
|
296
|
-
|
|
297
|
-
const cleanup = async () => {
|
|
298
|
-
await watcher.stop();
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
watcher.on('all', async (event) => {
|
|
302
|
-
await cleanup();
|
|
303
|
-
resolve(event);
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
watcher.on('error', async (error) => {
|
|
307
|
-
await cleanup();
|
|
308
|
-
reject(error);
|
|
309
|
-
});
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Watch with batching - collect events and emit in batches
|
|
315
|
-
*/
|
|
316
|
-
export function watchBatched(
|
|
317
|
-
paths: string | string[],
|
|
318
|
-
callback: (events: WatchEvent[]) => void | Promise<void>,
|
|
319
|
-
batchMs = 100,
|
|
320
|
-
options?: WatchOptions
|
|
321
|
-
): FileWatcher {
|
|
322
|
-
const watcher = watch(paths, options);
|
|
323
|
-
let batch: WatchEvent[] = [];
|
|
324
|
-
let timer: NodeJS.Timeout | null = null;
|
|
325
|
-
|
|
326
|
-
const flush = async () => {
|
|
327
|
-
if (batch.length > 0) {
|
|
328
|
-
const events = [...batch];
|
|
329
|
-
batch = [];
|
|
330
|
-
try {
|
|
331
|
-
await callback(events);
|
|
332
|
-
} catch (error) {
|
|
333
|
-
watcher.emit('error', error);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
watcher.on('all', (event) => {
|
|
339
|
-
batch.push(event);
|
|
340
|
-
|
|
341
|
-
if (timer) {
|
|
342
|
-
clearTimeout(timer);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
timer = setTimeout(flush, batchMs);
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
// Extend stop to flush remaining
|
|
349
|
-
const originalStop = watcher.stop.bind(watcher);
|
|
350
|
-
watcher.stop = async () => {
|
|
351
|
-
if (timer) {
|
|
352
|
-
clearTimeout(timer);
|
|
353
|
-
}
|
|
354
|
-
await flush();
|
|
355
|
-
await originalStop();
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
return watcher;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* Watch with filtering
|
|
363
|
-
*/
|
|
364
|
-
export function watchFiltered(
|
|
365
|
-
paths: string | string[],
|
|
366
|
-
filter: (event: WatchEvent) => boolean,
|
|
367
|
-
callback: WatchCallback,
|
|
368
|
-
options?: WatchOptions
|
|
369
|
-
): FileWatcher {
|
|
370
|
-
return watchCallback(
|
|
371
|
-
paths,
|
|
372
|
-
async (event) => {
|
|
373
|
-
if (filter(event)) {
|
|
374
|
-
await callback(event);
|
|
375
|
-
}
|
|
376
|
-
},
|
|
377
|
-
options
|
|
378
|
-
);
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* Watch only for specific event types
|
|
383
|
-
*/
|
|
384
|
-
export function watchEvents(
|
|
385
|
-
paths: string | string[],
|
|
386
|
-
eventTypes: WatchEventType[],
|
|
387
|
-
callback: WatchCallback,
|
|
388
|
-
options?: WatchOptions
|
|
389
|
-
): FileWatcher {
|
|
390
|
-
return watchFiltered(paths, (event) => eventTypes.includes(event.type), callback, options);
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
/**
|
|
394
|
-
* Watch only for file changes (add, change, unlink)
|
|
395
|
-
*/
|
|
396
|
-
export function watchFiles(
|
|
397
|
-
paths: string | string[],
|
|
398
|
-
callback: WatchCallback,
|
|
399
|
-
options?: WatchOptions
|
|
400
|
-
): FileWatcher {
|
|
401
|
-
return watchEvents(paths, ['add', 'change', 'unlink'], callback, options);
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* Watch only for directory changes
|
|
406
|
-
*/
|
|
407
|
-
export function watchDirs(
|
|
408
|
-
paths: string | string[],
|
|
409
|
-
callback: WatchCallback,
|
|
410
|
-
options?: WatchOptions
|
|
411
|
-
): FileWatcher {
|
|
412
|
-
return watchEvents(paths, ['addDir', 'unlinkDir'], callback, options);
|
|
413
|
-
}
|