@lvce-editor/file-watcher-process 4.14.0 → 4.15.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 +67 -41
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1255,7 +1255,7 @@ const normalizeEvent = (eventName, path) => {
|
|
|
1255
1255
|
};
|
|
1256
1256
|
};
|
|
1257
1257
|
|
|
1258
|
-
const waitForWatcherToBeReady = async watcher => {
|
|
1258
|
+
const waitForWatcherToBeReady = async (watcher, signal) => {
|
|
1259
1259
|
const {
|
|
1260
1260
|
promise,
|
|
1261
1261
|
reject,
|
|
@@ -1264,6 +1264,7 @@ const waitForWatcherToBeReady = async watcher => {
|
|
|
1264
1264
|
const cleanup = () => {
|
|
1265
1265
|
watcher.off('ready', handleReady);
|
|
1266
1266
|
watcher.off('error', handleError);
|
|
1267
|
+
signal?.removeEventListener('abort', handleAbort);
|
|
1267
1268
|
};
|
|
1268
1269
|
const handleReady = () => {
|
|
1269
1270
|
cleanup();
|
|
@@ -1273,6 +1274,13 @@ const waitForWatcherToBeReady = async watcher => {
|
|
|
1273
1274
|
cleanup();
|
|
1274
1275
|
reject(error);
|
|
1275
1276
|
};
|
|
1277
|
+
const handleAbort = () => {
|
|
1278
|
+
handleError(signal?.reason);
|
|
1279
|
+
};
|
|
1280
|
+
signal?.throwIfAborted();
|
|
1281
|
+
signal?.addEventListener('abort', handleAbort, {
|
|
1282
|
+
once: true
|
|
1283
|
+
});
|
|
1276
1284
|
watcher.on('ready', handleReady);
|
|
1277
1285
|
watcher.on('error', handleError);
|
|
1278
1286
|
await promise;
|
|
@@ -1326,7 +1334,7 @@ const callBackInternal = async (eventName, path, stats) => {
|
|
|
1326
1334
|
const callback = (eventName, path, stats) => {
|
|
1327
1335
|
void callBackInternal(eventName, path);
|
|
1328
1336
|
};
|
|
1329
|
-
const errorCallback
|
|
1337
|
+
const errorCallback = error => {
|
|
1330
1338
|
console.error(`[file-watcher-process] ${error}`);
|
|
1331
1339
|
};
|
|
1332
1340
|
const watchFolder = async uri => {
|
|
@@ -1335,7 +1343,7 @@ const watchFolder = async uri => {
|
|
|
1335
1343
|
const path = fileURLToPath(uri);
|
|
1336
1344
|
watcher = new FSWatcher();
|
|
1337
1345
|
watcher.on('all', callback);
|
|
1338
|
-
watcher.on('error', errorCallback
|
|
1346
|
+
watcher.on('error', errorCallback);
|
|
1339
1347
|
const readyPromise = waitForWatcherToBeReady(watcher);
|
|
1340
1348
|
watcher.add(path);
|
|
1341
1349
|
await readyPromise;
|
|
@@ -1391,9 +1399,6 @@ const normalizeEvent2 = (id, eventName, path) => {
|
|
|
1391
1399
|
};
|
|
1392
1400
|
|
|
1393
1401
|
const createIgnore = ignore;
|
|
1394
|
-
const errorCallback = error => {
|
|
1395
|
-
console.error(`[file-watcher-process] ${error}`);
|
|
1396
|
-
};
|
|
1397
1402
|
const loadGitIgnore = async (root, enabled) => {
|
|
1398
1403
|
try {
|
|
1399
1404
|
const content = await readFile(`${root}/.gitignore`, 'utf8');
|
|
@@ -1424,36 +1429,72 @@ const createIgnored = async (root, exclude, useGitIgnore) => {
|
|
|
1424
1429
|
return gitIgnore.ignores(candidate);
|
|
1425
1430
|
};
|
|
1426
1431
|
};
|
|
1432
|
+
const send = event => {
|
|
1433
|
+
void invoke('FileWatcher.handleChange', event).catch(error => {
|
|
1434
|
+
console.error(`[file-watcher-process] ${error}`);
|
|
1435
|
+
});
|
|
1436
|
+
};
|
|
1427
1437
|
const watchFolders = async ({
|
|
1438
|
+
depth,
|
|
1428
1439
|
exclude,
|
|
1429
1440
|
id,
|
|
1430
1441
|
roots,
|
|
1431
1442
|
useGitIgnore = false
|
|
1432
1443
|
}) => {
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1444
|
+
if (has(id)) {
|
|
1445
|
+
return fromError(new Error(`watcher ${id} is already registered`));
|
|
1446
|
+
}
|
|
1447
|
+
const controller = new AbortController();
|
|
1448
|
+
const watcherEntries = [];
|
|
1449
|
+
let ready = false;
|
|
1450
|
+
let closing;
|
|
1451
|
+
const callback = (eventName, path) => {
|
|
1452
|
+
if (!controller.signal.aborted) {
|
|
1453
|
+
send(normalizeEvent2(id, eventName, path));
|
|
1454
|
+
}
|
|
1441
1455
|
};
|
|
1442
|
-
const
|
|
1443
|
-
|
|
1456
|
+
const errorCallback = error => {
|
|
1457
|
+
console.error(`[file-watcher-process] ${error}`);
|
|
1458
|
+
if (controller.signal.aborted) return;
|
|
1459
|
+
if (ready) {
|
|
1460
|
+
send({
|
|
1461
|
+
...fromError(error),
|
|
1462
|
+
eventName: 'error',
|
|
1463
|
+
id,
|
|
1464
|
+
uri: ''
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
controller.abort(error);
|
|
1444
1468
|
};
|
|
1445
|
-
|
|
1469
|
+
controller.signal.addEventListener('abort', () => {
|
|
1470
|
+
remove(id);
|
|
1471
|
+
closing = Promise.allSettled(watcherEntries.map(({
|
|
1472
|
+
watcher
|
|
1473
|
+
}) => watcher.close()));
|
|
1474
|
+
}, {
|
|
1475
|
+
once: true
|
|
1476
|
+
});
|
|
1477
|
+
// Register before asynchronous setup so disposal also cancels a pending watch.
|
|
1478
|
+
add(id, controller);
|
|
1446
1479
|
try {
|
|
1447
1480
|
for (const root of roots) {
|
|
1481
|
+
controller.signal.throwIfAborted();
|
|
1448
1482
|
const path = fileURLToPath(root);
|
|
1449
1483
|
const ignored = useGitIgnore ? await createIgnored(path, exclude, true) : createExcludedNamesFilter(exclude);
|
|
1484
|
+
controller.signal.throwIfAborted();
|
|
1450
1485
|
const watcher = new FSWatcher({
|
|
1486
|
+
...(depth !== undefined && {
|
|
1487
|
+
depth
|
|
1488
|
+
}),
|
|
1451
1489
|
ignored,
|
|
1452
1490
|
ignoreInitial: true,
|
|
1453
|
-
ignorePermissionErrors:
|
|
1491
|
+
ignorePermissionErrors: false
|
|
1454
1492
|
});
|
|
1455
1493
|
watcher.on('error', errorCallback);
|
|
1456
|
-
|
|
1494
|
+
watcher.on('all', callback);
|
|
1495
|
+
const readyPromise = waitForWatcherToBeReady(watcher, controller.signal);
|
|
1496
|
+
// Later roots can fail before Promise.all is reached.
|
|
1497
|
+
void readyPromise.catch(() => {});
|
|
1457
1498
|
watcherEntries.push({
|
|
1458
1499
|
readyPromise,
|
|
1459
1500
|
watcher
|
|
@@ -1463,31 +1504,16 @@ const watchFolders = async ({
|
|
|
1463
1504
|
await Promise.all(watcherEntries.map(({
|
|
1464
1505
|
readyPromise
|
|
1465
1506
|
}) => readyPromise));
|
|
1507
|
+
controller.signal.throwIfAborted();
|
|
1508
|
+
ready = true;
|
|
1509
|
+
const inotifyWatchCount = await getInotifyWatchCount();
|
|
1510
|
+
controller.signal.throwIfAborted();
|
|
1511
|
+
return inotifyWatchCount === undefined ? success : successWithInotifyWatchCount(inotifyWatchCount);
|
|
1466
1512
|
} catch (error) {
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
}) => watcher.close()));
|
|
1513
|
+
controller.abort(error);
|
|
1514
|
+
await closing;
|
|
1470
1515
|
return fromError(error);
|
|
1471
1516
|
}
|
|
1472
|
-
for (const {
|
|
1473
|
-
watcher
|
|
1474
|
-
} of watcherEntries) {
|
|
1475
|
-
watcher.on('all', callback);
|
|
1476
|
-
}
|
|
1477
|
-
const controller = new AbortController();
|
|
1478
|
-
controller.signal.addEventListener('abort', () => {
|
|
1479
|
-
void Promise.allSettled(watcherEntries.map(({
|
|
1480
|
-
watcher
|
|
1481
|
-
}) => watcher.close()));
|
|
1482
|
-
}, {
|
|
1483
|
-
once: true
|
|
1484
|
-
});
|
|
1485
|
-
add(id, controller);
|
|
1486
|
-
const inotifyWatchCount = await getInotifyWatchCount();
|
|
1487
|
-
if (inotifyWatchCount === undefined) {
|
|
1488
|
-
return success;
|
|
1489
|
-
}
|
|
1490
|
-
return successWithInotifyWatchCount(inotifyWatchCount);
|
|
1491
1517
|
};
|
|
1492
1518
|
|
|
1493
1519
|
const commandMap = {
|