fix(core): only stop daemon if enabled (#28146)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes https://github.com/nrwl/nx/issues/27971
This commit is contained in:
Emily Xiong 2024-09-27 12:09:04 -04:00 committed by GitHub
parent 94932ec0e1
commit 0061b858b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -42,15 +42,15 @@ export async function resetHandler(args: ResetCommandOptions) {
if (all || args.onlyDaemon) { if (all || args.onlyDaemon) {
try { try {
await killDaemon(); await killDaemon();
} catch { } catch (e) {
errors.push('Failed to stop the Nx Daemon.'); errors.push('Failed to stop the Nx Daemon.', e.toString());
} }
} }
if (all || args.onlyCache) { if (all || args.onlyCache) {
try { try {
await cleanupCacheEntries(); await cleanupCacheEntries();
} catch { } catch (e) {
errors.push('Failed to clean up the cache directory.'); errors.push('Failed to clean up the cache directory.', e.toString());
} }
} }
if (all || args.onlyWorkspaceData) { if (all || args.onlyWorkspaceData) {
@ -61,12 +61,19 @@ export async function resetHandler(args: ResetCommandOptions) {
} }
try { try {
await cleanupWorkspaceData(); await cleanupWorkspaceData();
} catch { } catch (e) {
errors.push('Failed to clean up the workspace data directory.'); errors.push(
'Failed to clean up the workspace data directory.',
e.toString()
);
} }
} }
if (all || args.onlyCloud) { if (all || args.onlyCloud) {
try {
await resetCloudClient(); await resetCloudClient();
} catch (e) {
errors.push('Failed to reset the Nx Cloud client.', e.toString());
}
} }
if (errors.length > 0) { if (errors.length > 0) {
output.error({ output.error({
@ -81,9 +88,11 @@ export async function resetHandler(args: ResetCommandOptions) {
} }
} }
function killDaemon() { async function killDaemon(): Promise<void> {
if (daemonClient.enabled()) {
return daemonClient.stop(); return daemonClient.stop();
} }
}
async function resetCloudClient() { async function resetCloudClient() {
// Remove nx cloud marker files. This helps if the use happens to run `nx-cloud start-ci-run` or // Remove nx cloud marker files. This helps if the use happens to run `nx-cloud start-ci-run` or