From 0ef6892a6e3eb525548972b2e18b187a750a0356 Mon Sep 17 00:00:00 2001 From: Louie Weng <56288712+lourw@users.noreply.github.com> Date: Wed, 28 Aug 2024 21:14:01 +0200 Subject: [PATCH] feat(nx-cloud): remove feature flag for nx login (#27657) ## Current Behavior ## Expected Behavior Enables `nx connect` to use the V2 endpoint from Nx API such that it creates an `nxCloudId` ## Related Issue(s) Fixes # --- .../connect/connect-to-nx-cloud.spec.ts | 2 +- .../connect-to-nx-cloud.ts | 102 +++--------------- 2 files changed, 17 insertions(+), 87 deletions(-) diff --git a/packages/nx/src/command-line/connect/connect-to-nx-cloud.spec.ts b/packages/nx/src/command-line/connect/connect-to-nx-cloud.spec.ts index 3a7abee3f0522..691950b0bbdf2 100644 --- a/packages/nx/src/command-line/connect/connect-to-nx-cloud.spec.ts +++ b/packages/nx/src/command-line/connect/connect-to-nx-cloud.spec.ts @@ -21,7 +21,7 @@ describe('connect-to-nx-cloud', () => { expect( withEnvironmentVariables( { - NX_ENABLE_LOGIN: 'true', + NX_CLOUD_ACCESS_TOKEN: null, }, () => onlyDefaultRunnerIsUsed({ 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 28daeb07d20a6..401d3543dace9 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 @@ -48,28 +48,6 @@ function getNxInitDate(): string | null { } } -async function createNxCloudWorkspaceV1( - workspaceName: string, - installationSource: string, - nxInitDate: string | null -): Promise<{ token: string; url: string }> { - const apiUrl = getCloudUrl(); - const response = await require('axios').post( - `${apiUrl}/nx-cloud/create-org-and-workspace`, - { - workspaceName, - installationSource, - nxInitDate, - } - ); - - if (response.data.message) { - throw new Error(response.data.message); - } - - return response.data; -} - async function createNxCloudWorkspaceV2( workspaceName: string, installationSource: string, @@ -124,29 +102,6 @@ export interface ConnectToNxCloudOptions { directory?: string; } -function addNxCloudOptionsToNxJson( - tree: Tree, - token: string, - directory: string = '' -) { - const nxJsonPath = join(directory, 'nx.json'); - if (tree.exists(nxJsonPath)) { - updateJson( - tree, - join(directory, 'nx.json'), - (nxJson) => { - const overrideUrl = process.env.NX_CLOUD_API || process.env.NRWL_API; - if (overrideUrl) { - nxJson.nxCloudUrl = overrideUrl; - } - nxJson.nxCloudAccessToken = token; - - return nxJson; - } - ); - } -} - function addNxCloudIdToNxJson( tree: Tree, nxCloudId: string, @@ -183,12 +138,6 @@ export async function connectToNxCloud( } else { const usesGithub = schema.github ?? (await repoUsesGithub(schema.github)); - let responseFromCreateNxCloudWorkspaceV1: - | { - token: string; - } - | undefined; - let responseFromCreateNxCloudWorkspaceV2: | { nxCloudId: string; @@ -198,41 +147,22 @@ export async function connectToNxCloud( // do NOT create Nx Cloud token (createNxCloudWorkspace) // if user is using github and is running nx-connect if (!(usesGithub && schema.installationSource === 'nx-connect')) { - if (process.env.NX_ENABLE_LOGIN === 'true') { - responseFromCreateNxCloudWorkspaceV2 = await createNxCloudWorkspaceV2( - getRootPackageName(tree), - schema.installationSource, - getNxInitDate() - ); - - addNxCloudIdToNxJson( - tree, - responseFromCreateNxCloudWorkspaceV2?.nxCloudId, - schema.directory - ); - - await formatChangedFilesWithPrettierIfAvailable(tree, { - silent: schema.hideFormatLogs, - }); - return responseFromCreateNxCloudWorkspaceV2.nxCloudId; - } else { - responseFromCreateNxCloudWorkspaceV1 = await createNxCloudWorkspaceV1( - getRootPackageName(tree), - schema.installationSource, - getNxInitDate() - ); - - addNxCloudOptionsToNxJson( - tree, - responseFromCreateNxCloudWorkspaceV1?.token, - schema.directory - ); - - await formatChangedFilesWithPrettierIfAvailable(tree, { - silent: schema.hideFormatLogs, - }); - return responseFromCreateNxCloudWorkspaceV1.token; - } + responseFromCreateNxCloudWorkspaceV2 = await createNxCloudWorkspaceV2( + getRootPackageName(tree), + schema.installationSource, + getNxInitDate() + ); + + addNxCloudIdToNxJson( + tree, + responseFromCreateNxCloudWorkspaceV2?.nxCloudId, + schema.directory + ); + + await formatChangedFilesWithPrettierIfAvailable(tree, { + silent: schema.hideFormatLogs, + }); + return responseFromCreateNxCloudWorkspaceV2.nxCloudId; } } }