diff --git a/packages/js/src/generators/release-version/release-version.ts b/packages/js/src/generators/release-version/release-version.ts index f6c2b88e79ce0..23a17728cebb6 100644 --- a/packages/js/src/generators/release-version/release-version.ts +++ b/packages/js/src/generators/release-version/release-version.ts @@ -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'; @@ -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; }, }; diff --git a/packages/js/src/generators/release-version/utils/update-lock-file.ts b/packages/js/src/generators/release-version/utils/update-lock-file.ts index 976c7e445d193..3f3ec5a744b2c 100644 --- a/packages/js/src/generators/release-version/utils/update-lock-file.ts +++ b/packages/js/src/generators/release-version/utils/update-lock-file.ts @@ -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, @@ -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); @@ -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]; }