From 4ecf54f10456e68e60a947cf3effa324c69a8c68 Mon Sep 17 00:00:00 2001 From: nikolapeevski Date: Mon, 2 Aug 2021 23:55:51 +0300 Subject: [PATCH] fix: assets copying from 'nest build' is problematic --- lib/compiler/assets-manager.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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,