@lvce-editor/file-watcher-process 3.5.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 +78 -51
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -6,6 +6,79 @@ 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);
@@ -62,55 +135,6 @@ class VError extends Error {
62
135
  }
63
136
  }
64
137
 
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
-
114
138
  const isMessagePort = value => {
115
139
  return value && value instanceof MessagePort;
116
140
  };
@@ -1176,6 +1200,8 @@ const watchFile2 = async (id, uri) => {
1176
1200
  });
1177
1201
  };
1178
1202
  const path = fileURLToPath(uri);
1203
+ const controller = new AbortController();
1204
+ add(id, controller);
1179
1205
  await watchInternal(path, {}, callback);
1180
1206
  };
1181
1207
 
@@ -1255,11 +1281,12 @@ const watchFolders = async ({
1255
1281
  };
1256
1282
 
1257
1283
  const commandMap = {
1258
- 'HandleElectronMessagePort.handleElectronMessagePort': handleElectronMessagePort,
1284
+ 'FileWatcher.dispose': disposeWatcher,
1259
1285
  'FileWatcher.watchFile': watchFile,
1260
1286
  'FileWatcher.watchFile2': watchFile2,
1261
1287
  'FileWatcher.watchFolder': watchFolder,
1262
- 'FileWatcher.watchFolders': watchFolders
1288
+ 'FileWatcher.watchFolders': watchFolders,
1289
+ 'HandleElectronMessagePort.handleElectronMessagePort': handleElectronMessagePort
1263
1290
  };
1264
1291
 
1265
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.5.0",
3
+ "version": "3.6.0",
4
4
  "description": "File Watcher Process",
5
5
  "keywords": [
6
6
  "Lvce Editor",