File tree 9 files changed +73
-58
lines changed
intellij/src/main/kotlin/dev/nx/console/utils
9 files changed +73
-58
lines changed Original file line number Diff line number Diff line change @@ -3,10 +3,9 @@ package dev.nx.console.utils
3
3
import com.intellij.openapi.application.readAction
4
4
import com.intellij.openapi.progress.ProgressManager
5
5
import com.intellij.openapi.project.Project
6
+ import com.intellij.openapi.roots.ProjectFileIndex
6
7
import com.intellij.openapi.vfs.LocalFileSystem
7
- import com.intellij.openapi.vfs.VfsUtilCore
8
8
import com.intellij.openapi.vfs.VirtualFile
9
- import com.intellij.openapi.vfs.VirtualFileVisitor
10
9
11
10
suspend fun findNxConfigurationFiles (
12
11
project : Project ,
@@ -16,22 +15,17 @@ suspend fun findNxConfigurationFiles(
16
15
readAction {
17
16
val startDirectory = LocalFileSystem .getInstance().findFileByPath(project.nxBasePath)
18
17
if (startDirectory != null ) {
19
- VfsUtilCore .visitChildrenRecursively(
20
- startDirectory,
21
- object : VirtualFileVisitor <Any ?>() {
22
- override fun visitFile (file : VirtualFile ): Boolean {
23
- if (
24
- ! file.isDirectory &&
25
- (file.name == " project.json" ||
26
- (includeNxJson && file.name == " nx.json" ))
27
- ) {
28
- paths.add(file)
29
- }
30
- ProgressManager .checkCanceled()
31
- return true
32
- }
18
+ ProjectFileIndex .getInstance(project).iterateContentUnderDirectory(startDirectory) {
19
+ file ->
20
+ if (
21
+ ! file.isDirectory &&
22
+ (file.name == " project.json" || (includeNxJson && file.name == " nx.json" ))
23
+ ) {
24
+ paths.add(file)
33
25
}
34
- )
26
+ ProgressManager .checkCanceled()
27
+ return @iterateContentUnderDirectory true
28
+ }
35
29
}
36
30
}
37
31
return paths
Original file line number Diff line number Diff line change 23
23
"@parcel/watcher-linux-x64-glibc" : " 2.4.1" ,
24
24
"@parcel/watcher-linux-x64-musl" : " 2.4.1" ,
25
25
"@parcel/watcher-win32-arm64" : " 2.4.1" ,
26
- "@parcel/watcher-win32-x64" : " 2.4.1" ,
27
- "@nx/nx-darwin-arm64" : " 19.0.3" ,
28
- "@nx/nx-darwin-x64" : " 19.0.3" ,
29
- "@nx/nx-freebsd-x64" : " 19.0.3" ,
30
- "@nx/nx-linux-arm-gnueabihf" : " 19.0.3" ,
31
- "@nx/nx-linux-arm64-gnu" : " 19.0.3" ,
32
- "@nx/nx-linux-arm64-musl" : " 19.0.3" ,
33
- "@nx/nx-linux-x64-gnu" : " 19.0.3" ,
34
- "@nx/nx-linux-x64-musl" : " 19.0.3" ,
35
- "@nx/nx-win32-arm64-msvc" : " 19.0.3" ,
36
- "@nx/nx-win32-x64-msvc" : " 19.0.3"
26
+ "@parcel/watcher-win32-x64" : " 2.4.1"
37
27
}
38
28
}
Original file line number Diff line number Diff line change 53
53
"@parcel/watcher-linux-x64-musl" : " 2.4.1" ,
54
54
"@parcel/watcher-win32-arm64" : " 2.4.1" ,
55
55
"@parcel/watcher-win32-x64" : " 2.4.1" ,
56
- "@nx/nx-darwin-arm64" : " 19.0.3" ,
57
- "@nx/nx-darwin-x64" : " 19.0.3" ,
58
- "@nx/nx-freebsd-x64" : " 19.0.3" ,
59
- "@nx/nx-linux-arm-gnueabihf" : " 19.0.3" ,
60
- "@nx/nx-linux-arm64-gnu" : " 19.0.3" ,
61
- "@nx/nx-linux-arm64-musl" : " 19.0.3" ,
62
- "@nx/nx-linux-x64-gnu" : " 19.0.3" ,
63
- "@nx/nx-linux-x64-musl" : " 19.0.3" ,
64
- "@nx/nx-win32-arm64-msvc" : " 19.0.3" ,
65
- "@nx/nx-win32-x64-msvc" : " 19.0.3" ,
66
56
"@vscode-elements/elements" : " ^1.6.1"
67
57
},
68
58
"contributes" : {
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 @@ -94,7 +94,7 @@ export class DaemonWatcher {
94
94
if ( error === 'closed' ) {
95
95
if ( ! this . stopped ) {
96
96
lspLogger . log ( 'Daemon watcher connection closed, restarting' ) ;
97
- this . tryRestartWatcher ( ) ;
97
+ this . useNativeWatcher ( ) ;
98
98
}
99
99
} else if ( error ) {
100
100
lspLogger . log ( 'Error watching files: ' + error ) ;
@@ -142,24 +142,8 @@ export class DaemonWatcher {
142
142
lspLogger . log (
143
143
`Error initializing daemon watcher, check daemon logs. ${ e } `
144
144
) ;
145
- this . tryRestartWatcher ( ) ;
146
- }
147
- }
148
-
149
- private async tryRestartWatcher ( ) {
150
- this . disposeEverything ( ) ;
151
- if ( this . retryCount > 0 ) {
152
- lspLogger . log ( 'Daemon watcher failed to restart, using native watcher' ) ;
153
145
this . useNativeWatcher ( ) ;
154
- return ;
155
146
}
156
- this . retryCount ++ ;
157
- await new Promise ( ( resolve ) => {
158
- const timeout = setTimeout ( resolve , 100 ) ;
159
- this . disposables . add ( ( ) => clearTimeout ( timeout ) ) ;
160
- } ) ;
161
-
162
- await this . initWatcher ( ) ;
163
147
}
164
148
165
149
private useNativeWatcher ( ) {
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' ,
@@ -130,6 +140,7 @@ export function getDefaultBranch(workspacePath: string) {
130
140
'git symbolic-ref refs/remotes/origin/HEAD' ,
131
141
{
132
142
cwd : workspacePath ,
143
+ stdio : 'pipe' ,
133
144
}
134
145
)
135
146
. toString ( )
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ export class GoogleAnalyticsSender implements TelemetrySender {
41
41
getOutputChannel ( ) . appendLine ( `Uncaught Exception: ${ error } ` ) ;
42
42
43
43
const shouldLogToRollbar = this . production
44
- ? Math . floor ( Math . random ( ) * 75 ) === 0
44
+ ? Math . floor ( Math . random ( ) * 25 ) === 0
45
45
: true ;
46
46
if ( shouldLogToRollbar ) {
47
47
this . rollbar . error ( error ) ;
You can’t perform that action at this time.
0 commit comments