@lvce-editor/file-watcher-process 4.3.0 → 4.4.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 +71 -25
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -15,7 +15,7 @@ class AssertionError extends Error {
15
15
  const Object$1 = 1;
16
16
  const Number = 2;
17
17
  const Array$1 = 3;
18
- const String = 4;
18
+ const String$1 = 4;
19
19
  const Boolean = 5;
20
20
  const Function = 6;
21
21
  const Null = 7;
@@ -27,7 +27,7 @@ const getType = value => {
27
27
  case 'function':
28
28
  return Function;
29
29
  case 'string':
30
- return String;
30
+ return String$1;
31
31
  case 'object':
32
32
  if (value === null) {
33
33
  return Null;
@@ -50,7 +50,7 @@ const number = value => {
50
50
  };
51
51
  const string = value => {
52
52
  const type = getType(value);
53
- if (type !== String) {
53
+ if (type !== String$1) {
54
54
  throw new AssertionError('expected value to be of type string');
55
55
  }
56
56
  };
@@ -1234,6 +1234,41 @@ const waitForWatcherToBeReady = async watcher => {
1234
1234
  await promise;
1235
1235
  };
1236
1236
 
1237
+ const success = {
1238
+ ok: true
1239
+ };
1240
+ const getErrorCode = error => {
1241
+ if (error && typeof error === 'object' && 'code' in error && typeof error.code === 'string') {
1242
+ return error.code;
1243
+ }
1244
+ return undefined;
1245
+ };
1246
+ const fromError = error => {
1247
+ if (error instanceof Error) {
1248
+ const code = getErrorCode(error);
1249
+ return {
1250
+ error: {
1251
+ ...(code && {
1252
+ code
1253
+ }),
1254
+ message: error.message,
1255
+ name: error.name,
1256
+ ...(error.stack && {
1257
+ stack: error.stack
1258
+ })
1259
+ },
1260
+ ok: false
1261
+ };
1262
+ }
1263
+ return {
1264
+ error: {
1265
+ message: String(error),
1266
+ name: 'Error'
1267
+ },
1268
+ ok: false
1269
+ };
1270
+ };
1271
+
1237
1272
  const callBackInternal = async (eventName, path, stats) => {
1238
1273
  const event = normalizeEvent(eventName, path);
1239
1274
  await invoke('FileWatcher.handleChange', event);
@@ -1245,13 +1280,22 @@ const errorCallback$1 = error => {
1245
1280
  console.error(`[file-watcher-process] ${error}`);
1246
1281
  };
1247
1282
  const watchFolder = async uri => {
1248
- const path = fileURLToPath(uri);
1249
- const watcher = new FSWatcher();
1250
- watcher.on('all', callback);
1251
- watcher.on('error', errorCallback$1);
1252
- const readyPromise = waitForWatcherToBeReady(watcher);
1253
- watcher.add(path);
1254
- await readyPromise;
1283
+ let watcher;
1284
+ try {
1285
+ const path = fileURLToPath(uri);
1286
+ watcher = new FSWatcher();
1287
+ watcher.on('all', callback);
1288
+ watcher.on('error', errorCallback$1);
1289
+ const readyPromise = waitForWatcherToBeReady(watcher);
1290
+ watcher.add(path);
1291
+ await readyPromise;
1292
+ return success;
1293
+ } catch (error) {
1294
+ if (watcher) {
1295
+ await Promise.allSettled([watcher.close()]);
1296
+ }
1297
+ return fromError(error);
1298
+ }
1255
1299
  };
1256
1300
 
1257
1301
  const normalizeEvent2 = (id, eventName, path) => {
@@ -1283,21 +1327,22 @@ const watchFolders = async ({
1283
1327
  const callback = (eventName, path, stats) => {
1284
1328
  void callBackInternal(eventName, path);
1285
1329
  };
1286
- const watcherEntries = roots.map(root => {
1287
- const path = fileURLToPath(root);
1288
- const watcher = new FSWatcher({
1289
- ignoreInitial: true,
1290
- ignorePermissionErrors: true
1291
- });
1292
- watcher.on('error', errorCallback);
1293
- const readyPromise = waitForWatcherToBeReady(watcher);
1294
- watcher.add(path);
1295
- return {
1296
- readyPromise,
1297
- watcher
1298
- };
1299
- });
1330
+ const watcherEntries = [];
1300
1331
  try {
1332
+ for (const root of roots) {
1333
+ const path = fileURLToPath(root);
1334
+ const watcher = new FSWatcher({
1335
+ ignoreInitial: true,
1336
+ ignorePermissionErrors: true
1337
+ });
1338
+ watcher.on('error', errorCallback);
1339
+ const readyPromise = waitForWatcherToBeReady(watcher);
1340
+ watcherEntries.push({
1341
+ readyPromise,
1342
+ watcher
1343
+ });
1344
+ watcher.add(path);
1345
+ }
1301
1346
  await Promise.all(watcherEntries.map(({
1302
1347
  readyPromise
1303
1348
  }) => readyPromise));
@@ -1305,13 +1350,14 @@ const watchFolders = async ({
1305
1350
  await Promise.allSettled(watcherEntries.map(({
1306
1351
  watcher
1307
1352
  }) => watcher.close()));
1308
- throw error;
1353
+ return fromError(error);
1309
1354
  }
1310
1355
  for (const {
1311
1356
  watcher
1312
1357
  } of watcherEntries) {
1313
1358
  watcher.on('all', callback);
1314
1359
  }
1360
+ return success;
1315
1361
  };
1316
1362
 
1317
1363
  const commandMap = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/file-watcher-process",
3
- "version": "4.3.0",
3
+ "version": "4.4.0",
4
4
  "description": "File Watcher Process",
5
5
  "keywords": [
6
6
  "Lvce Editor",