Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: assets copying from 'nest build' is problematic
  • Loading branch information
NikolaPeevski committed Aug 2, 2021
1 parent 5d3ab68 commit 4ecf54f
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/compiler/assets-manager.ts
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 4ecf54f

Please sign in to comment.