Skip to content

Commit

Permalink
fix(core): ensure setting up nx cloud in nx migrate using the generat…
Browse files Browse the repository at this point in the history
…or from the installed latest version (#23194)

<!-- 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` -->

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

Choosing to set up Nx Cloud during `nx migrate` executes the generator
from the locally installed packages. This leads to the user getting an
outdated flow and messaging.

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

Choosing to set up Nx Cloud during `nx migrate` should execute the
generator from the installed latest version to ensure the user gets the
up-to-date flow and messaging.

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

Fixes #
  • Loading branch information
leosvelperez committed May 6, 2024
1 parent 35dec92 commit f13dcce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 9 additions & 3 deletions packages/nx/src/command-line/connect/connect-to-nx-cloud.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { output } from '../../utils/output';
import { readNxJson } from '../../config/configuration';
import { FsTree, flushChanges } from '../../generators/tree';
import { connectToNxCloud } from '../../nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud';
import { getNxCloudUrl, isNxCloudUsed } from '../../utils/nx-cloud-utils';
import { runNxSync } from '../../utils/child-process';
import { NxJsonConfiguration } from '../../config/nx-json';
Expand All @@ -11,6 +13,7 @@ import {
messages,
} from '../../utils/ab-testing';
import { nxVersion } from '../../utils/versions';
import { workspaceRoot } from '../../utils/workspace-root';
import chalk = require('chalk');

export function onlyDefaultRunnerIsUsed(nxJson: NxJsonConfiguration) {
Expand Down Expand Up @@ -59,9 +62,12 @@ export async function connectToNxCloudCommand(): Promise<boolean> {
return false;
}

runNxSync(`g nx:connect-to-nx-cloud --quiet --no-interactive`, {
stdio: [0, 1, 2],
});
const tree = new FsTree(workspaceRoot, false, 'connect-to-nx-cloud');
const callback = await connectToNxCloud(tree, {});
tree.lock();
flushChanges(workspaceRoot, tree.listChanges());
callback();

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ function printSuccessMessage(url: string) {
}

interface ConnectToNxCloudOptions {
analytics: boolean;
installationSource: string;
analytics?: boolean;
installationSource?: string;
hideFormatLogs?: boolean;
}

Expand All @@ -114,6 +114,8 @@ export async function connectToNxCloud(
tree: Tree,
schema: ConnectToNxCloudOptions
) {
schema.installationSource ??= 'user';

const nxJson = readNxJson(tree) as
| null
| (NxJsonConfiguration & { neverConnectToCloud: boolean });
Expand Down

0 comments on commit f13dcce

Please sign in to comment.