Skip to content

Commit d6572f3

Browse files
authored
fix(core): clean up daemon workspace data directory on nx reset --onl… (#34174)
Previously, `nx reset --onlyDaemon` would only stop the daemon process but not clean up the daemon files in `.nx/workspace-data/d`. This change ensures the daemon workspace data directory is also removed when using the `--onlyDaemon` flag, consistent with the behavior of a full reset. Co-authored-by: MaxKless <[email protected]>
1 parent 367986d commit d6572f3

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

packages/nx/src/command-line/reset/command-object.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const yargsResetCommand: CommandModule<
2424
})
2525
.option('onlyDaemon', {
2626
description:
27-
'Stops the Nx Daemon, it will be restarted fresh when the next Nx command is run.',
27+
'Stops the Nx Daemon and clears its workspace data, it will be restarted fresh when the next Nx command is run.',
2828
type: 'boolean',
2929
})
3030
.option('onlyCloud', {

packages/nx/src/command-line/reset/reset.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { rmSync } from 'node:fs';
22
import { join } from 'node:path';
33

44
import { daemonClient } from '../../daemon/client/client';
5+
import { DAEMON_DIR_FOR_CURRENT_WORKSPACE } from '../../daemon/tmp-dir';
56
import { cacheDir, workspaceDataDirectory } from '../../utils/cache-directory';
67
import { output } from '../../utils/output';
78
import { getNativeFileCacheLocation } from '../../native/native-file-cache-location';
@@ -35,7 +36,7 @@ export async function resetHandler(args: ResetCommandOptions) {
3536
const bodyLines = [];
3637
if (!all) {
3738
if (args.onlyDaemon) {
38-
bodyLines.push('- Nx Daemon');
39+
bodyLines.push('- Nx Daemon and its workspace data');
3940
}
4041
if (args.onlyCache) {
4142
bodyLines.push('- Cache directory');
@@ -55,6 +56,14 @@ export async function resetHandler(args: ResetCommandOptions) {
5556
} catch (e) {
5657
errors.push('Failed to stop the Nx Daemon.', e.toString());
5758
}
59+
try {
60+
await cleanupDaemonWorkspaceData();
61+
} catch (e) {
62+
errors.push(
63+
'Failed to clean up the daemon workspace data directory.',
64+
e.toString()
65+
);
66+
}
5867
}
5968
if (all || args.onlyCache) {
6069
try {
@@ -105,6 +114,19 @@ async function killDaemon(): Promise<void> {
105114
}
106115
}
107116

117+
function cleanupDaemonWorkspaceData() {
118+
return incrementalBackoff(
119+
INCREMENTAL_BACKOFF_FIRST_DELAY,
120+
INCREMENTAL_BACKOFF_MAX_DURATION,
121+
() => {
122+
rmSync(DAEMON_DIR_FOR_CURRENT_WORKSPACE, {
123+
recursive: true,
124+
force: true,
125+
});
126+
}
127+
);
128+
}
129+
108130
async function resetCloudClient() {
109131
// Remove nx cloud marker files. This helps if the use happens to run `nx-cloud start-ci-run` or
110132
// similar commands on their local machine.

0 commit comments

Comments
 (0)