Skip to content

Commit f13dcce

Browse files
authored
fix(core): ensure setting up nx cloud in nx migrate using the generator 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 #
1 parent 35dec92 commit f13dcce

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

packages/nx/src/command-line/connect/connect-to-nx-cloud.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { output } from '../../utils/output';
22
import { readNxJson } from '../../config/configuration';
3+
import { FsTree, flushChanges } from '../../generators/tree';
4+
import { connectToNxCloud } from '../../nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud';
35
import { getNxCloudUrl, isNxCloudUsed } from '../../utils/nx-cloud-utils';
46
import { runNxSync } from '../../utils/child-process';
57
import { NxJsonConfiguration } from '../../config/nx-json';
@@ -11,6 +13,7 @@ import {
1113
messages,
1214
} from '../../utils/ab-testing';
1315
import { nxVersion } from '../../utils/versions';
16+
import { workspaceRoot } from '../../utils/workspace-root';
1417
import chalk = require('chalk');
1518

1619
export function onlyDefaultRunnerIsUsed(nxJson: NxJsonConfiguration) {
@@ -59,9 +62,12 @@ export async function connectToNxCloudCommand(): Promise<boolean> {
5962
return false;
6063
}
6164

62-
runNxSync(`g nx:connect-to-nx-cloud --quiet --no-interactive`, {
63-
stdio: [0, 1, 2],
64-
});
65+
const tree = new FsTree(workspaceRoot, false, 'connect-to-nx-cloud');
66+
const callback = await connectToNxCloud(tree, {});
67+
tree.lock();
68+
flushChanges(workspaceRoot, tree.listChanges());
69+
callback();
70+
6571
return true;
6672
}
6773

packages/nx/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ function printSuccessMessage(url: string) {
8989
}
9090

9191
interface ConnectToNxCloudOptions {
92-
analytics: boolean;
93-
installationSource: string;
92+
analytics?: boolean;
93+
installationSource?: string;
9494
hideFormatLogs?: boolean;
9595
}
9696

@@ -114,6 +114,8 @@ export async function connectToNxCloud(
114114
tree: Tree,
115115
schema: ConnectToNxCloudOptions
116116
) {
117+
schema.installationSource ??= 'user';
118+
117119
const nxJson = readNxJson(tree) as
118120
| null
119121
| (NxJsonConfiguration & { neverConnectToCloud: boolean });

0 commit comments

Comments
 (0)