Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "fix(): copy all assets on build" #1866

Merged
merged 1 commit into from Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions actions/build.action.ts
Expand Up @@ -152,6 +152,7 @@ export class BuildAction extends AbstractAction {
);
} else {
this.compiler.run(configuration, pathToTsconfig, appName, onSuccess);
this.assetsManager.closeWatchers();
}
}

Expand Down
26 changes: 21 additions & 5 deletions lib/compiler/assets-manager.ts
Expand Up @@ -13,9 +13,27 @@ 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() {
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);
}

public copyAssets(
Expand Down Expand Up @@ -78,10 +96,6 @@ 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) {
Expand All @@ -101,6 +115,8 @@ 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,
Expand Down