Skip to content

Commit 9ab8b09

Browse files
fix: bump to core 3 (#42)
* 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
1 parent 1bc3f39 commit 9ab8b09

10 files changed

+1336
-2109
lines changed

.husky/commit-msg

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
yarn commitlint --edit

.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
yarn lint && yarn pretty-quick --staged

.husky/pre-push

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
yarn build && yarn test --forbid-only

LICENSE.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2018, Salesforce.com, Inc.
1+
Copyright (c) 2022, Salesforce.com, Inc.
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

messages/telemetry.js

-5
This file was deleted.

package.json

+19-17
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"format": "sf-format",
1616
"lint": "sf-lint",
1717
"lint-fix": "yarn sfdx-lint --fix",
18-
"prepack": "sf-build",
19-
"prepare": "npm run build",
18+
"prepack": "sf-prepack",
19+
"prepare": "sf-install",
2020
"pretest": "sf-compile-test",
2121
"test": "sf-test"
2222
},
@@ -33,33 +33,35 @@
3333
"!lib/**/*.map"
3434
],
3535
"dependencies": {
36-
"@salesforce/core": "^2.31.0",
37-
"@salesforce/ts-types": "^1.2.1",
36+
"@salesforce/core": "^3.16.0",
37+
"@salesforce/ts-types": "^1.5.20",
3838
"applicationinsights": "^1.4.0",
3939
"axios": "^0.27.2"
4040
},
4141
"devDependencies": {
42-
"@salesforce/dev-config": "^2.0.0",
43-
"@salesforce/dev-scripts": "^0.9.18",
42+
"@salesforce/dev-config": "^3.0.1",
43+
"@salesforce/dev-scripts": "^2.0.2",
4444
"@salesforce/prettier-config": "^0.0.2",
4545
"@salesforce/ts-sinon": "^1.1.0",
46-
"@typescript-eslint/eslint-plugin": "^2.30.0",
47-
"@typescript-eslint/parser": "^2.30.0",
46+
"@typescript-eslint/eslint-plugin": "^4.2.0",
47+
"@typescript-eslint/parser": "^4.2.0",
4848
"chai": "^4.2.0",
49-
"eslint": "^6.8.0",
49+
"eslint": "^7.27.0",
5050
"eslint-config-prettier": "^6.11.0",
51-
"eslint-config-salesforce": "^0.1.0",
52-
"eslint-config-salesforce-license": "^0.1.0",
53-
"eslint-config-salesforce-typescript": "^0.1.0",
51+
"eslint-config-salesforce": "^0.1.6",
52+
"eslint-config-salesforce-license": "^0.1.6",
53+
"eslint-config-salesforce-typescript": "^0.2.7",
5454
"eslint-plugin-header": "^3.0.0",
55-
"eslint-plugin-import": "^2.20.2",
56-
"eslint-plugin-jsdoc": "^27.0.3",
55+
"eslint-plugin-import": "2.24.2",
56+
"eslint-plugin-jsdoc": "^35.1.2",
5757
"eslint-plugin-prettier": "^3.1.3",
58-
"mocha": "^7.2.0",
58+
"husky": "^7.0.4",
59+
"mocha": "^9.1.3",
5960
"nyc": "^15.1.0",
6061
"prettier": "^2.0.5",
61-
"sinon": "^9.0.2",
62-
"ts-node": "^8.10.2",
62+
"pretty-quick": "^3.1.0",
63+
"sinon": "10.0.0",
64+
"ts-node": "^10.0.0",
6365
"typescript": "^4.1.3"
6466
},
6567
"types": "lib/exported.d.ts",

src/appInsights.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77
import * as os from 'os';
8-
import { Logger, Messages } from '@salesforce/core';
8+
import { Logger } from '@salesforce/core';
99
import { AsyncCreatable, Env } from '@salesforce/kit';
1010
import { isBoolean, isNumber, isString, JsonPrimitive } from '@salesforce/ts-types';
1111
import * as appInsights from 'applicationinsights';
@@ -36,8 +36,6 @@ export interface TelemetryOptions {
3636
waitForConnection?: boolean;
3737
}
3838

39-
Messages.importMessagesDirectory(__dirname);
40-
4139
export function getPlatformVersion(): string {
4240
return (os.release() || '').replace(/^(\d+)(\.\d+)?(\.\d+)?(.*)/, '$1$2$3');
4341
}
@@ -158,7 +156,7 @@ export class AppInsights extends AsyncCreatable<TelemetryOptions> {
158156
/**
159157
* Publishes diagnostic information to app insights dashboard
160158
*
161-
* @param message {string} - trace message to sen to app insights.
159+
* @param traceMessage {string} - trace message to sen to app insights.
162160
* @param properties {Properties} - map of properties to publish alongside the event.
163161
*/
164162
public sendTelemetryTrace(traceMessage: string, properties?: Properties): void {
@@ -169,7 +167,7 @@ export class AppInsights extends AsyncCreatable<TelemetryOptions> {
169167
/**
170168
* Publishes metric to app insights dashboard
171169
*
172-
* @param name {string} - name of the metric you want published
170+
* @param metricName {string} - name of the metric you want published
173171
* @param value {number} - value of the metric
174172
* @param properties {Properties} - map of properties to publish alongside the event.
175173
*/

src/telemetryReporter.ts

+11-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77
import * as os from 'os';
8-
import { ConfigAggregator, Logger } from '@salesforce/core';
8+
import { Logger, SfdxConfigAggregator } from '@salesforce/core';
99
import { AsyncCreatable, env } from '@salesforce/kit';
1010

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

2626
private options: TelemetryOptions;
2727
private logger!: Logger;
28-
private config!: ConfigAggregator;
28+
private config!: SfdxConfigAggregator;
2929
private reporter!: AppInsights;
3030

3131
public constructor(options: TelemetryOptions) {
@@ -39,18 +39,17 @@ export class TelemetryReporter extends AsyncCreatable<TelemetryOptions> {
3939
*/
4040
public static async determineSfdxTelemetryEnabled(): Promise<boolean> {
4141
if (!TelemetryReporter.config) {
42-
TelemetryReporter.config = await ConfigAggregator.create({});
42+
TelemetryReporter.config = await SfdxConfigAggregator.create({});
4343
}
4444
const configValue = TelemetryReporter.config.getPropertyValue(DISABLE_TELEMETRY);
4545
const sfdxDisableInsights = configValue === 'true' || env.getBoolean('SFDX_DISABLE_INSIGHTS');
46-
const isEnabled = !sfdxDisableInsights;
47-
return isEnabled;
46+
return !sfdxDisableInsights;
4847
}
4948

5049
public async init(): Promise<void> {
5150
this.logger = await Logger.child('TelemetryReporter');
5251
if (!TelemetryReporter.config) {
53-
TelemetryReporter.config = await ConfigAggregator.create({});
52+
TelemetryReporter.config = await SfdxConfigAggregator.create({});
5453
}
5554
this.config = TelemetryReporter.config;
5655
if (this.options.waitForConnection) await this.waitForConnection();
@@ -128,7 +127,7 @@ export class TelemetryReporter extends AsyncCreatable<TelemetryOptions> {
128127
* Sends exception to child process.
129128
*
130129
* @param exception {Error} - exception you want published.
131-
* @param measurements {Measurements} - map of measurements to publish alongside the event.
130+
* @param attributes {Attributes} - map of measurements to publish alongside the event.
132131
*/
133132
public sendTelemetryException(exception: Error, attributes: Attributes = {}): void {
134133
if (this.isSfdxTelemetryEnabled()) {
@@ -142,7 +141,7 @@ export class TelemetryReporter extends AsyncCreatable<TelemetryOptions> {
142141
/**
143142
* Publishes diagnostic information to app insights dashboard
144143
*
145-
* @param message {string} - trace message to sen to app insights.
144+
* @param traceMessage {string} - trace message to sen to app insights.
146145
* @param properties {Properties} - map of properties to publish alongside the event.
147146
*/
148147
public sendTelemetryTrace(traceMessage: string, properties?: Properties): void {
@@ -154,7 +153,7 @@ export class TelemetryReporter extends AsyncCreatable<TelemetryOptions> {
154153
/**
155154
* Publishes metric to app insights dashboard
156155
*
157-
* @param name {string} - name of the metric you want published
156+
* @param metricName {string} - name of the metric you want published
158157
* @param value {number} - value of the metric
159158
* @param properties {Properties} - map of properties to publish alongside the event.
160159
*/
@@ -171,8 +170,8 @@ export class TelemetryReporter extends AsyncCreatable<TelemetryOptions> {
171170
public isSfdxTelemetryEnabled(): boolean {
172171
const configValue = this.config.getPropertyValue(DISABLE_TELEMETRY);
173172
const sfdxDisableInsights = configValue === 'true' || env.getBoolean('SFDX_DISABLE_INSIGHTS');
174-
const isEnabled = !sfdxDisableInsights;
175-
return isEnabled;
173+
// isEnabled = !sfdxDisableInsights
174+
return !sfdxDisableInsights;
176175
}
177176

178177
public logTelemetryStatus(): void {

test/unit/telemetryReporter.test.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Licensed under the BSD 3-Clause license.
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
7-
import { ConfigAggregator, Logger } from '@salesforce/core';
7+
import { SfdxConfigAggregator, Logger } from '@salesforce/core';
88
import axios from 'axios';
99
import { expect } from 'chai';
1010
import * as sinon from 'sinon';
@@ -29,7 +29,7 @@ describe('TelemetryReporter', () => {
2929

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)