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 {
|
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 currentMessage;
|
||||||
private currentResolve = null;
|
private currentResolve;
|
||||||
private currentReject = null;
|
private currentReject;
|
||||||
|
|
||||||
private _enabled: boolean | undefined;
|
private _enabled: boolean | undefined;
|
||||||
private _connected: boolean = false;
|
private _connected: boolean;
|
||||||
|
|
||||||
enabled() {
|
enabled() {
|
||||||
if (this._enabled === undefined) {
|
if (this._enabled === undefined) {
|
||||||
@ -79,6 +81,16 @@ export class DaemonClient {
|
|||||||
return this._enabled;
|
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> {
|
async getProjectGraph(): Promise<ProjectGraph> {
|
||||||
return (await this.sendToDaemonViaQueue({ type: 'REQUEST_PROJECT_GRAPH' }))
|
return (await this.sendToDaemonViaQueue({ type: 'REQUEST_PROJECT_GRAPH' }))
|
||||||
.projectGraph;
|
.projectGraph;
|
||||||
|
|||||||
@ -118,7 +118,10 @@ function handleProjectGraphError(opts: { exitOnError: boolean }, e) {
|
|||||||
* stored in the daemon process. To reset both run: `nx reset`.
|
* stored in the daemon process. To reset both run: `nx reset`.
|
||||||
*/
|
*/
|
||||||
export async function createProjectGraphAsync(
|
export async function createProjectGraphAsync(
|
||||||
opts: { exitOnError: boolean } = { exitOnError: false }
|
opts: { exitOnError: boolean; resetDaemonClient?: boolean } = {
|
||||||
|
exitOnError: false,
|
||||||
|
resetDaemonClient: false,
|
||||||
|
}
|
||||||
): Promise<ProjectGraph> {
|
): Promise<ProjectGraph> {
|
||||||
if (!daemonClient.enabled()) {
|
if (!daemonClient.enabled()) {
|
||||||
try {
|
try {
|
||||||
@ -128,6 +131,9 @@ export async function createProjectGraphAsync(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
if (opts.resetDaemonClient) {
|
||||||
|
daemonClient.reset();
|
||||||
|
}
|
||||||
return await daemonClient.getProjectGraph();
|
return await daemonClient.getProjectGraph();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!e.internalDaemonError) {
|
if (!e.internalDaemonError) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user