Skip to content

Commit 7ca0821

Browse files
committed
Merge branch 'master' into release
2 parents fbca91e + c7bc53d commit 7ca0821

File tree

9 files changed

+73
-58
lines changed

9 files changed

+73
-58
lines changed

apps/intellij/src/main/kotlin/dev/nx/console/utils/FindNxConfigurationFiles.kt

+11-17
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ package dev.nx.console.utils
33
import com.intellij.openapi.application.readAction
44
import com.intellij.openapi.progress.ProgressManager
55
import com.intellij.openapi.project.Project
6+
import com.intellij.openapi.roots.ProjectFileIndex
67
import com.intellij.openapi.vfs.LocalFileSystem
7-
import com.intellij.openapi.vfs.VfsUtilCore
88
import com.intellij.openapi.vfs.VirtualFile
9-
import com.intellij.openapi.vfs.VirtualFileVisitor
109

1110
suspend fun findNxConfigurationFiles(
1211
project: Project,
@@ -16,22 +15,17 @@ suspend fun findNxConfigurationFiles(
1615
readAction {
1716
val startDirectory = LocalFileSystem.getInstance().findFileByPath(project.nxBasePath)
1817
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)
3325
}
34-
)
26+
ProgressManager.checkCanceled()
27+
return@iterateContentUnderDirectory true
28+
}
3529
}
3630
}
3731
return paths

apps/nxls/package.json

+1-11
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@
2323
"@parcel/watcher-linux-x64-glibc": "2.4.1",
2424
"@parcel/watcher-linux-x64-musl": "2.4.1",
2525
"@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"
3727
}
3828
}

apps/vscode/package.json

-10
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,6 @@
5353
"@parcel/watcher-linux-x64-musl": "2.4.1",
5454
"@parcel/watcher-win32-arm64": "2.4.1",
5555
"@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",
6656
"@vscode-elements/elements": "^1.6.1"
6757
},
6858
"contributes": {

libs/language-server/utils/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export * from './lib/lsp-log';
88
export * from './lib/json-language-service';
99
export * from './lib/find-property';
1010
export * from './lib/executor';
11+
export * from './lib/nx-cloud';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
}

libs/language-server/watcher/src/lib/daemon-watcher.ts

+1-17
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class DaemonWatcher {
9494
if (error === 'closed') {
9595
if (!this.stopped) {
9696
lspLogger.log('Daemon watcher connection closed, restarting');
97-
this.tryRestartWatcher();
97+
this.useNativeWatcher();
9898
}
9999
} else if (error) {
100100
lspLogger.log('Error watching files: ' + error);
@@ -142,24 +142,8 @@ export class DaemonWatcher {
142142
lspLogger.log(
143143
`Error initializing daemon watcher, check daemon logs. ${e}`
144144
);
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');
153145
this.useNativeWatcher();
154-
return;
155146
}
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();
163147
}
164148

165149
private useNativeWatcher() {

libs/language-server/workspace/src/lib/get-cloud-onboarding-info.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { existsSync, readFileSync } from 'fs';
33
import * as os from 'node:os';
44
import { join } from 'path';
55

6-
import { lspLogger } from '@nx-console/language-server/utils';
6+
import { isNxCloudUsed, lspLogger } from '@nx-console/language-server/utils';
77
import {
88
getNxAccessToken,
99
getNxCloudId,
@@ -24,6 +24,16 @@ export async function getCloudOnboardingInfo(
2424
content.includes('nx affected')
2525
);
2626

27+
if (!(await isNxCloudUsed(workspacePath))) {
28+
return {
29+
hasNxInCI,
30+
hasAffectedCommandsInCI,
31+
isConnectedToCloud: false,
32+
isWorkspaceClaimed: false,
33+
personalAccessToken: undefined,
34+
};
35+
}
36+
2737
const accessToken = await getNxAccessToken(workspacePath);
2838
const nxCloudId = await getNxCloudId(workspacePath);
2939
const nxCloudUrl = await getNxCloudUrl(workspacePath);
@@ -185,6 +195,7 @@ async function getNxCloudWorkspaceClaimed(
185195
headers['Nx-Cloud-Personal-Access-Token'] = pat;
186196
}
187197

198+
lspLogger.log(`Making claimed request`);
188199
try {
189200
const response = await xhr({
190201
type: 'POST',

libs/language-server/workspace/src/lib/get-recent-cipe-data.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { lspLogger } from '@nx-console/language-server/utils';
1+
import { isNxCloudUsed, lspLogger } from '@nx-console/language-server/utils';
22
import {
33
getNxAccessToken,
44
getNxCloudId,
@@ -14,6 +14,15 @@ export async function getRecentCIPEData(workspacePath: string): Promise<{
1414
error?: CIPEInfoError;
1515
workspaceUrl?: string;
1616
}> {
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+
1726
const branches = getRecentlyCommittedGitBranches(workspacePath);
1827

1928
const nxCloudUrl = await getNxCloudUrl(workspacePath);
@@ -44,6 +53,7 @@ export async function getRecentCIPEData(workspacePath: string): Promise<{
4453
headers['Authorization'] = accessToken;
4554
}
4655

56+
lspLogger.log(`Making recent CIPE request`);
4757
try {
4858
const response = await xhr({
4959
type: 'POST',
@@ -130,6 +140,7 @@ export function getDefaultBranch(workspacePath: string) {
130140
'git symbolic-ref refs/remotes/origin/HEAD',
131141
{
132142
cwd: workspacePath,
143+
stdio: 'pipe',
133144
}
134145
)
135146
.toString()

libs/vscode/telemetry/src/lib/google-analytics-sender.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class GoogleAnalyticsSender implements TelemetrySender {
4141
getOutputChannel().appendLine(`Uncaught Exception: ${error}`);
4242

4343
const shouldLogToRollbar = this.production
44-
? Math.floor(Math.random() * 75) === 0
44+
? Math.floor(Math.random() * 25) === 0
4545
: true;
4646
if (shouldLogToRollbar) {
4747
this.rollbar.error(error);

0 commit comments

Comments
 (0)