Skip to content

Commit

Permalink
fix(release): do not restart the daemon when skipLockFileUpdate is set
Browse files Browse the repository at this point in the history
  • Loading branch information
fahslaj committed Jan 29, 2024
1 parent 1ea09ad commit eb427c7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
26 changes: 2 additions & 24 deletions packages/js/src/generators/release-version/release-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
deriveNewSemverVersion,
validReleaseVersionPrefixes,
} from 'nx/src/command-line/release/version';
import { daemonClient } from 'nx/src/daemon/client/client';

import { interpolate } from 'nx/src/tasks-runner/utils';
import * as ora from 'ora';
import { relative } from 'path';
Expand Down Expand Up @@ -500,29 +500,7 @@ To fix this you will either need to add a package.json file at that location, or
data: versionData,
callback: async (tree, opts) => {
const cwd = tree.root;

const isDaemonEnabled = daemonClient.enabled();
if (isDaemonEnabled) {
// temporarily stop the daemon, as it will error if the lock file is updated
await daemonClient.stop();
}

const updatedFiles = updateLockFile(cwd, opts);

if (isDaemonEnabled) {
try {
await daemonClient.startInBackground();
} catch (e) {
// If the daemon fails to start, we don't want to prevent the user from continuing, so we just log the error and move on
if (opts.verbose) {
output.warn({
title:
'Unable to restart the Nx Daemon. It will be disabled until you run "nx reset"',
bodyLines: [e.message],
});
}
}
}
const updatedFiles = await updateLockFile(cwd, opts);
return updatedFiles;
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import {
output,
} from '@nx/devkit';
import { execSync } from 'child_process';
import { daemonClient } from 'nx/src/daemon/client/client';
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
import { getLockFileName } from 'nx/src/plugins/js/lock-file/lock-file';
import { gte } from 'semver';

export function updateLockFile(
export async function updateLockFile(
cwd: string,
{
dryRun,
Expand All @@ -30,6 +31,12 @@ export function updateLockFile(
return [];
}

const isDaemonEnabled = daemonClient.enabled();
if (isDaemonEnabled) {
// temporarily stop the daemon, as it will error if the lock file is updated
await daemonClient.stop();
}

const packageManager = detectPackageManager(cwd);
const packageManagerCommands = getPackageManagerCommand(packageManager);

Expand Down Expand Up @@ -72,6 +79,21 @@ export function updateLockFile(

execLockFileUpdate(command, cwd, env);

if (isDaemonEnabled) {
try {
await daemonClient.startInBackground();
} catch (e) {
// If the daemon fails to start, we don't want to prevent the user from continuing, so we just log the error and move on
if (verbose) {
output.warn({
title:
'Unable to restart the Nx Daemon. It will be disabled until you run "nx reset"',
bodyLines: [e.message],
});
}
}
}

return [lockFile];
}

Expand Down

0 comments on commit eb427c7

Please sign in to comment.