Skip to content

Commit 68f1c9b

Browse files
committed
Merge branch 'master' into release
2 parents 59e1ea7 + 36da921 commit 68f1c9b

File tree

13 files changed

+184
-154
lines changed

13 files changed

+184
-154
lines changed

apps/intellij/src/main/kotlin/dev/nx/console/nxls/NxlsProcess.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import com.intellij.lang.javascript.service.JSLanguageServiceUtil
77
import com.intellij.openapi.diagnostic.logger
88
import com.intellij.openapi.diagnostic.thisLogger
99
import com.intellij.openapi.project.Project
10-
import com.intellij.util.application
1110
import com.intellij.util.io.awaitExit
1211
import dev.nx.console.NxConsoleBundle
12+
import dev.nx.console.utils.isDevelopmentInstance
1313
import dev.nx.console.utils.nodeInterpreter
1414
import dev.nx.console.utils.nxBasePath
1515
import java.io.File
@@ -112,7 +112,7 @@ class NxlsProcess(private val project: Project, private val cs: CoroutineScope)
112112
logger.info("nxls found via ${lsp.path}")
113113
return GeneralCommandLine().apply {
114114
withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE)
115-
if (application.isInternal) {
115+
if (isDevelopmentInstance()) {
116116
withEnvironment("NODE_OPTIONS", "--inspect=6009 --enable-source-maps")
117117
}
118118
withCharset(Charsets.UTF_8)

apps/intellij/src/main/kotlin/dev/nx/console/telemetry/MeasurementProtocolTelemetryService.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import com.intellij.openapi.application.ApplicationInfo
55
import com.intellij.openapi.application.PermanentInstallationID
66
import com.intellij.openapi.diagnostic.logger
77
import com.intellij.openapi.util.SystemInfo
8-
import com.intellij.util.application
98
import dev.nx.console.settings.NxConsoleSettingsProvider
9+
import dev.nx.console.utils.isDevelopmentInstance
1010
import io.ktor.client.*
1111
import io.ktor.client.call.*
1212
import io.ktor.client.request.*
@@ -18,6 +18,7 @@ val SESSION_ID = UUID.randomUUID().toString()
1818
private val logger = logger<MeasurementProtocolService>()
1919

2020
class MeasurementProtocolService(private val client: HttpClient) : Telemetry {
21+
private val isDevelopmentInstance = isDevelopmentInstance()
2122

2223
override suspend fun featureUsed(feature: String, data: Map<String, Any>?) {
2324
val payload = this.buildPayload(feature, data)
@@ -68,7 +69,7 @@ class MeasurementProtocolService(private val client: HttpClient) : Telemetry {
6869
put(
6970
"value",
7071
PluginManager.getPluginByClass(TelemetryService::class.java)?.version
71-
?: "0.0.0"
72+
?: "0.0.0",
7273
)
7374
}
7475
}
@@ -78,7 +79,7 @@ class MeasurementProtocolService(private val client: HttpClient) : Telemetry {
7879
putJsonObject("params") {
7980
put("engagement_time_msec", "1")
8081
put("session_id", SESSION_ID)
81-
put("debug_mode", if (application.isInternal) 1 else null)
82+
put("debug_mode", if (isDevelopmentInstance) 1 else null)
8283

8384
put("action_type", eventName)
8485

apps/intellij/src/main/kotlin/dev/nx/console/telemetry/TelemetryService.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package dev.nx.console.telemetry
33
import com.intellij.openapi.components.Service
44
import com.intellij.openapi.diagnostic.logger
55
import com.intellij.openapi.project.Project
6-
import com.intellij.util.application
6+
import dev.nx.console.utils.isDevelopmentInstance
77
import io.ktor.client.*
88
import io.ktor.client.engine.cio.*
99
import io.ktor.client.plugins.logging.*
@@ -16,6 +16,7 @@ interface Telemetry {
1616

1717
@Service(Service.Level.PROJECT)
1818
class TelemetryService(private val cs: CoroutineScope) {
19+
private val isDevelopmentInstance = isDevelopmentInstance()
1920
val logger = logger<TelemetryService>()
2021

2122
companion object {
@@ -24,7 +25,7 @@ class TelemetryService(private val cs: CoroutineScope) {
2425
}
2526

2627
private val service: Telemetry =
27-
if (application.isInternal) {
28+
if (isDevelopmentInstance) {
2829
LoggerTelemetryService()
2930
} else {
3031
MeasurementProtocolService(
@@ -48,7 +49,7 @@ class TelemetryService(private val cs: CoroutineScope) {
4849
source != null &&
4950
source is String &&
5051
TelemetryEventSource.isValidSource(source) &&
51-
application.isInternal
52+
isDevelopmentInstance
5253
) {
5354
logger.error("source has to be of type TelemetryEventSource")
5455
return
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package dev.nx.console.utils
2+
3+
import com.intellij.openapi.application.PathManager
4+
5+
fun isDevelopmentInstance(): Boolean {
6+
val configPath = PathManager.getConfigPath()
7+
8+
return configPath.contains("idea-sandbox")
9+
}

apps/nxls-e2e/src/pdv-data/pdv-data-default.test.ts

+29
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { NxlsWrapper } from '../nxls-wrapper';
99
import {
1010
defaultVersion,
1111
e2eCwd,
12+
modifyJsonFile,
1213
newWorkspace,
1314
simpleReactWorkspaceOptions,
1415
uniq,
@@ -61,6 +62,34 @@ describe('pdv data', () => {
6162
);
6263
});
6364

65+
it('should contain disabledTaskSyncGenerators if set in nx.json', async () => {
66+
await waitFor(1000);
67+
68+
const nxJsonPath = join(e2eCwd, workspaceName, 'nx.json');
69+
modifyJsonFile(nxJsonPath, (json) => {
70+
json.sync ??= {};
71+
json.sync.disabledTaskSyncGenerators = ['@nx/foo:bar'];
72+
return json;
73+
});
74+
75+
await nxlsWrapper.waitForNotification(
76+
NxWorkspaceRefreshNotification.method
77+
);
78+
79+
const pdvData = (
80+
await nxlsWrapper.sendRequest({
81+
...NxPDVDataRequest,
82+
params: {
83+
filePath: join(e2eCwd, workspaceName, 'project.json'),
84+
},
85+
})
86+
).result as PDVData;
87+
88+
expect(pdvData.pdvDataSerialized).toContain(
89+
'"disabledTaskSyncGenerators":["@nx/foo:bar"]'
90+
);
91+
});
92+
6493
it('should contain pdv data & error for partial errors', async () => {
6594
await waitFor(1000);
6695
viteFileContents = readFileSync(viteFilePath, 'utf-8');

apps/vscode/src/nx-init.ts

+30-21
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,36 @@ import {
1111

1212
export function initNxInit(context: ExtensionContext) {
1313
context.subscriptions.push(
14-
commands.registerCommand('nx.init', async () => {
15-
getTelemetry().logUsage('cli.init');
16-
const workspacePath =
17-
workspace.workspaceFolders && workspace.workspaceFolders[0].uri.fsPath;
18-
const command = 'nx@latest init';
19-
const task = new Task(
20-
{ type: 'nx' }, // definition
21-
TaskScope.Workspace, // scope
22-
command, // name
23-
'nx',
24-
// execution
25-
new ShellExecution(`npx ${command}`, {
26-
cwd: workspacePath,
27-
env: {
28-
NX_CONSOLE: 'true',
29-
},
30-
})
31-
);
32-
task.presentationOptions.focus = true;
14+
commands.registerCommand(
15+
'nx.init',
16+
async (triggeredFromAngularMigrate?: boolean) => {
17+
getTelemetry().logUsage('cli.init', {
18+
source:
19+
triggeredFromAngularMigrate === true
20+
? 'migrate-angular-prompt'
21+
: undefined,
22+
});
23+
const workspacePath =
24+
workspace.workspaceFolders &&
25+
workspace.workspaceFolders[0].uri.fsPath;
26+
const command = 'nx@latest init';
27+
const task = new Task(
28+
{ type: 'nx' }, // definition
29+
TaskScope.Workspace, // scope
30+
command, // name
31+
'nx',
32+
// execution
33+
new ShellExecution(`npx ${command}`, {
34+
cwd: workspacePath,
35+
env: {
36+
NX_CONSOLE: 'true',
37+
},
38+
})
39+
);
40+
task.presentationOptions.focus = true;
3341

34-
tasks.executeTask(task);
35-
})
42+
tasks.executeTask(task);
43+
}
44+
)
3645
);
3746
}

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

+24-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
import { workspaceDependencyPath } from '@nx-console/shared/npm';
2-
import { nxWorkspace } from './workspace';
3-
import { getProjectByPath } from './get-project-by-path';
4-
import { getNxVersion } from './get-nx-version';
1+
import { directoryExists } from '@nx-console/shared/file-system';
2+
import { readNxJson, workspaceDependencyPath } from '@nx-console/shared/npm';
3+
import { PDVData } from '@nx-console/shared/types';
54
import type {
65
ProjectConfiguration,
76
ProjectGraphProjectNode,
87
} from 'nx/src/devkit-exports';
9-
import { PDVData } from '@nx-console/shared/types';
108
import { join, relative } from 'path';
11-
import { directoryExists } from '@nx-console/shared/file-system';
12-
import { getSourceMapFilesToProjectsMap } from './get-source-map';
13-
import { lspLogger } from '@nx-console/language-server/utils';
14-
import { getNxCloudStatus } from './get-nx-cloud-status';
159
import { gte } from 'semver';
10+
import { getNxCloudStatus } from './get-nx-cloud-status';
11+
import { getNxVersion } from './get-nx-version';
12+
import { getProjectByPath } from './get-project-by-path';
13+
import { getSourceMapFilesToProjectsMap } from './get-source-map';
14+
import { nxWorkspace } from './workspace';
1615

1716
export async function getPDVData(
1817
workspacePath: string,
@@ -70,6 +69,9 @@ export async function getPDVData(
7069
const projectRootsForConfigFile = sourceMapsFilesToProjectsMap[relativePath];
7170

7271
const nxCloudStatus = await getNxCloudStatus(workspacePath);
72+
const disabledTaskSyncGenerators = await getDisabledTaskSyncGenerators(
73+
workspacePath
74+
);
7375

7476
if (!projectRootsForConfigFile || projectRootsForConfigFile.length <= 1) {
7577
const project = await getProjectByPath(filePath, workspacePath);
@@ -95,6 +97,7 @@ export async function getPDVData(
9597
sourceMap: workspace.workspace.sourceMaps?.[project.root],
9698
errors: workspace.errors,
9799
connectedToCloud: nxCloudStatus.isConnected,
100+
disabledTaskSyncGenerators,
98101
}),
99102
pdvDataSerializedMulti: undefined,
100103
errorsSerialized: undefined,
@@ -118,6 +121,7 @@ export async function getPDVData(
118121
sourceMap: workspace.workspace.sourceMaps?.[project.data.root],
119122
errors: workspace.errors,
120123
connectedToCloud: nxCloudStatus.isConnected,
124+
disabledTaskSyncGenerators,
121125
});
122126
}
123127

@@ -170,3 +174,14 @@ function isCompleteProjectConfiguration(
170174
): project is ProjectConfiguration & { name: string } {
171175
return !!project && !!project.name;
172176
}
177+
178+
async function getDisabledTaskSyncGenerators(
179+
workspacePath: string
180+
): Promise<string[] | undefined> {
181+
try {
182+
const nxJson = await readNxJson(workspacePath);
183+
return nxJson.sync?.disabledTaskSyncGenerators;
184+
} catch (e) {
185+
return undefined;
186+
}
187+
}

libs/vscode/nx-conversion/src/lib/vscode-nx-conversion.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { WorkspaceConfigurationStore } from '@nx-console/vscode/configuration';
2-
import { EXECUTE_ARBITRARY_COMMAND } from '@nx-console/vscode/nx-commands-view';
3-
import { getTelemetry } from '@nx-console/vscode/telemetry';
42
import { commands, ExtensionContext, window } from 'vscode';
53

64
let run = false;
@@ -34,10 +32,7 @@ export async function initNxConversion(
3432
const command = commands.registerCommand(
3533
'nxConsole.migrateAngularCliToNx',
3634
() => {
37-
getTelemetry().logUsage('cli.init', {
38-
source: 'migrate-angular-prompt',
39-
});
40-
commands.executeCommand(EXECUTE_ARBITRARY_COMMAND, 'nx init');
35+
commands.executeCommand('nx.init', true);
4136
}
4237
);
4338
context.subscriptions.push(command);
@@ -53,7 +48,7 @@ export async function initNxConversion(
5348
'Learn More'
5449
);
5550
if (answer === 'Migrate Now') {
56-
commands.executeCommand(EXECUTE_ARBITRARY_COMMAND, 'nx init');
51+
commands.executeCommand('nxConsole.migrateAngularCliToNx');
5752
return;
5853
}
5954
if (answer === 'Learn More') {

0 commit comments

Comments
 (0)