edhindex 1.0.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.
@@ -0,0 +1,77 @@
1
+ import { join, relative } from 'node:path';
2
+ import { logger } from '../logging.js';
3
+ import { emitProgress } from '../progress.js';
4
+
5
+ type ChangeHandler = (filePath: string) => Promise<void>;
6
+
7
+ export class FileWatcher {
8
+ private watcher: any = null;
9
+ private rootPath: string;
10
+ private onFileChange: ChangeHandler;
11
+ private timeoutId: any = null;
12
+ private pending = new Set<string>();
13
+ private debounceMs: number;
14
+
15
+ constructor(rootPath: string, onChange: ChangeHandler, debounceMs = 300) {
16
+ this.rootPath = rootPath;
17
+ this.onFileChange = onChange;
18
+ this.debounceMs = debounceMs;
19
+ }
20
+
21
+ async start(): Promise<void> {
22
+ const chokidar = await import('chokidar');
23
+ const { createIgnoreRules } = await import('../indexer/ignore.js');
24
+ const ignore = createIgnoreRules(this.rootPath);
25
+
26
+ this.watcher = chokidar.watch(this.rootPath, {
27
+ ignored: (path: string) => {
28
+ const rel = relative(this.rootPath, path).replace(/\\/g, '/');
29
+ return ignore.isIgnored(rel);
30
+ },
31
+ persistent: true,
32
+ ignoreInitial: true,
33
+ depth: 99,
34
+ });
35
+
36
+ this.watcher.on('change', (path: string) => this.queueChange(path));
37
+ this.watcher.on('add', (path: string) => this.queueChange(path));
38
+ this.watcher.on('unlink', (path: string) => this.queueChange(path));
39
+
40
+ logger.info('File watcher started');
41
+ }
42
+
43
+ private queueChange(filePath: string) {
44
+ const rel = relative(this.rootPath, filePath).replace(/\\/g, '/');
45
+ this.pending.add(rel);
46
+
47
+ if (this.timeoutId) {
48
+ clearTimeout(this.timeoutId);
49
+ }
50
+
51
+ this.timeoutId = setTimeout(async () => {
52
+ const batch = Array.from(this.pending);
53
+ this.pending.clear();
54
+ this.timeoutId = null;
55
+
56
+ for (const file of batch) {
57
+ try {
58
+ logger.debug(`File changed: ${file}`);
59
+ await this.onFileChange(file);
60
+ } catch (e) {
61
+ logger.debug(`Failed to handle file change ${file}:`, e);
62
+ }
63
+ }
64
+ }, this.debounceMs);
65
+ }
66
+
67
+ async stop(): Promise<void> {
68
+ if (this.timeoutId) {
69
+ clearTimeout(this.timeoutId);
70
+ this.timeoutId = null;
71
+ }
72
+ if (this.watcher) {
73
+ await this.watcher.close();
74
+ this.watcher = null;
75
+ }
76
+ }
77
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ES2022",
5
+ "moduleResolution": "bundler",
6
+ "lib": ["ES2022"],
7
+ "outDir": "./dist",
8
+ "rootDir": "./src",
9
+ "strict": true,
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "resolveJsonModule": true,
14
+ "declaration": true,
15
+ "declarationMap": true,
16
+ "sourceMap": true,
17
+ "isolatedModules": true
18
+ },
19
+ "include": ["src/**/*"],
20
+ "exclude": ["node_modules", "dist"]
21
+ }