Skip to content

Commit

Permalink
feat(perf): remove vcs check, defer-app-insights
Browse files Browse the repository at this point in the history
* feat: remove vcs check

* feat(perf): defer-app-insights (#497)

* chore: use node16 modules for pjson exports

* chore: type only import

* feat: use standalone method

* perf: use standalone enabled check

* feat: dynamic import to defer require of appInsights

* test: config and stub change

* ci: use library pre-rel

* chore(release): 2.2.7-qa.0 [skip ci]

* chore: update to released telemetry lib

---------

Co-authored-by: svc-cli-bot <[email protected]>

---------

Co-authored-by: svc-cli-bot <[email protected]>
  • Loading branch information
mshanemc and svc-cli-bot authored Aug 14, 2023
1 parent a68ddd6 commit 6772427
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 268 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "@salesforce/plugin-telemetry",
"description": "Command usage and error telemetry for the Salesforce CLI",
"version": "2.2.6",
"version": "2.2.7-qa.0",
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^2.11.7",
"@salesforce/core": "^5.2.0",
"@salesforce/sf-plugins-core": "^3.1.14",
"@salesforce/telemetry": "^4.0.16",
"@salesforce/telemetry": "^4.1.0",
"debug": "^4.3.4",
"tslib": "^2"
},
Expand All @@ -33,11 +33,11 @@
"eslint-config-salesforce-typescript": "^1.1.2",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-jsdoc": "^43.0.5",
"eslint-plugin-jsdoc": "^46.4.6",
"husky": "^7.0.4",
"mocha": "^9.1.3",
"nyc": "^15.1.0",
"oclif": "^3.9.0",
"oclif": "^3.11.3",
"prettier": "^2.8.8",
"pretty-quick": "^3.1.0",
"shx": "0.3.4",
Expand Down
28 changes: 3 additions & 25 deletions src/commandExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { join } from 'path';
import * as fs from 'fs';
import { Config, Command, Parser } from '@oclif/core';
import { FlagInput } from '@oclif/core/lib/interfaces/parser';
import { Org, SfProject } from '@salesforce/core';
import { Org } from '@salesforce/core';
import { AsyncCreatable } from '@salesforce/kit';
import { isNumber, JsonMap, Optional } from '@salesforce/ts-types';
import { debug } from './debugger';
Expand All @@ -34,7 +32,6 @@ export class CommandExecution extends AsyncCreatable {
private command: Partial<Command.Class>;
private readonly argv: string[];
private config: Partial<Config>;
private vcs?: string;

private orgId?: string | null;
private devhubId?: string | null;
Expand All @@ -50,26 +47,10 @@ export class CommandExecution extends AsyncCreatable {
}

/**
* Determines whether the SFDX project is using GIT for version control or some other VCS.
* Returns a token indicating the VCS for usage stats, or an empty string if the command
* was executed outside of an SFDX project.
* @deprecated. Will always return en empty string.
*/
public static async resolveVCSInfo(): Promise<string> {
let possibleVcsPath: string;
try {
possibleVcsPath = await SfProject.resolveProjectPath();
} catch (err) {
debug('Not in a sfdx project, using current working directory');
possibleVcsPath = process.cwd();
}

const gitPath = join(possibleVcsPath, '.git');
try {
await fs.promises.access(gitPath, fs.constants.R_OK);
return 'git';
} catch (err) {
return 'other';
}
return Promise.resolve('');
}

public toJson(): JsonMap {
Expand All @@ -81,7 +62,6 @@ export class CommandExecution extends AsyncCreatable {
platform: this.config.platform,
shell: this.config.shell,
arch: this.config.arch,
vcs: this.vcs,
nodeEnv: process.env.NODE_ENV,
nodeVersion: process.version,
processUptime: process.uptime() * 1000,
Expand Down Expand Up @@ -176,8 +156,6 @@ export class CommandExecution extends AsyncCreatable {
? (flags['target-dev-hub'] as unknown as Org).getConnection().getApiVersion()
: null;
this.determineSpecifiedFlags(argv, flags, flagDefinitions);

this.vcs = await CommandExecution.resolveVCSInfo();
}

private determineSpecifiedFlags(argv: string[], flags: FlagInput, flagDefinitions: FlagInput): void {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { SfCommand } from '@salesforce/sf-plugins-core';
import TelemetryReporter from '@salesforce/telemetry';
import { isEnabled } from '@salesforce/telemetry/enabledCheck';
import Telemetry from '../telemetry';
import { TelemetryGlobal } from '../telemetryGlobal';

Expand All @@ -23,7 +23,7 @@ export default class TelemetryGet extends SfCommand<TelemetryGetResult> {
public static hidden = true;

public async run(): Promise<TelemetryGetResult> {
const enabled = await TelemetryReporter.determineSfdxTelemetryEnabled();
const enabled = await isEnabled();
const cliId = global.cliTelemetry?.getCLIId();

this.log(`Telemetry is ${enabled ? 'enabled' : 'disabled'}.`);
Expand Down
5 changes: 2 additions & 3 deletions src/hooks/telemetryPrerun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { join } from 'path';
import { Hook, Performance } from '@oclif/core';
import { SfError, Lifecycle } from '@salesforce/core';
import { JsonMap } from '@salesforce/ts-types';
import { TelemetryReporter } from '@salesforce/telemetry';
import { isEnabled } from '@salesforce/telemetry/enabledCheck';
import Telemetry from '../telemetry';
import { TelemetryGlobal } from '../telemetryGlobal';
import { CommandExecution } from '../commandExecution';
Expand All @@ -31,9 +31,8 @@ type CommonData = {
* 3. Logs command usage data to the server right after the process ends by spawning a detached process.
*/
const hook: Hook.Prerun = async function (options): Promise<void> {
const telemetryEnabled = await TelemetryReporter.determineSfdxTelemetryEnabled();
// Don't even bother logging if telemetry is disabled
if (!telemetryEnabled) {
if (!(await isEnabled())) {
debug('Telemetry disabled. Doing nothing.');
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { randomBytes } from 'crypto';
import * as fs from 'fs';
import { EOL, tmpdir } from 'os';
import { join } from 'path';
import { Attributes } from '@salesforce/telemetry';
import type { Attributes } from '@salesforce/telemetry';
import { AsyncCreatable, env } from '@salesforce/kit';
import { SfError } from '@salesforce/core';
import { isBoolean, isNumber, isString, JsonMap } from '@salesforce/ts-types';
Expand Down
4 changes: 2 additions & 2 deletions src/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

/* eslint-disable no-await-in-loop */
import { SfError } from '@salesforce/core';
import TelemetryReporter from '@salesforce/telemetry';
import { asString, Dictionary } from '@salesforce/ts-types';
import Telemetry from './telemetry';
import { debug, version } from './debugger';
Expand Down Expand Up @@ -35,7 +34,8 @@ export class Uploader {
* Reads the telemetry events from file and sends them to the telemetry service.
*/
private async sendToTelemetry(): Promise<void> {
let reporter: TelemetryReporter;
const { TelemetryReporter } = await import('@salesforce/telemetry');
let reporter: InstanceType<typeof TelemetryReporter>;
try {
reporter = await TelemetryReporter.create({
project: PROJECT,
Expand Down
1 change: 0 additions & 1 deletion test/commandExecution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ describe('toJson', () => {
const sandbox = createSandbox();

beforeEach(() => {
stubMethod(sandbox, CommandExecution, 'resolveVCSInfo').returns('git');
stubMethod(sandbox, Performance, 'highlights').get(() => ({
runTime: 0,
initTime: 0,
Expand Down
4 changes: 2 additions & 2 deletions test/hooks/telemetryPrerun.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { Hook, Config } from '@oclif/core';

import TelemetryReporter from '@salesforce/telemetry';
import * as enabledCheckStubs from '@salesforce/telemetry/enabledCheck';
import { StubbedType, stubInterface, stubMethod } from '@salesforce/ts-sinon';
import { expect } from 'chai';
import * as sinon from 'sinon';
Expand All @@ -33,7 +33,7 @@ describe('telemetry prerun hook', () => {

beforeEach(() => {
sandbox = sinon.createSandbox();
determineSfdxTelemetryEnabledStub = stubMethod(sandbox, TelemetryReporter, 'determineSfdxTelemetryEnabled');
determineSfdxTelemetryEnabledStub = stubMethod(sandbox, enabledCheckStubs, 'isEnabled');
recordStub = sandbox.stub();
recordErrorStub = sandbox.stub();
uploadStub = sandbox.stub();
Expand Down
3 changes: 2 additions & 1 deletion test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "@salesforce/dev-config/tsconfig-test-strict",
"include": ["./**/*.ts"],
"compilerOptions": {
"skipLibCheck": true
"skipLibCheck": true,
"moduleResolution": "node16"
}
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"compilerOptions": {
"outDir": "lib",
"rootDir": "src",
"skipLibCheck": true
"skipLibCheck": true,
"moduleResolution": "node16"
},
"include": ["./src/**/*.ts"]
}
Loading

0 comments on commit 6772427

Please sign in to comment.