From f13dcce8a9a911413cc97ed297e9797acd9a59e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Mon, 6 May 2024 16:31:11 +0200 Subject: [PATCH] fix(core): ensure setting up nx cloud in nx migrate using the generator from the installed latest version (#23194) ## Current Behavior 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 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) Fixes # --- .../src/command-line/connect/connect-to-nx-cloud.ts | 12 +++++++++--- .../connect-to-nx-cloud/connect-to-nx-cloud.ts | 6 ++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/nx/src/command-line/connect/connect-to-nx-cloud.ts b/packages/nx/src/command-line/connect/connect-to-nx-cloud.ts index 2b743b18d3031..a0d0392031f89 100644 --- a/packages/nx/src/command-line/connect/connect-to-nx-cloud.ts +++ b/packages/nx/src/command-line/connect/connect-to-nx-cloud.ts @@ -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'; @@ -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) { @@ -59,9 +62,12 @@ export async function connectToNxCloudCommand(): Promise { 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; } diff --git a/packages/nx/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.ts b/packages/nx/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.ts index 6f4f85c7fd6e0..2f07596b497a2 100644 --- a/packages/nx/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.ts +++ b/packages/nx/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.ts @@ -89,8 +89,8 @@ function printSuccessMessage(url: string) { } interface ConnectToNxCloudOptions { - analytics: boolean; - installationSource: string; + analytics?: boolean; + installationSource?: string; hideFormatLogs?: boolean; } @@ -114,6 +114,8 @@ export async function connectToNxCloud( tree: Tree, schema: ConnectToNxCloudOptions ) { + schema.installationSource ??= 'user'; + const nxJson = readNxJson(tree) as | null | (NxJsonConfiguration & { neverConnectToCloud: boolean });