Skip to content

Commit

Permalink
fix: bump to core 3 (#42)
Browse files Browse the repository at this point in the history
* fix: bump to core 3

* chore: prepare is set to sf-install

* chore: prepare not prepack

* chore: bump to core 3.16.0

* chore: regenerate yarn.lock, use SfdxConfigAggregator
  • Loading branch information
WillieRuemmele authored May 6, 2022
1 parent 1bc3f39 commit 9ab8b09
Show file tree
Hide file tree
Showing 10 changed files with 1,336 additions and 2,109 deletions.
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn commitlint --edit
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint && yarn pretty-quick --staged
4 changes: 4 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn build && yarn test --forbid-only
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2018, Salesforce.com, Inc.
Copyright (c) 2022, Salesforce.com, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand Down
5 changes: 0 additions & 5 deletions messages/telemetry.js

This file was deleted.

36 changes: 19 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"format": "sf-format",
"lint": "sf-lint",
"lint-fix": "yarn sfdx-lint --fix",
"prepack": "sf-build",
"prepare": "npm run build",
"prepack": "sf-prepack",
"prepare": "sf-install",
"pretest": "sf-compile-test",
"test": "sf-test"
},
Expand All @@ -33,33 +33,35 @@
"!lib/**/*.map"
],
"dependencies": {
"@salesforce/core": "^2.31.0",
"@salesforce/ts-types": "^1.2.1",
"@salesforce/core": "^3.16.0",
"@salesforce/ts-types": "^1.5.20",
"applicationinsights": "^1.4.0",
"axios": "^0.27.2"
},
"devDependencies": {
"@salesforce/dev-config": "^2.0.0",
"@salesforce/dev-scripts": "^0.9.18",
"@salesforce/dev-config": "^3.0.1",
"@salesforce/dev-scripts": "^2.0.2",
"@salesforce/prettier-config": "^0.0.2",
"@salesforce/ts-sinon": "^1.1.0",
"@typescript-eslint/eslint-plugin": "^2.30.0",
"@typescript-eslint/parser": "^2.30.0",
"@typescript-eslint/eslint-plugin": "^4.2.0",
"@typescript-eslint/parser": "^4.2.0",
"chai": "^4.2.0",
"eslint": "^6.8.0",
"eslint": "^7.27.0",
"eslint-config-prettier": "^6.11.0",
"eslint-config-salesforce": "^0.1.0",
"eslint-config-salesforce-license": "^0.1.0",
"eslint-config-salesforce-typescript": "^0.1.0",
"eslint-config-salesforce": "^0.1.6",
"eslint-config-salesforce-license": "^0.1.6",
"eslint-config-salesforce-typescript": "^0.2.7",
"eslint-plugin-header": "^3.0.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jsdoc": "^27.0.3",
"eslint-plugin-import": "2.24.2",
"eslint-plugin-jsdoc": "^35.1.2",
"eslint-plugin-prettier": "^3.1.3",
"mocha": "^7.2.0",
"husky": "^7.0.4",
"mocha": "^9.1.3",
"nyc": "^15.1.0",
"prettier": "^2.0.5",
"sinon": "^9.0.2",
"ts-node": "^8.10.2",
"pretty-quick": "^3.1.0",
"sinon": "10.0.0",
"ts-node": "^10.0.0",
"typescript": "^4.1.3"
},
"types": "lib/exported.d.ts",
Expand Down
8 changes: 3 additions & 5 deletions src/appInsights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import * as os from 'os';
import { Logger, Messages } from '@salesforce/core';
import { Logger } from '@salesforce/core';
import { AsyncCreatable, Env } from '@salesforce/kit';
import { isBoolean, isNumber, isString, JsonPrimitive } from '@salesforce/ts-types';
import * as appInsights from 'applicationinsights';
Expand Down Expand Up @@ -36,8 +36,6 @@ export interface TelemetryOptions {
waitForConnection?: boolean;
}

Messages.importMessagesDirectory(__dirname);

export function getPlatformVersion(): string {
return (os.release() || '').replace(/^(\d+)(\.\d+)?(\.\d+)?(.*)/, '$1$2$3');
}
Expand Down Expand Up @@ -158,7 +156,7 @@ export class AppInsights extends AsyncCreatable<TelemetryOptions> {
/**
* Publishes diagnostic information to app insights dashboard
*
* @param message {string} - trace message to sen to app insights.
* @param traceMessage {string} - trace message to sen to app insights.
* @param properties {Properties} - map of properties to publish alongside the event.
*/
public sendTelemetryTrace(traceMessage: string, properties?: Properties): void {
Expand All @@ -169,7 +167,7 @@ export class AppInsights extends AsyncCreatable<TelemetryOptions> {
/**
* Publishes metric to app insights dashboard
*
* @param name {string} - name of the metric you want published
* @param metricName {string} - name of the metric you want published
* @param value {number} - value of the metric
* @param properties {Properties} - map of properties to publish alongside the event.
*/
Expand Down
23 changes: 11 additions & 12 deletions src/telemetryReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import * as os from 'os';
import { ConfigAggregator, Logger } from '@salesforce/core';
import { Logger, SfdxConfigAggregator } from '@salesforce/core';
import { AsyncCreatable, env } from '@salesforce/kit';

import axios from 'axios';
Expand All @@ -21,11 +21,11 @@ export { TelemetryOptions, Attributes, Properties, TelemetryClient } from './app
*/
export class TelemetryReporter extends AsyncCreatable<TelemetryOptions> {
// Keep a cache of config aggregator so we aren't loading it every time.
private static config: ConfigAggregator;
private static config: SfdxConfigAggregator;

private options: TelemetryOptions;
private logger!: Logger;
private config!: ConfigAggregator;
private config!: SfdxConfigAggregator;
private reporter!: AppInsights;

public constructor(options: TelemetryOptions) {
Expand All @@ -39,18 +39,17 @@ export class TelemetryReporter extends AsyncCreatable<TelemetryOptions> {
*/
public static async determineSfdxTelemetryEnabled(): Promise<boolean> {
if (!TelemetryReporter.config) {
TelemetryReporter.config = await ConfigAggregator.create({});
TelemetryReporter.config = await SfdxConfigAggregator.create({});
}
const configValue = TelemetryReporter.config.getPropertyValue(DISABLE_TELEMETRY);
const sfdxDisableInsights = configValue === 'true' || env.getBoolean('SFDX_DISABLE_INSIGHTS');
const isEnabled = !sfdxDisableInsights;
return isEnabled;
return !sfdxDisableInsights;
}

public async init(): Promise<void> {
this.logger = await Logger.child('TelemetryReporter');
if (!TelemetryReporter.config) {
TelemetryReporter.config = await ConfigAggregator.create({});
TelemetryReporter.config = await SfdxConfigAggregator.create({});
}
this.config = TelemetryReporter.config;
if (this.options.waitForConnection) await this.waitForConnection();
Expand Down Expand Up @@ -128,7 +127,7 @@ export class TelemetryReporter extends AsyncCreatable<TelemetryOptions> {
* Sends exception to child process.
*
* @param exception {Error} - exception you want published.
* @param measurements {Measurements} - map of measurements to publish alongside the event.
* @param attributes {Attributes} - map of measurements to publish alongside the event.
*/
public sendTelemetryException(exception: Error, attributes: Attributes = {}): void {
if (this.isSfdxTelemetryEnabled()) {
Expand All @@ -142,7 +141,7 @@ export class TelemetryReporter extends AsyncCreatable<TelemetryOptions> {
/**
* Publishes diagnostic information to app insights dashboard
*
* @param message {string} - trace message to sen to app insights.
* @param traceMessage {string} - trace message to sen to app insights.
* @param properties {Properties} - map of properties to publish alongside the event.
*/
public sendTelemetryTrace(traceMessage: string, properties?: Properties): void {
Expand All @@ -154,7 +153,7 @@ export class TelemetryReporter extends AsyncCreatable<TelemetryOptions> {
/**
* Publishes metric to app insights dashboard
*
* @param name {string} - name of the metric you want published
* @param metricName {string} - name of the metric you want published
* @param value {number} - value of the metric
* @param properties {Properties} - map of properties to publish alongside the event.
*/
Expand All @@ -171,8 +170,8 @@ export class TelemetryReporter extends AsyncCreatable<TelemetryOptions> {
public isSfdxTelemetryEnabled(): boolean {
const configValue = this.config.getPropertyValue(DISABLE_TELEMETRY);
const sfdxDisableInsights = configValue === 'true' || env.getBoolean('SFDX_DISABLE_INSIGHTS');
const isEnabled = !sfdxDisableInsights;
return isEnabled;
// isEnabled = !sfdxDisableInsights
return !sfdxDisableInsights;
}

public logTelemetryStatus(): void {
Expand Down
24 changes: 12 additions & 12 deletions test/unit/telemetryReporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { ConfigAggregator, Logger } from '@salesforce/core';
import { SfdxConfigAggregator, Logger } from '@salesforce/core';
import axios from 'axios';
import { expect } from 'chai';
import * as sinon from 'sinon';
Expand All @@ -29,7 +29,7 @@ describe('TelemetryReporter', () => {

it('should send a telemetry event', async () => {
const options = { project, key };
sandbox.stub(ConfigAggregator.prototype, 'getPropertyValue').returns('false');
sandbox.stub(SfdxConfigAggregator.prototype, 'getPropertyValue').returns('false');
const reporter = await TelemetryReporter.create(options);
const sendStub = sandbox.stub(reporter.getTelemetryClient(), 'trackEvent').callsFake(() => {});

Expand All @@ -39,7 +39,7 @@ describe('TelemetryReporter', () => {

it('should send a telemetry exception', async () => {
const options = { project, key };
sandbox.stub(ConfigAggregator.prototype, 'getPropertyValue').returns('false');
sandbox.stub(SfdxConfigAggregator.prototype, 'getPropertyValue').returns('false');
const reporter = await TelemetryReporter.create(options);
const sendStub = sandbox.stub(reporter.getTelemetryClient(), 'trackException').callsFake(() => {});

Expand All @@ -50,7 +50,7 @@ describe('TelemetryReporter', () => {

it('should send a telemetry trace', async () => {
const options = { project, key };
sandbox.stub(ConfigAggregator.prototype, 'getPropertyValue').returns('false');
sandbox.stub(SfdxConfigAggregator.prototype, 'getPropertyValue').returns('false');
const reporter = await TelemetryReporter.create(options);
const sendStub = sandbox.stub(reporter.getTelemetryClient(), 'trackTrace').callsFake(() => {});

Expand All @@ -60,7 +60,7 @@ describe('TelemetryReporter', () => {

it('should send a telemetry metric', async () => {
const options = { project, key };
sandbox.stub(ConfigAggregator.prototype, 'getPropertyValue').returns('false');
sandbox.stub(SfdxConfigAggregator.prototype, 'getPropertyValue').returns('false');
const reporter = await TelemetryReporter.create(options);
const sendStub = sandbox.stub(reporter.getTelemetryClient(), 'trackMetric').callsFake(() => {});

Expand All @@ -69,7 +69,7 @@ describe('TelemetryReporter', () => {
});

it('should not send a telemetry event when disabled', async () => {
sandbox.stub(ConfigAggregator.prototype, 'getPropertyValue').returns('true');
sandbox.stub(SfdxConfigAggregator.prototype, 'getPropertyValue').returns('true');
const options = { project, key };
const reporter = await TelemetryReporter.create(options);
const sendStub = sandbox.stub(reporter.getTelemetryClient(), 'trackEvent').callsFake(() => {});
Expand All @@ -79,7 +79,7 @@ describe('TelemetryReporter', () => {
});

it('should not send a telemetry exception when disabled', async () => {
sandbox.stub(ConfigAggregator.prototype, 'getPropertyValue').returns('true');
sandbox.stub(SfdxConfigAggregator.prototype, 'getPropertyValue').returns('true');
const options = { project, key };
const reporter = await TelemetryReporter.create(options);
const sendStub = sandbox.stub(reporter.getTelemetryClient(), 'trackException').callsFake(() => {});
Expand All @@ -89,7 +89,7 @@ describe('TelemetryReporter', () => {
});

it('should not send a telemetry trace when disabled', async () => {
sandbox.stub(ConfigAggregator.prototype, 'getPropertyValue').returns('true');
sandbox.stub(SfdxConfigAggregator.prototype, 'getPropertyValue').returns('true');
const options = { project, key };
const reporter = await TelemetryReporter.create(options);
const sendStub = sandbox.stub(reporter.getTelemetryClient(), 'trackTrace').callsFake(() => {});
Expand All @@ -99,7 +99,7 @@ describe('TelemetryReporter', () => {
});

it('should not send a telemetry metric when disabled', async () => {
sandbox.stub(ConfigAggregator.prototype, 'getPropertyValue').returns('true');
sandbox.stub(SfdxConfigAggregator.prototype, 'getPropertyValue').returns('true');
const options = { project, key };
const reporter = await TelemetryReporter.create(options);
const sendStub = sandbox.stub(reporter.getTelemetryClient(), 'trackMetric').callsFake(() => {});
Expand All @@ -109,7 +109,7 @@ describe('TelemetryReporter', () => {
});

it('should log to enable telemetry metric when disabled', async () => {
sandbox.stub(ConfigAggregator.prototype, 'getPropertyValue').returns('true');
sandbox.stub(SfdxConfigAggregator.prototype, 'getPropertyValue').returns('true');
const warn = sandbox.stub();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
sandbox.stub(Logger, 'child').resolves({ warn, debug: sandbox.stub() } as any);
Expand All @@ -123,7 +123,7 @@ describe('TelemetryReporter', () => {

it('should log to disable telemetry metric when enabled', async () => {
const warn = sandbox.stub();
sandbox.stub(ConfigAggregator.prototype, 'getPropertyValue').returns('false');
sandbox.stub(SfdxConfigAggregator.prototype, 'getPropertyValue').returns('false');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
sandbox.stub(Logger, 'child').resolves({ warn, debug: sandbox.stub() } as any);
const options = { project, key };
Expand All @@ -135,7 +135,7 @@ describe('TelemetryReporter', () => {
});

it('should cache config aggregator', async () => {
const stub = sandbox.stub(ConfigAggregator, 'create');
const stub = sandbox.stub(SfdxConfigAggregator, 'create');

// eslint-disable-next-line @typescript-eslint/no-explicit-any
stub.resolves({ getPropertyValue: () => false } as any);
Expand Down
Loading

0 comments on commit 9ab8b09

Please sign in to comment.