feat(core): add the ability to reset the daemon client when getting a project graph
This commit is contained in:
parent
24c8124e79
commit
8d1f284048
@ -31,18 +31,20 @@ const DAEMON_ENV_SETTINGS = {
|
||||
};
|
||||
|
||||
export class DaemonClient {
|
||||
constructor(private readonly nxJson: NxJsonConfiguration) {}
|
||||
constructor(private readonly nxJson: NxJsonConfiguration) {
|
||||
this.reset();
|
||||
}
|
||||
|
||||
private queue = new PromisedBasedQueue();
|
||||
private queue: PromisedBasedQueue;
|
||||
|
||||
private socket = null;
|
||||
private socket;
|
||||
|
||||
private currentMessage = null;
|
||||
private currentResolve = null;
|
||||
private currentReject = null;
|
||||
private currentMessage;
|
||||
private currentResolve;
|
||||
private currentReject;
|
||||
|
||||
private _enabled: boolean | undefined;
|
||||
private _connected: boolean = false;
|
||||
private _connected: boolean;
|
||||
|
||||
enabled() {
|
||||
if (this._enabled === undefined) {
|
||||
@ -79,6 +81,16 @@ export class DaemonClient {
|
||||
return this._enabled;
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.queue = new PromisedBasedQueue();
|
||||
this.socket = null;
|
||||
this.currentMessage = null;
|
||||
this.currentResolve = null;
|
||||
this.currentReject = null;
|
||||
this._enabled = undefined;
|
||||
this._connected = false;
|
||||
}
|
||||
|
||||
async getProjectGraph(): Promise<ProjectGraph> {
|
||||
return (await this.sendToDaemonViaQueue({ type: 'REQUEST_PROJECT_GRAPH' }))
|
||||
.projectGraph;
|
||||
|
||||
@ -118,7 +118,10 @@ function handleProjectGraphError(opts: { exitOnError: boolean }, e) {
|
||||
* stored in the daemon process. To reset both run: `nx reset`.
|
||||
*/
|
||||
export async function createProjectGraphAsync(
|
||||
opts: { exitOnError: boolean } = { exitOnError: false }
|
||||
opts: { exitOnError: boolean; resetDaemonClient?: boolean } = {
|
||||
exitOnError: false,
|
||||
resetDaemonClient: false,
|
||||
}
|
||||
): Promise<ProjectGraph> {
|
||||
if (!daemonClient.enabled()) {
|
||||
try {
|
||||
@ -128,6 +131,9 @@ export async function createProjectGraphAsync(
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
if (opts.resetDaemonClient) {
|
||||
daemonClient.reset();
|
||||
}
|
||||
return await daemonClient.getProjectGraph();
|
||||
} catch (e) {
|
||||
if (!e.internalDaemonError) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user