|
3 | 3 | // Licensed under the MIT License.
|
4 | 4 |
|
5 | 5 | import TelemetryReporter from '@vscode/extension-telemetry';
|
6 |
| - |
7 |
| -import * as path from 'path'; |
8 |
| -import * as fs from 'fs-extra'; |
| 6 | +import type * as vscodeTypes from 'vscode'; |
9 | 7 | import { DiagnosticCodes } from '../application/diagnostics/constants';
|
10 |
| -import { AppinsightsKey, EXTENSION_ROOT_DIR, isTestExecution, isUnitTestExecution } from '../common/constants'; |
| 8 | +import { AppinsightsKey, isTestExecution, isUnitTestExecution, PVSC_EXTENSION_ID } from '../common/constants'; |
11 | 9 | import type { TerminalShellType } from '../common/terminal/types';
|
12 | 10 | import { StopWatch } from '../common/utils/stopWatch';
|
13 | 11 | import { isPromise } from '../common/utils/async';
|
@@ -39,14 +37,20 @@ function isTelemetrySupported(): boolean {
|
39 | 37 | }
|
40 | 38 | }
|
41 | 39 |
|
| 40 | +// eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 41 | +let packageJSON: any; |
| 42 | + |
42 | 43 | /**
|
43 | 44 | * Checks if the telemetry is disabled
|
44 | 45 | * @returns {boolean}
|
45 | 46 | */
|
46 | 47 | export function isTelemetryDisabled(): boolean {
|
47 |
| - const packageJsonPath = path.join(EXTENSION_ROOT_DIR, 'package.json'); |
48 |
| - const packageJson = fs.readJSONSync(packageJsonPath); |
49 |
| - return !packageJson.enableTelemetry; |
| 48 | + if (!packageJSON) { |
| 49 | + const vscode = require('vscode') as typeof vscodeTypes; |
| 50 | + const pythonExtension = vscode.extensions.getExtension(PVSC_EXTENSION_ID)!; |
| 51 | + packageJSON = pythonExtension.packageJSON; |
| 52 | + } |
| 53 | + return !packageJSON.enableTelemetry; |
50 | 54 | }
|
51 | 55 |
|
52 | 56 | const sharedProperties: Record<string, unknown> = {};
|
|
0 commit comments