@lvce-editor/file-watcher-process 3.4.0 → 3.5.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/index.js +63 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
1
2
|
import * as fs from 'node:fs/promises';
|
|
2
3
|
import { watch } from 'chokidar';
|
|
3
|
-
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
4
4
|
|
|
5
5
|
const handleUncaughtExceptionMonitor = error => {
|
|
6
6
|
console.error(`[file-watcher-process] Uncaught Exception: ${error}`);
|
|
@@ -62,6 +62,55 @@ class VError extends Error {
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
class AssertionError extends Error {
|
|
66
|
+
constructor(message) {
|
|
67
|
+
super(message);
|
|
68
|
+
this.name = 'AssertionError';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const Object$1 = 1;
|
|
72
|
+
const Number = 2;
|
|
73
|
+
const Array$1 = 3;
|
|
74
|
+
const String = 4;
|
|
75
|
+
const Boolean = 5;
|
|
76
|
+
const Function = 6;
|
|
77
|
+
const Null = 7;
|
|
78
|
+
const Unknown = 8;
|
|
79
|
+
const getType = value => {
|
|
80
|
+
switch (typeof value) {
|
|
81
|
+
case 'number':
|
|
82
|
+
return Number;
|
|
83
|
+
case 'function':
|
|
84
|
+
return Function;
|
|
85
|
+
case 'string':
|
|
86
|
+
return String;
|
|
87
|
+
case 'object':
|
|
88
|
+
if (value === null) {
|
|
89
|
+
return Null;
|
|
90
|
+
}
|
|
91
|
+
if (Array.isArray(value)) {
|
|
92
|
+
return Array$1;
|
|
93
|
+
}
|
|
94
|
+
return Object$1;
|
|
95
|
+
case 'boolean':
|
|
96
|
+
return Boolean;
|
|
97
|
+
default:
|
|
98
|
+
return Unknown;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const number = value => {
|
|
102
|
+
const type = getType(value);
|
|
103
|
+
if (type !== Number) {
|
|
104
|
+
throw new AssertionError('expected value to be of type number');
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const string = value => {
|
|
108
|
+
const type = getType(value);
|
|
109
|
+
if (type !== String) {
|
|
110
|
+
throw new AssertionError('expected value to be of type string');
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
65
114
|
const isMessagePort = value => {
|
|
66
115
|
return value && value instanceof MessagePort;
|
|
67
116
|
};
|
|
@@ -1117,6 +1166,18 @@ const watchFile = async path => {
|
|
|
1117
1166
|
};
|
|
1118
1167
|
await watchInternal(path, {}, callback);
|
|
1119
1168
|
};
|
|
1169
|
+
const watchFile2 = async (id, uri) => {
|
|
1170
|
+
number(id);
|
|
1171
|
+
string(uri);
|
|
1172
|
+
const callback = async event => {
|
|
1173
|
+
await invoke('FileWatcher.handleChange', {
|
|
1174
|
+
id,
|
|
1175
|
+
...event
|
|
1176
|
+
});
|
|
1177
|
+
};
|
|
1178
|
+
const path = fileURLToPath(uri);
|
|
1179
|
+
await watchInternal(path, {}, callback);
|
|
1180
|
+
};
|
|
1120
1181
|
|
|
1121
1182
|
const normalizeEvent = (eventName, path) => {
|
|
1122
1183
|
const uri = pathToFileURL(path).toString();
|
|
@@ -1196,6 +1257,7 @@ const watchFolders = async ({
|
|
|
1196
1257
|
const commandMap = {
|
|
1197
1258
|
'HandleElectronMessagePort.handleElectronMessagePort': handleElectronMessagePort,
|
|
1198
1259
|
'FileWatcher.watchFile': watchFile,
|
|
1260
|
+
'FileWatcher.watchFile2': watchFile2,
|
|
1199
1261
|
'FileWatcher.watchFolder': watchFolder,
|
|
1200
1262
|
'FileWatcher.watchFolders': watchFolders
|
|
1201
1263
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/file-watcher-process",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "File Watcher Process",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Lvce Editor",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"file-watcher-process": "bin/fileWatcherProcess.js"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
+
"@lvce-editor/assert": "^1.4.0",
|
|
21
22
|
"chokidar": "^4.0.3"
|
|
22
23
|
},
|
|
23
24
|
"engines": {
|