@lvce-editor/file-watcher-process 3.4.0 → 3.6.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.
Files changed (2) hide show
  1. package/dist/index.js +92 -3
  2. package/package.json +2 -1
package/dist/index.js CHANGED
@@ -1,11 +1,84 @@
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}`);
7
7
  };
8
8
 
9
+ class AssertionError extends Error {
10
+ constructor(message) {
11
+ super(message);
12
+ this.name = 'AssertionError';
13
+ }
14
+ }
15
+ const Object$1 = 1;
16
+ const Number = 2;
17
+ const Array$1 = 3;
18
+ const String = 4;
19
+ const Boolean = 5;
20
+ const Function = 6;
21
+ const Null = 7;
22
+ const Unknown = 8;
23
+ const getType = value => {
24
+ switch (typeof value) {
25
+ case 'number':
26
+ return Number;
27
+ case 'function':
28
+ return Function;
29
+ case 'string':
30
+ return String;
31
+ case 'object':
32
+ if (value === null) {
33
+ return Null;
34
+ }
35
+ if (Array.isArray(value)) {
36
+ return Array$1;
37
+ }
38
+ return Object$1;
39
+ case 'boolean':
40
+ return Boolean;
41
+ default:
42
+ return Unknown;
43
+ }
44
+ };
45
+ const number = value => {
46
+ const type = getType(value);
47
+ if (type !== Number) {
48
+ throw new AssertionError('expected value to be of type number');
49
+ }
50
+ };
51
+ const string = value => {
52
+ const type = getType(value);
53
+ if (type !== String) {
54
+ throw new AssertionError('expected value to be of type string');
55
+ }
56
+ };
57
+
58
+ const watchers = Object.create(null);
59
+ const add = (id, controller) => {
60
+ watchers[id] = controller;
61
+ };
62
+ const get$2 = id => {
63
+ return watchers[id];
64
+ };
65
+ const has = id => {
66
+ return id in watchers;
67
+ };
68
+ const remove$1 = id => {
69
+ delete watchers[id];
70
+ };
71
+
72
+ const disposeWatcher = id => {
73
+ number(id);
74
+ if (!has(id)) {
75
+ return;
76
+ }
77
+ const controller = get$2(id);
78
+ controller.abort();
79
+ remove$1(id);
80
+ };
81
+
9
82
  const normalizeLine = line => {
10
83
  if (line.startsWith('Error: ')) {
11
84
  return line.slice('Error: '.length);
@@ -1117,6 +1190,20 @@ const watchFile = async path => {
1117
1190
  };
1118
1191
  await watchInternal(path, {}, callback);
1119
1192
  };
1193
+ const watchFile2 = async (id, uri) => {
1194
+ number(id);
1195
+ string(uri);
1196
+ const callback = async event => {
1197
+ await invoke('FileWatcher.handleChange', {
1198
+ id,
1199
+ ...event
1200
+ });
1201
+ };
1202
+ const path = fileURLToPath(uri);
1203
+ const controller = new AbortController();
1204
+ add(id, controller);
1205
+ await watchInternal(path, {}, callback);
1206
+ };
1120
1207
 
1121
1208
  const normalizeEvent = (eventName, path) => {
1122
1209
  const uri = pathToFileURL(path).toString();
@@ -1194,10 +1281,12 @@ const watchFolders = async ({
1194
1281
  };
1195
1282
 
1196
1283
  const commandMap = {
1197
- 'HandleElectronMessagePort.handleElectronMessagePort': handleElectronMessagePort,
1284
+ 'FileWatcher.dispose': disposeWatcher,
1198
1285
  'FileWatcher.watchFile': watchFile,
1286
+ 'FileWatcher.watchFile2': watchFile2,
1199
1287
  'FileWatcher.watchFolder': watchFolder,
1200
- 'FileWatcher.watchFolders': watchFolders
1288
+ 'FileWatcher.watchFolders': watchFolders,
1289
+ 'HandleElectronMessagePort.handleElectronMessagePort': handleElectronMessagePort
1201
1290
  };
1202
1291
 
1203
1292
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/file-watcher-process",
3
- "version": "3.4.0",
3
+ "version": "3.6.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": {