File tree 4 files changed +58
-2
lines changed
4 files changed +58
-2
lines changed Original file line number Diff line number Diff line change @@ -8,3 +8,4 @@ export * from './lib/lsp-log';
8
8
export * from './lib/json-language-service' ;
9
9
export * from './lib/find-property' ;
10
10
export * from './lib/executor' ;
11
+ export * from './lib/nx-cloud' ;
Original file line number Diff line number Diff line change
1
+ import { importNxPackagePath , readNxJson } from '@nx-console/shared/npm' ;
2
+ import type { NxJsonConfiguration } from 'nx/src/devkit-exports' ;
3
+ import { lspLogger } from './lsp-log' ;
4
+
5
+ export async function isNxCloudUsed ( workspacePath : string ) : Promise < boolean > {
6
+ const nxJson = await readNxJson ( workspacePath ) ;
7
+
8
+ let getIsNxCloudUsed : ( nxJson : NxJsonConfiguration ) => boolean ;
9
+ try {
10
+ // try to use nx utils if they exist
11
+ const nxCloudUtils = await importNxPackagePath <
12
+ typeof import ( 'nx/src/utils/nx-cloud-utils' )
13
+ > ( workspacePath , 'src/utils/nx-cloud-utils' , lspLogger ) ;
14
+ getIsNxCloudUsed = nxCloudUtils . isNxCloudUsed ;
15
+ } catch ( e ) {
16
+ // fallback implementation, copied from nx
17
+ getIsNxCloudUsed = ( nxJson : NxJsonConfiguration ) => {
18
+ if ( process . env . NX_NO_CLOUD === 'true' || nxJson . neverConnectToCloud ) {
19
+ return false ;
20
+ }
21
+
22
+ return (
23
+ ! ! process . env . NX_CLOUD_ACCESS_TOKEN ||
24
+ ! ! nxJson . nxCloudAccessToken ||
25
+ ! ! nxJson . nxCloudId ||
26
+ ! ! Object . values ( nxJson . tasksRunnerOptions ?? { } ) . find (
27
+ ( r ) => r . runner == '@nrwl/nx-cloud' || r . runner == 'nx-cloud'
28
+ )
29
+ ) ;
30
+ } ;
31
+ }
32
+
33
+ return getIsNxCloudUsed ( nxJson ) ;
34
+ }
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { existsSync, readFileSync } from 'fs';
3
3
import * as os from 'node:os' ;
4
4
import { join } from 'path' ;
5
5
6
- import { lspLogger } from '@nx-console/language-server/utils' ;
6
+ import { isNxCloudUsed , lspLogger } from '@nx-console/language-server/utils' ;
7
7
import {
8
8
getNxAccessToken ,
9
9
getNxCloudId ,
@@ -24,6 +24,16 @@ export async function getCloudOnboardingInfo(
24
24
content . includes ( 'nx affected' )
25
25
) ;
26
26
27
+ if ( ! ( await isNxCloudUsed ( workspacePath ) ) ) {
28
+ return {
29
+ hasNxInCI,
30
+ hasAffectedCommandsInCI,
31
+ isConnectedToCloud : false ,
32
+ isWorkspaceClaimed : false ,
33
+ personalAccessToken : undefined ,
34
+ } ;
35
+ }
36
+
27
37
const accessToken = await getNxAccessToken ( workspacePath ) ;
28
38
const nxCloudId = await getNxCloudId ( workspacePath ) ;
29
39
const nxCloudUrl = await getNxCloudUrl ( workspacePath ) ;
@@ -185,6 +195,7 @@ async function getNxCloudWorkspaceClaimed(
185
195
headers [ 'Nx-Cloud-Personal-Access-Token' ] = pat ;
186
196
}
187
197
198
+ lspLogger . log ( `Making claimed request` ) ;
188
199
try {
189
200
const response = await xhr ( {
190
201
type : 'POST' ,
Original file line number Diff line number Diff line change 1
- import { lspLogger } from '@nx-console/language-server/utils' ;
1
+ import { isNxCloudUsed , lspLogger } from '@nx-console/language-server/utils' ;
2
2
import {
3
3
getNxAccessToken ,
4
4
getNxCloudId ,
@@ -14,6 +14,15 @@ export async function getRecentCIPEData(workspacePath: string): Promise<{
14
14
error ?: CIPEInfoError ;
15
15
workspaceUrl ?: string ;
16
16
} > {
17
+ if ( ! ( await isNxCloudUsed ( workspacePath ) ) ) {
18
+ return {
19
+ error : {
20
+ type : 'other' ,
21
+ message : 'Nx Cloud is not used in this workspace' ,
22
+ } ,
23
+ } ;
24
+ }
25
+
17
26
const branches = getRecentlyCommittedGitBranches ( workspacePath ) ;
18
27
19
28
const nxCloudUrl = await getNxCloudUrl ( workspacePath ) ;
@@ -44,6 +53,7 @@ export async function getRecentCIPEData(workspacePath: string): Promise<{
44
53
headers [ 'Authorization' ] = accessToken ;
45
54
}
46
55
56
+ lspLogger . log ( `Making recent CIPE request` ) ;
47
57
try {
48
58
const response = await xhr ( {
49
59
type : 'POST' ,
You can’t perform that action at this time.
0 commit comments