diff --git a/lib/compiler/assets-manager.ts b/lib/compiler/assets-manager.ts index 63b838ae3..51cd5f09b 100644 --- a/lib/compiler/assets-manager.ts +++ b/lib/compiler/assets-manager.ts @@ -13,13 +13,25 @@ import { getValueOrDefault } from './helpers/get-value-or-default'; export class AssetsManager { private watchAssetsKeyValue: { [key: string]: boolean } = {}; private watchers: chokidar.FSWatcher[] = []; + private actionInProgress = false; /** * Using on `nest build` to close file watch or the build process will not end + * Interval like process + * If no action has been taken recently close watchers + * If action has been taken recently flag and try again */ public closeWatchers() { - const timeoutMs = 300; - const closeFn = () => this.watchers.forEach((watcher) => watcher.close()); + // Consider adjusting this for larger files + const timeoutMs = 500; + const closeFn = () => { + if (this.actionInProgress) { + this.actionInProgress = false; + setTimeout(closeFn, timeoutMs); + } else { + this.watchers.forEach((watcher) => watcher.close()); + } + }; setTimeout(closeFn, timeoutMs); } @@ -101,9 +113,10 @@ export class AssetsManager { if (!isWatchEnabled && this.watchAssetsKeyValue[path]) { return; } - // Set path value to true for watching the first time this.watchAssetsKeyValue[path] = true; + // Set action to true to avoid watches getting cutoff + this.actionInProgress = true; const dest = copyPathResolve( path,