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

fix(): copy all assets on build #1829

Merged
merged 1 commit into from Dec 27, 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: 0 additions & 1 deletion actions/build.action.ts
Expand Up @@ -152,7 +152,6 @@ export class BuildAction extends AbstractAction {
);
} else {
this.compiler.run(configuration, pathToTsconfig, appName, onSuccess);
this.assetsManager.closeWatchers();
}
}

Expand Down
26 changes: 5 additions & 21 deletions lib/compiler/assets-manager.ts
Expand Up @@ -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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.watchers.forEach((watcher) => watcher.close());
this.watchers.forEach((watcher) => watcher.close());

AFAIR close() returns a Promise

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the same as before. Is there a problem with that?

}

public copyAssets(
Expand Down Expand Up @@ -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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Watcher event listener return type is void, so it will not listen to the promise.

}

this.watchers.push(watcher);
}
} catch (err) {
Expand All @@ -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,
Expand Down