From e6faacd52fc8ba390165a5307c34951ad1d51507 Mon Sep 17 00:00:00 2001 From: Benjamin Toby Date: Wed, 16 Oct 2024 10:02:16 +0100 Subject: [PATCH] Add timeout to watcher --- lib/watch/folders.js | 12 ++++++++++-- package.json | 2 +- tsconfig.json | 27 --------------------------- 3 files changed, 11 insertions(+), 30 deletions(-) delete mode 100644 tsconfig.json diff --git a/lib/watch/folders.js b/lib/watch/folders.js index 78e105e..61867f7 100644 --- a/lib/watch/folders.js +++ b/lib/watch/folders.js @@ -5,6 +5,10 @@ const path = require("path"); const { execSync } = require("child_process"); const delay = require("../../utils/delay"); +/** @type {any} */ +let timeout; +const UPDATE_TIMEOUT = 5000; + /** * * @param {SyncFoldersFnParams} param0 @@ -82,8 +86,12 @@ async function watchFolders({ folders, options }) { await delay(); fs.watch(dirPath, { recursive: true }, (evt, fileName) => { - sync({ dirPath, dirs, options }); - process.exit(1); + clearTimeout(timeout); + + timeout = setTimeout(() => { + sync({ dirPath, dirs, options }); + process.exit(1); + }, UPDATE_TIMEOUT); }); } } diff --git a/package.json b/package.json index 782055c..8d74a9a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "turbosync", - "version": "1.2.1", + "version": "1.3.0", "module": "index.js", "scripts": { "start": "node index.ts", diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index ec3f79f..0000000 --- a/tsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - "target": "ES2015", - "module": "ESNext", - "moduleDetection": "force", - "jsx": "react-jsx", - "allowJs": true, - - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "verbatimModuleSyntax": true, - "noEmit": true, - - "strict": true, - "skipLibCheck": true, - "noFallthroughCasesInSwitch": true, - "emitDeclarationOnly": true, - - "noUnusedLocals": false, - "noUnusedParameters": false, - "declaration": true, - "outDir": "dump/dist", - "noPropertyAccessFromIndexSignature": false - }, - "include": ["index.ts", "index.d.ts", "**/*.ts"], - "exclude": ["dump"] -}