Skip to content

Commit

Permalink
further prod/staging fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKless committed Dec 28, 2022
1 parent c2139f6 commit 1672a2e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getNxCloudRunnerUrl } from '@nx-console/vscode/nx-workspace';
import { getNxCloudRunnerOptions } from '@nx-console/vscode/nx-workspace';
import { commands, ExtensionContext, window } from 'vscode';
import { NxCloudAuthenticationProvider } from './auth/nx-cloud-authentication-provider';
import { prodConfig, stagingConfig } from './config';
Expand Down Expand Up @@ -44,7 +44,12 @@ export async function initNxCloudOnboardingView(
async function determineProdOrDevMode(
productionEnv: boolean
): Promise<'prod' | 'dev'> {
const nxCloudRunnerUrl = await getNxCloudRunnerUrl();
const nxCloudRunnerOptions = await getNxCloudRunnerOptions();

// if we're using the cloud runner but no URL is defined, it means an implicit prod endpoint
const nxCloudRunnerUrl = nxCloudRunnerOptions
? nxCloudRunnerOptions.url ?? prodConfig.appUrl
: '';

if (nxCloudRunnerUrl === stagingConfig.appUrl) {
return 'dev';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getPackageManagerCommand } from '@nrwl/devkit';
import { WorkspaceConfigurationStore } from '@nx-console/vscode/configuration';
import { EXECUTE_ARBITRARY_COMMAND } from '@nx-console/vscode/nx-commands-view';
import {
getNxCloudRunnerUrl,
getNxCloudRunnerOptions,
getNxWorkspace,
} from '@nx-console/vscode/nx-workspace';
import {
Expand All @@ -29,7 +29,7 @@ import {
tasks,
window,
} from 'vscode';
import type { CloudConfig } from '../config';
import { CloudConfig, prodConfig, stagingConfig } from '../config';
import {
CLAIM_COMMAND,
INSPECT_RUN_COMMAND,
Expand Down Expand Up @@ -213,7 +213,13 @@ export class NxCloudService extends StateBaseService<InternalState> {
'latest'
);

const env = { ...process.env, NX_CLOUD_API: this.config.appUrl };
const cloudRunnerUrl =
this.config.appUrl === stagingConfig.appUrl
? stagingConfig.appUrl
: undefined;
const env = cloudRunnerUrl
? { ...process.env, NX_CLOUD_API: this.config.appUrl }
: process.env;

window.withProgress(
{
Expand Down Expand Up @@ -400,10 +406,7 @@ export class NxCloudService extends StateBaseService<InternalState> {
}

private async openRunDetails(runLinkId: string) {
const url = await getNxCloudRunnerUrl();
if (!url) {
return;
}
const url = await this.getCloudRunnerUrl();
commands.executeCommand(
'vscode.open',
`${url}/runs/${runLinkId}?utm_source=nxconsole`
Expand All @@ -420,7 +423,7 @@ export class NxCloudService extends StateBaseService<InternalState> {
}
const orgId = this.state.cloudWorkspaceOrgId;
const workspaceId = this.state.cloudWorkspaceId;
const baseUrl = await getNxCloudRunnerUrl();
const baseUrl = await this.getCloudRunnerUrl();

const link = `${baseUrl}/orgs/${orgId}/workspaces/${workspaceId}/set-up-vcs-integration?utm_source=nxconsole`;

Expand Down Expand Up @@ -664,4 +667,8 @@ export class NxCloudService extends StateBaseService<InternalState> {
(r) => r.runner == '@nrwl/nx-cloud'
);
}

private async getCloudRunnerUrl(): Promise<string> {
return (await getNxCloudRunnerOptions())?.url ?? prodConfig.appUrl;
}
}
6 changes: 4 additions & 2 deletions libs/vscode/nx-workspace/src/lib/get-nx-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export async function getNxWorkspaceProjects(reset?: boolean): Promise<{
return projects;
}

export async function getNxCloudRunnerUrl(): Promise<string | undefined> {
export async function getNxCloudRunnerOptions(): Promise<
{ accessToken: string; url?: string } | undefined
> {
const nxConfig = (await getNxWorkspace()).workspace;

if (!nxConfig.tasksRunnerOptions) {
Expand All @@ -26,5 +28,5 @@ export async function getNxCloudRunnerUrl(): Promise<string | undefined> {
const nxCloudTaskRunner = Object.values(nxConfig.tasksRunnerOptions).find(
(r) => r.runner == '@nrwl/nx-cloud'
);
return nxCloudTaskRunner?.options?.url;
return nxCloudTaskRunner?.options;
}

0 comments on commit 1672a2e

Please sign in to comment.