diff --git a/actions/build.action.ts b/actions/build.action.ts index 7553afc0e..84e19fca8 100644 --- a/actions/build.action.ts +++ b/actions/build.action.ts @@ -152,7 +152,6 @@ export class BuildAction extends AbstractAction { ); } else { this.compiler.run(configuration, pathToTsconfig, appName, onSuccess); - this.assetsManager.closeWatchers(); } } diff --git a/lib/compiler/assets-manager.ts b/lib/compiler/assets-manager.ts index 51cd5f09b..fe1b3384f 100644 --- a/lib/compiler/assets-manager.ts +++ b/lib/compiler/assets-manager.ts @@ -13,27 +13,9 @@ 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() { - // 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); + this.watchers.forEach((watcher) => watcher.close()); } public copyAssets( @@ -96,6 +78,10 @@ export class AssetsManager { .on('change', (path: string) => this.actionOnFile({ ...option, path, action: 'change' })) .on('unlink', (path: string) => this.actionOnFile({ ...option, path, action: 'unlink' })); + if (!isWatchEnabled) { + watcher.on('ready', () => watcher.close()); + } + this.watchers.push(watcher); } } catch (err) { @@ -115,8 +101,6 @@ export class AssetsManager { } // 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,