Skip to content

Commit 84075c3

Browse files
authoredMar 20, 2023
fix(core): misc daemon fixes (#15472)
1 parent 61fb737 commit 84075c3

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed
 

‎packages/nx/src/command-line/migrate.ts

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import { isCI } from '../utils/is-ci';
5656
import { getNxRequirePaths } from '../utils/installation-directory';
5757
import { readNxJson } from '../config/configuration';
5858
import { runNxSync } from '../utils/child-process';
59+
import { daemonClient } from '../daemon/client/client';
5960

6061
export interface ResolvedMigrationConfiguration extends MigrationsJson {
6162
packageGroup?: ArrayPackageGroup;
@@ -1553,6 +1554,8 @@ export async function migrate(
15531554
process.env.NX_VERBOSE_LOGGING = 'true';
15541555
}
15551556

1557+
await daemonClient.stop();
1558+
15561559
return handleErrors(process.env.NX_VERBOSE_LOGGING === 'true', async () => {
15571560
const opts = await parseMigrationsOptions(args);
15581561
if (opts.type === 'generateMigrations') {

‎packages/nx/src/daemon/client/client.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { workspaceRoot } from '../../utils/workspace-root';
22
import { ChildProcess, spawn } from 'child_process';
33
import { openSync, readFileSync, statSync } from 'fs';
4+
import { FileHandle, open } from 'fs/promises';
45
import { ensureDirSync, ensureFileSync } from 'fs-extra';
56
import { connect } from 'net';
67
import { join } from 'path';
@@ -48,6 +49,8 @@ export class DaemonClient {
4849

4950
private _enabled: boolean | undefined;
5051
private _connected: boolean;
52+
private _out: FileHandle = null;
53+
private _err: FileHandle = null;
5154

5255
enabled() {
5356
if (this._enabled === undefined) {
@@ -86,12 +89,19 @@ export class DaemonClient {
8689
}
8790

8891
reset() {
92+
this.socketMessenger?.close();
8993
this.socketMessenger = null;
9094
this.queue = new PromisedBasedQueue();
9195
this.currentMessage = null;
9296
this.currentResolve = null;
9397
this.currentReject = null;
9498
this._enabled = undefined;
99+
100+
this._out?.close();
101+
this._err?.close();
102+
this._out = null;
103+
this._err = null;
104+
95105
this._connected = false;
96106
}
97107

@@ -312,14 +322,15 @@ export class DaemonClient {
312322
ensureDirSync(DAEMON_DIR_FOR_CURRENT_WORKSPACE);
313323
ensureFileSync(DAEMON_OUTPUT_LOG_FILE);
314324

315-
const out = openSync(DAEMON_OUTPUT_LOG_FILE, 'a');
316-
const err = openSync(DAEMON_OUTPUT_LOG_FILE, 'a');
325+
this._out = await open(DAEMON_OUTPUT_LOG_FILE, 'a');
326+
this._err = await open(DAEMON_OUTPUT_LOG_FILE, 'a');
327+
317328
const backgroundProcess = spawn(
318329
process.execPath,
319330
[join(__dirname, '../server/start.js')],
320331
{
321332
cwd: workspaceRoot,
322-
stdio: ['ignore', out, err],
333+
stdio: ['ignore', this._out.fd, this._err.fd],
323334
detached: true,
324335
windowsHide: true,
325336
shell: false,

‎packages/nx/src/daemon/tmp-dir.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function isDaemonDisabled() {
5050

5151
function socketDirName() {
5252
const hasher = createHash('sha256');
53-
hasher.update(workspaceRoot);
53+
hasher.update(workspaceRoot.toLowerCase());
5454
const unique = hasher.digest('hex').substring(0, 20);
5555
return join(tmpdir, unique);
5656
}

‎packages/nx/src/project-graph/project-graph.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,11 @@ export async function createProjectGraphAsync(
130130
}
131131
} else {
132132
try {
133+
const projectGraph = await daemonClient.getProjectGraph();
133134
if (opts.resetDaemonClient) {
134135
daemonClient.reset();
135136
}
136-
return await daemonClient.getProjectGraph();
137+
return projectGraph;
137138
} catch (e) {
138139
if (e.message.indexOf('inotify_add_watch') > -1) {
139140
// common errors with the daemon due to OS settings (cannot watch all the files available)

0 commit comments

Comments
 (0)