Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(release): do not restart the daemon when skipLockFileUpdate is set #21389

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 7 additions & 1 deletion scripts/nx-release.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env node
import { createProjectGraphAsync, workspaceRoot } from '@nx/devkit';
import * as chalk from 'chalk';
import { execSync } from 'node:child_process';
import { rmSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { URL } from 'node:url';
import { isRelativeVersionKeyword } from 'nx/src/command-line/release/utils/semver';
import { ReleaseType, inc, major, parse } from 'semver';
import * as yargs from 'yargs';
import * as chalk from 'chalk';

const LARGE_BUFFER = 1024 * 1000000;

Expand Down Expand Up @@ -58,6 +58,9 @@ const LARGE_BUFFER = 1024 * 1000000;
if (options.dryRun) {
versionCommand += ' --dry-run';
}
if (isVerboseLogging) {
versionCommand += ' --verbose';
}
console.log(`> ${versionCommand}`);
execSync(versionCommand, {
stdio: isVerboseLogging ? [0, 1, 2] : 'ignore',
Expand Down Expand Up @@ -95,6 +98,9 @@ const LARGE_BUFFER = 1024 * 1000000;
if (options.dryRun) {
changelogCommand += ' --dry-run';
}
if (isVerboseLogging) {
changelogCommand += ' --verbose';
}
console.log(`> ${changelogCommand}`);
execSync(changelogCommand, {
stdio: isVerboseLogging ? [0, 1, 2] : 'ignore',
Expand Down