@lvce-editor/file-watcher-process 4.4.0 → 4.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.
Files changed (2) hide show
  1. package/dist/index.js +45 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { fileURLToPath, pathToFileURL } from 'node:url';
2
2
  import * as fs from 'node:fs/promises';
3
3
  import { FSWatcher } from 'chokidar';
4
+ import { join } from 'node:path';
4
5
 
5
6
  const handleUncaughtExceptionMonitor = error => {
6
7
  console.error(`[file-watcher-process] Uncaught Exception: ${error}`);
@@ -1237,6 +1238,12 @@ const waitForWatcherToBeReady = async watcher => {
1237
1238
  const success = {
1238
1239
  ok: true
1239
1240
  };
1241
+ const successWithInotifyWatchCount = inotifyWatchCount => {
1242
+ return {
1243
+ inotifyWatchCount,
1244
+ ok: true
1245
+ };
1246
+ };
1240
1247
  const getErrorCode = error => {
1241
1248
  if (error && typeof error === 'object' && 'code' in error && typeof error.code === 'string') {
1242
1249
  return error.code;
@@ -1298,6 +1305,39 @@ const watchFolder = async uri => {
1298
1305
  }
1299
1306
  };
1300
1307
 
1308
+ // cspell:disable-next-line
1309
+ const fdInfoPath = '/proc/self/fdinfo';
1310
+ const countInotifyWatches = fdInfoContents => {
1311
+ let count = 0;
1312
+ for (const content of fdInfoContents) {
1313
+ for (const line of content.split('\n')) {
1314
+ if (line.startsWith('inotify ')) {
1315
+ count++;
1316
+ }
1317
+ }
1318
+ }
1319
+ return count;
1320
+ };
1321
+ const readFdInfo = async fileName => {
1322
+ try {
1323
+ return await fs.readFile(join(fdInfoPath, fileName), 'utf8');
1324
+ } catch {
1325
+ return '';
1326
+ }
1327
+ };
1328
+ const getInotifyWatchCount = async () => {
1329
+ if (process.platform !== 'linux') {
1330
+ return undefined;
1331
+ }
1332
+ try {
1333
+ const fileNames = await fs.readdir(fdInfoPath);
1334
+ const fdInfoContents = await Promise.all(fileNames.map(readFdInfo));
1335
+ return countInotifyWatches(fdInfoContents);
1336
+ } catch {
1337
+ return undefined;
1338
+ }
1339
+ };
1340
+
1301
1341
  const normalizeEvent2 = (id, eventName, path) => {
1302
1342
  const uri = pathToFileURL(path).toString();
1303
1343
  return {
@@ -1357,7 +1397,11 @@ const watchFolders = async ({
1357
1397
  } of watcherEntries) {
1358
1398
  watcher.on('all', callback);
1359
1399
  }
1360
- return success;
1400
+ const inotifyWatchCount = await getInotifyWatchCount();
1401
+ if (inotifyWatchCount === undefined) {
1402
+ return success;
1403
+ }
1404
+ return successWithInotifyWatchCount(inotifyWatchCount);
1361
1405
  };
1362
1406
 
1363
1407
  const commandMap = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/file-watcher-process",
3
- "version": "4.4.0",
3
+ "version": "4.5.0",
4
4
  "description": "File Watcher Process",
5
5
  "keywords": [
6
6
  "Lvce Editor",