@static-suite/static-suite-data-server 2.0.1 → 2.0.3
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/lib/utils/fs/fsWatchUtils.d.ts +2 -7
- package/dist/lib/utils/fs/fsWatchUtils.d.ts.map +1 -1
- package/dist/lib/utils/fs/fsWatchUtils.js +18 -28
- package/dist/lib/utils/misc/debounce.d.ts +2 -0
- package/dist/lib/utils/misc/debounce.d.ts.map +1 -0
- package/dist/lib/utils/misc/debounce.js +22 -0
- package/dist/lib/watcher/watcher.d.ts.map +1 -1
- package/dist/lib/watcher/watcher.js +2 -6
- package/package.json +4 -5
- package/src/lib/utils/fs/fsWatchUtils.ts +26 -28
- package/src/lib/utils/misc/debounce.ts +24 -0
- package/src/lib/watcher/watcher.ts +2 -6
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Watches for changes on a set of paths and attach listener to them
|
|
3
3
|
*
|
|
4
|
-
* @remarks
|
|
5
|
-
* It handles three different events: add, change and unlink
|
|
6
|
-
*
|
|
7
4
|
* @param paths - An array of paths to be watched
|
|
8
|
-
* @param
|
|
9
|
-
* and a listener function as value. That function will be executed once any of
|
|
10
|
-
* the event keys is dispatched.
|
|
5
|
+
* @param callback - A callback function to be executed when a file changes
|
|
11
6
|
*/
|
|
12
|
-
export declare const watch: (paths: string[],
|
|
7
|
+
export declare const watch: (paths: string[], callback: (filePath: string) => void) => void;
|
|
13
8
|
//# sourceMappingURL=fsWatchUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fsWatchUtils.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/fs/fsWatchUtils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fsWatchUtils.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/fs/fsWatchUtils.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,eAAO,MAAM,KAAK,GAChB,OAAO,MAAM,EAAE,EACf,UAAU,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,KACnC,IA2BF,CAAC"}
|
|
@@ -4,42 +4,32 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.watch = void 0;
|
|
7
|
-
const
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
8
|
const logger_1 = require("../logger");
|
|
9
|
+
const debounce_1 = require("../misc/debounce");
|
|
9
10
|
/**
|
|
10
11
|
* Watches for changes on a set of paths and attach listener to them
|
|
11
12
|
*
|
|
12
|
-
* @remarks
|
|
13
|
-
* It handles three different events: add, change and unlink
|
|
14
|
-
*
|
|
15
13
|
* @param paths - An array of paths to be watched
|
|
16
|
-
* @param
|
|
17
|
-
* and a listener function as value. That function will be executed once any of
|
|
18
|
-
* the event keys is dispatched.
|
|
14
|
+
* @param callback - A callback function to be executed when a file changes
|
|
19
15
|
*/
|
|
20
|
-
const watch = (paths,
|
|
16
|
+
const watch = (paths, callback) => {
|
|
21
17
|
if (paths.length > 0) {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
logger_1.logger.debug(`File ${filePath} changed`);
|
|
36
|
-
listeners.change(filePath);
|
|
37
|
-
})
|
|
38
|
-
.on('unlink', filePath => {
|
|
39
|
-
logger_1.logger.debug(`File ${filePath} removed`);
|
|
40
|
-
listeners.unlink(filePath);
|
|
41
|
-
});
|
|
18
|
+
const listener = (eventType, filename) => {
|
|
19
|
+
if (filename) {
|
|
20
|
+
logger_1.logger.debug(`File ${filename} ${eventType}`);
|
|
21
|
+
callback(filename);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
paths.forEach(path => {
|
|
25
|
+
node_fs_1.default.watch(path, {
|
|
26
|
+
ignore: /(^|[/\\])\../,
|
|
27
|
+
recursive: true,
|
|
28
|
+
},
|
|
29
|
+
// Ensure filenames are absolute
|
|
30
|
+
(0, debounce_1.debounce)((eventType, filename) => filename ? listener(eventType, `${path}/${filename}`) : null, 300));
|
|
42
31
|
});
|
|
32
|
+
logger_1.logger.debug(`Watcher listening for changes on ${paths.join(',')}`);
|
|
43
33
|
}
|
|
44
34
|
};
|
|
45
35
|
exports.watch = watch;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debounce.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/misc/debounce.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,OAAO,EAAE,EAC1C,UAAU,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,IAAI,EAC9B,OAAO,MAAM,MAIL,GAAG,MAAM,CAAC,SAOnB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// export const debounce = (func: any, wait = 100) => {
|
|
3
|
+
// let timeout: ;
|
|
4
|
+
// return (...args) => {
|
|
5
|
+
// clearTimeout(timeout);
|
|
6
|
+
// timeout = setTimeout(() => {
|
|
7
|
+
// func.apply(this, args);
|
|
8
|
+
// }, wait);
|
|
9
|
+
// };
|
|
10
|
+
// };
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.debounce = void 0;
|
|
13
|
+
const debounce = (callback, delay) => {
|
|
14
|
+
let timeoutTimer;
|
|
15
|
+
return (...args) => {
|
|
16
|
+
clearTimeout(timeoutTimer);
|
|
17
|
+
timeoutTimer = setTimeout(() => {
|
|
18
|
+
callback(...args);
|
|
19
|
+
}, delay);
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
exports.debounce = debounce;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../../../src/lib/watcher/watcher.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,WAAW,QAAO,
|
|
1
|
+
{"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../../../src/lib/watcher/watcher.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,WAAW,QAAO,IAqC9B,CAAC"}
|
|
@@ -35,7 +35,7 @@ const initWatcher = () => {
|
|
|
35
35
|
if (config_1.config.taskDir) {
|
|
36
36
|
paths.push(config_1.config.taskDir);
|
|
37
37
|
}
|
|
38
|
-
const
|
|
38
|
+
const callback = (filePath) => {
|
|
39
39
|
// Remove all modules inside the query directory.
|
|
40
40
|
if (config_1.config.queryDir && filePath.startsWith(config_1.config.queryDir)) {
|
|
41
41
|
query_1.queryManager.reset();
|
|
@@ -56,10 +56,6 @@ const initWatcher = () => {
|
|
|
56
56
|
task_1.taskManager.reset();
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
|
-
(0, fsWatchUtils_1.watch)(paths,
|
|
60
|
-
add: listener,
|
|
61
|
-
change: listener,
|
|
62
|
-
unlink: listener,
|
|
63
|
-
});
|
|
59
|
+
(0, fsWatchUtils_1.watch)(paths, callback);
|
|
64
60
|
};
|
|
65
61
|
exports.initWatcher = initWatcher;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@static-suite/static-suite-data-server",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "A flexible, fast and developer friendly Data Server for Static Suite",
|
|
5
5
|
"main": "./dist/lib/index.js",
|
|
6
6
|
"typings": "./dist/lib/index.d.ts",
|
|
@@ -12,9 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@creativebulma/bulma-tooltip": "^1.2.0",
|
|
15
|
-
"@microsoft/api-extractor": "^7.34.4",
|
|
16
15
|
"bulma": "^1.0.4",
|
|
17
|
-
"chokidar": "4.0.3",
|
|
18
16
|
"clear-module": "^4.1.2",
|
|
19
17
|
"clipboard": "^2.0.11",
|
|
20
18
|
"cors": "^2.8.5",
|
|
@@ -26,8 +24,6 @@
|
|
|
26
24
|
"mime-types": "^3.0.1",
|
|
27
25
|
"pug": "^3.0.3",
|
|
28
26
|
"simple-datatables": "^10.0.0",
|
|
29
|
-
"tsc-watch": "^7.1.1",
|
|
30
|
-
"typescript": "^6.0.3",
|
|
31
27
|
"winston": "^3.8.2",
|
|
32
28
|
"yargs": "^18.0.0"
|
|
33
29
|
},
|
|
@@ -49,6 +45,7 @@
|
|
|
49
45
|
},
|
|
50
46
|
"devDependencies": {
|
|
51
47
|
"@eslint/js": "^10.0.1",
|
|
48
|
+
"@microsoft/api-extractor": "^7.34.4",
|
|
52
49
|
"@types/cors": "^2.8.13",
|
|
53
50
|
"@types/express": "^5.0.3",
|
|
54
51
|
"@types/jest": "^30.0.0",
|
|
@@ -69,7 +66,9 @@
|
|
|
69
66
|
"jest": "^30.1.3",
|
|
70
67
|
"prettier": "^3.6.2",
|
|
71
68
|
"ts-jest": "^29.4.1",
|
|
69
|
+
"tsc-watch": "^7.1.1",
|
|
72
70
|
"typedoc": "^0.28.12",
|
|
71
|
+
"typescript": "^6",
|
|
73
72
|
"typescript-eslint": "^8.43.0"
|
|
74
73
|
},
|
|
75
74
|
"jest": {
|
|
@@ -1,43 +1,41 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from 'node:fs';
|
|
2
2
|
import { logger } from '../logger';
|
|
3
|
+
import { debounce } from '../misc/debounce';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Watches for changes on a set of paths and attach listener to them
|
|
6
7
|
*
|
|
7
|
-
* @remarks
|
|
8
|
-
* It handles three different events: add, change and unlink
|
|
9
|
-
*
|
|
10
8
|
* @param paths - An array of paths to be watched
|
|
11
|
-
* @param
|
|
12
|
-
* and a listener function as value. That function will be executed once any of
|
|
13
|
-
* the event keys is dispatched.
|
|
9
|
+
* @param callback - A callback function to be executed when a file changes
|
|
14
10
|
*/
|
|
15
11
|
export const watch = (
|
|
16
12
|
paths: string[],
|
|
17
|
-
|
|
13
|
+
callback: (filePath: string) => void,
|
|
18
14
|
): void => {
|
|
19
15
|
if (paths.length > 0) {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
const listener = (eventType: string, filename: string): void => {
|
|
17
|
+
if (filename) {
|
|
18
|
+
logger.debug(`File ${filename} ${eventType}`);
|
|
19
|
+
callback(filename);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
listeners.unlink(filePath);
|
|
40
|
-
});
|
|
23
|
+
paths.forEach(path => {
|
|
24
|
+
fs.watch(
|
|
25
|
+
path,
|
|
26
|
+
{
|
|
27
|
+
ignore: /(^|[/\\])\../,
|
|
28
|
+
recursive: true,
|
|
29
|
+
},
|
|
30
|
+
// Ensure filenames are absolute
|
|
31
|
+
debounce(
|
|
32
|
+
(eventType, filename) =>
|
|
33
|
+
filename ? listener(eventType, `${path}/${filename}`) : null,
|
|
34
|
+
300,
|
|
35
|
+
),
|
|
36
|
+
);
|
|
41
37
|
});
|
|
38
|
+
|
|
39
|
+
logger.debug(`Watcher listening for changes on ${paths.join(',')}`);
|
|
42
40
|
}
|
|
43
41
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// export const debounce = (func: any, wait = 100) => {
|
|
2
|
+
// let timeout: ;
|
|
3
|
+
// return (...args) => {
|
|
4
|
+
// clearTimeout(timeout);
|
|
5
|
+
// timeout = setTimeout(() => {
|
|
6
|
+
// func.apply(this, args);
|
|
7
|
+
// }, wait);
|
|
8
|
+
// };
|
|
9
|
+
// };
|
|
10
|
+
|
|
11
|
+
export const debounce = <T extends unknown[]>(
|
|
12
|
+
callback: (...args: T) => void,
|
|
13
|
+
delay: number,
|
|
14
|
+
) => {
|
|
15
|
+
let timeoutTimer: ReturnType<typeof setTimeout>;
|
|
16
|
+
|
|
17
|
+
return (...args: T) => {
|
|
18
|
+
clearTimeout(timeoutTimer);
|
|
19
|
+
|
|
20
|
+
timeoutTimer = setTimeout(() => {
|
|
21
|
+
callback(...args);
|
|
22
|
+
}, delay);
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -34,7 +34,7 @@ export const initWatcher = (): void => {
|
|
|
34
34
|
paths.push(config.taskDir);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
const
|
|
37
|
+
const callback = (filePath: string) => {
|
|
38
38
|
// Remove all modules inside the query directory.
|
|
39
39
|
if (config.queryDir && filePath.startsWith(config.queryDir)) {
|
|
40
40
|
queryManager.reset();
|
|
@@ -58,9 +58,5 @@ export const initWatcher = (): void => {
|
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
watch(paths,
|
|
62
|
-
add: listener,
|
|
63
|
-
change: listener,
|
|
64
|
-
unlink: listener,
|
|
65
|
-
});
|
|
61
|
+
watch(paths, callback);
|
|
66
62
|
};
|