muaddib-scanner 2.4.3 → 2.4.5

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/src/watch.js CHANGED
@@ -1,56 +1,56 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const { run } = require('./index.js');
4
-
5
- function watch(targetPath) {
6
- let debounceTimer = null;
7
- const watchers = [];
8
-
9
- console.log(`[MUADDIB] Surveillance de ${targetPath}\n`);
10
- console.log('[INFO] Ctrl+C pour arreter\n');
11
-
12
- // Scan initial
13
- run(targetPath, { json: false }).catch(err => console.error('[ERROR]', err.message));
14
-
15
- // Surveille les changements
16
- const watchPaths = [
17
- path.join(targetPath, 'package.json'),
18
- path.join(targetPath, 'package-lock.json'),
19
- path.join(targetPath, 'node_modules')
20
- ];
21
-
22
- for (const watchPath of watchPaths) {
23
- if (fs.existsSync(watchPath)) {
24
- // Note: recursive option only works on macOS and Windows.
25
- // On Linux, only top-level changes in watchPath are detected.
26
- if (process.platform === 'linux' && watchPath.includes('node_modules')) {
27
- console.log(`[WARN] recursive watch not supported on Linux for ${watchPath}`);
28
- }
29
- const watcher = fs.watch(watchPath, { recursive: true }, (eventType, filename) => {
30
- if (debounceTimer) clearTimeout(debounceTimer);
31
-
32
- debounceTimer = setTimeout(() => {
33
- console.log(`\n[CHANGE] ${filename || 'unknown file'} modifie`);
34
- console.log('[MUADDIB] Re-scan...\n');
35
- run(targetPath, { json: false }).catch(err => console.error('[ERROR]', err.message));
36
- }, 1000);
37
- });
38
- watcher.on('error', (err) => {
39
- console.error(`[WARN] Watcher error on ${watchPath}: ${err.message}`);
40
- });
41
- watchers.push(watcher);
42
- console.log(`[WATCH] ${watchPath}`);
43
- }
44
- }
45
-
46
- // Cleanup on SIGINT
47
- process.once('SIGINT', () => {
48
- console.log('\n[MUADDIB] Arret surveillance...');
49
- for (const w of watchers) {
50
- try { w.close(); } catch { /* ignore */ }
51
- }
52
- process.exit(0);
53
- });
54
- }
55
-
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { run } = require('./index.js');
4
+
5
+ function watch(targetPath) {
6
+ let debounceTimer = null;
7
+ const watchers = [];
8
+
9
+ console.log(`[MUADDIB] Surveillance de ${targetPath}\n`);
10
+ console.log('[INFO] Ctrl+C pour arreter\n');
11
+
12
+ // Scan initial
13
+ run(targetPath, { json: false }).catch(err => console.error('[ERROR]', err.message));
14
+
15
+ // Surveille les changements
16
+ const watchPaths = [
17
+ path.join(targetPath, 'package.json'),
18
+ path.join(targetPath, 'package-lock.json'),
19
+ path.join(targetPath, 'node_modules')
20
+ ];
21
+
22
+ for (const watchPath of watchPaths) {
23
+ if (fs.existsSync(watchPath)) {
24
+ // Note: recursive option only works on macOS and Windows.
25
+ // On Linux, only top-level changes in watchPath are detected.
26
+ if (process.platform === 'linux' && watchPath.includes('node_modules')) {
27
+ console.log(`[WARN] recursive watch not supported on Linux for ${watchPath}`);
28
+ }
29
+ const watcher = fs.watch(watchPath, { recursive: true }, (eventType, filename) => {
30
+ if (debounceTimer) clearTimeout(debounceTimer);
31
+
32
+ debounceTimer = setTimeout(() => {
33
+ console.log(`\n[CHANGE] ${filename || 'unknown file'} modifie`);
34
+ console.log('[MUADDIB] Re-scan...\n');
35
+ run(targetPath, { json: false }).catch(err => console.error('[ERROR]', err.message));
36
+ }, 1000);
37
+ });
38
+ watcher.on('error', (err) => {
39
+ console.error(`[WARN] Watcher error on ${watchPath}: ${err.message}`);
40
+ });
41
+ watchers.push(watcher);
42
+ console.log(`[WATCH] ${watchPath}`);
43
+ }
44
+ }
45
+
46
+ // Cleanup on SIGINT
47
+ process.once('SIGINT', () => {
48
+ console.log('\n[MUADDIB] Arret surveillance...');
49
+ for (const w of watchers) {
50
+ try { w.close(); } catch { /* ignore */ }
51
+ }
52
+ process.exit(0);
53
+ });
54
+ }
55
+
56
56
  module.exports = { watch };