Skip to content

Commit 56a29e5

Browse files
SF-CLI-BOTmshanemccristiand391
authored
refactor: devScripts update (#442)
* chore: updates from devScripts * refactor: dev-scripts linter and TS latest Co-authored-by: mshanemc <[email protected]> Co-authored-by: Cristian Dominguez <[email protected]>
1 parent 4d7c635 commit 56a29e5

File tree

18 files changed

+558
-832
lines changed

18 files changed

+558
-832
lines changed

.github/workflows/notify-slack-on-pr-open.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ jobs:
88
build:
99
runs-on: ubuntu-latest
1010
steps:
11-
- name: Notify Slack on PR open
12-
env:
13-
WEBHOOK_URL : ${{ secrets.CLI_TEAM_SLACK_WEBHOOK_URL }}
14-
PULL_REQUEST_AUTHOR_ICON_URL : ${{ github.event.pull_request.user.avatar_url }}
15-
PULL_REQUEST_AUTHOR_NAME : ${{ github.event.pull_request.user.login }}
16-
PULL_REQUEST_AUTHOR_PROFILE_URL: ${{ github.event.pull_request.user.html_url }}
17-
PULL_REQUEST_BASE_BRANCH_NAME : ${{ github.event.pull_request.base.ref }}
18-
PULL_REQUEST_COMPARE_BRANCH_NAME : ${{ github.event.pull_request.head.ref }}
19-
PULL_REQUEST_NUMBER : ${{ github.event.pull_request.number }}
20-
PULL_REQUEST_REPO: ${{ github.event.pull_request.head.repo.name }}
21-
PULL_REQUEST_TITLE : ${{ github.event.pull_request.title }}
22-
PULL_REQUEST_URL : ${{ github.event.pull_request.html_url }}
23-
uses: salesforcecli/github-workflows/.github/actions/prNotification@main
11+
- name: Notify Slack on PR open
12+
env:
13+
WEBHOOK_URL: ${{ secrets.CLI_TEAM_SLACK_WEBHOOK_URL }}
14+
PULL_REQUEST_AUTHOR_ICON_URL: ${{ github.event.pull_request.user.avatar_url }}
15+
PULL_REQUEST_AUTHOR_NAME: ${{ github.event.pull_request.user.login }}
16+
PULL_REQUEST_AUTHOR_PROFILE_URL: ${{ github.event.pull_request.user.html_url }}
17+
PULL_REQUEST_BASE_BRANCH_NAME: ${{ github.event.pull_request.base.ref }}
18+
PULL_REQUEST_COMPARE_BRANCH_NAME: ${{ github.event.pull_request.head.ref }}
19+
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }}
20+
PULL_REQUEST_REPO: ${{ github.event.pull_request.head.repo.name }}
21+
PULL_REQUEST_TITLE: ${{ github.event.pull_request.title }}
22+
PULL_REQUEST_URL: ${{ github.event.pull_request.html_url }}
23+
uses: salesforcecli/github-workflows/.github/actions/prNotification@main

package.json

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,43 +18,37 @@
1818
"@oclif/test": "^2.2.3",
1919
"@salesforce/cli-plugins-testkit": "^3.2.1",
2020
"@salesforce/dev-config": "^3.1.0",
21-
"@salesforce/dev-scripts": "^2.0.4",
22-
"@salesforce/plugin-command-reference": "^1.4.3",
21+
"@salesforce/dev-scripts": "^3.1.0",
22+
"@salesforce/plugin-command-reference": "^1.3.0",
2323
"@salesforce/prettier-config": "^0.0.2",
2424
"@salesforce/ts-sinon": "1.4.0",
25+
"@types/chai-as-promised": "^7.1.5",
2526
"@types/shelljs": "^0.8.10",
26-
"@typescript-eslint/eslint-plugin": "^4.33.0",
27-
"@typescript-eslint/parser": "^4.33.0",
27+
"@typescript-eslint/eslint-plugin": "^5.33.0",
28+
"@typescript-eslint/parser": "^5.33.0",
2829
"chai": "^4.2.0",
2930
"chai-as-promised": "^7.1.1",
30-
"cz-conventional-changelog": "^3.2.0",
31-
"eslint": "^7.27.0",
32-
"eslint-config-prettier": "^8.3.0",
33-
"eslint-config-salesforce": "^0.1.6",
31+
"eslint": "^8.21.0",
32+
"eslint-config-prettier": "^8.5.0",
33+
"eslint-config-salesforce": "^1.1.0",
3434
"eslint-config-salesforce-license": "^0.1.6",
35-
"eslint-config-salesforce-typescript": "^0.2.8",
35+
"eslint-config-salesforce-typescript": "^1.1.1",
3636
"eslint-plugin-header": "^3.0.0",
3737
"eslint-plugin-import": "2.26.0",
38-
"eslint-plugin-jsdoc": "^35.1.2",
39-
"eslint-plugin-prettier": "^3.1.3",
38+
"eslint-plugin-jsdoc": "^39.3.6",
4039
"husky": "^7.0.4",
4140
"mocha": "^9.1.3",
4241
"moment": "^2.29.1",
4342
"nyc": "^15.1.0",
44-
"oclif": "^3.2.15",
45-
"prettier": "^2.4.1",
43+
"oclif": "^3.2.12",
44+
"prettier": "^2.7.1",
4645
"pretty-quick": "^3.1.0",
4746
"shelljs": "^0.8.5",
4847
"shx": "0.3.4",
4948
"sinon": "10.0.0",
5049
"ts-node": "^10.9.1",
5150
"typescript": "^4.8.4"
5251
},
53-
"config": {
54-
"commitizen": {
55-
"path": "cz-conventional-changelog"
56-
}
57-
},
5852
"engines": {
5953
"node": ">=14.0.0"
6054
},
@@ -118,4 +112,4 @@
118112
"publishConfig": {
119113
"access": "public"
120114
}
121-
}
115+
}

src/commands/force/org/clone.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import {
2222
ResultEvent,
2323
SandboxProcessObject,
2424
} from '@salesforce/core';
25-
import { Duration, upperFirst } from '@salesforce/kit';
25+
import { Duration } from '@salesforce/kit';
26+
import { lowerToUpper } from '../../../shared/utils';
2627
import { SandboxReporter } from '../../../shared/sandboxReporter';
2728

2829
Messages.importMessagesDirectory(__dirname);
@@ -90,7 +91,7 @@ export class OrgCloneCommand extends SfdxCommand {
9091
if (results?.sandboxRes?.authUserName) {
9192
if (this.flags.setalias) {
9293
const stateAggregator = await StateAggregator.getInstance();
93-
stateAggregator.aliases.set(this.flags.setalias, results.sandboxRes.authUserName);
94+
stateAggregator.aliases.set(this.flags.setalias as string, results.sandboxRes.authUserName);
9495
const result = stateAggregator.aliases.getAll();
9596
this.logger.debug('Set Alias: %s result: %s', this.flags.setalias, result);
9697
}
@@ -123,10 +124,10 @@ export class OrgCloneCommand extends SfdxCommand {
123124
let capitalizedVarArgs = {};
124125

125126
if (sandboxDefFileContents) {
126-
sandboxDefFileContents = this.lowerToUpper(sandboxDefFileContents);
127+
sandboxDefFileContents = lowerToUpper(sandboxDefFileContents);
127128
}
128129
if (this.varargs) {
129-
capitalizedVarArgs = this.lowerToUpper(this.varargs);
130+
capitalizedVarArgs = lowerToUpper(this.varargs);
130131
}
131132

132133
// varargs override file input
@@ -152,17 +153,11 @@ export class OrgCloneCommand extends SfdxCommand {
152153
return { sandboxReq, srcSandboxName };
153154
}
154155

155-
private lowerToUpper(object: Record<string, unknown>): Record<string, unknown> {
156-
// the API has keys defined in capital camel case, while the definition schema has them as lower camel case
157-
// we need to convert lower camel case to upper before merging options so they will override properly
158-
return Object.fromEntries(Object.entries(object).map(([key, value]) => [upperFirst(key), value]));
159-
}
160-
161156
private readJsonDefFile(): Record<string, unknown> {
162157
// the -f option
163158
if (this.flags.definitionfile) {
164159
this.logger.debug('Reading JSON DefFile %s ', this.flags.definitionfile);
165-
return JSON.parse(fs.readFileSync(this.flags.definitionfile, 'utf-8')) as Record<string, unknown>;
160+
return JSON.parse(fs.readFileSync(this.flags.definitionfile as string, 'utf-8')) as Record<string, unknown>;
166161
}
167162
}
168163
}

src/commands/force/org/create.ts

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
ScratchOrgInfo,
2929
ScratchOrgRequest,
3030
} from '@salesforce/core';
31+
import { lowerToUpper } from '../../../shared/utils';
3132
import { SandboxReporter } from '../../../shared/sandboxReporter';
3233

3334
Messages.importMessagesDirectory(__dirname);
@@ -122,43 +123,29 @@ export class Create extends SfdxCommand {
122123
}
123124

124125
if (this.flags.clientid) {
125-
this.ux.warn(messages.getMessage('clientIdNotSupported', [this.flags.clientid]));
126+
this.ux.warn(messages.getMessage('clientIdNotSupported', [this.flags.clientid as string]));
126127
}
127128
if (this.flags.nonamespace) {
128-
this.ux.warn(messages.getMessage('noNamespaceNotSupported', [this.flags.nonamespace]));
129+
this.ux.warn(messages.getMessage('noNamespaceNotSupported', [this.flags.nonamespace as boolean]));
129130
}
130131
if (this.flags.noancestors) {
131-
this.ux.warn(messages.getMessage('noAncestorsNotSupported', [this.flags.noancestors]));
132+
this.ux.warn(messages.getMessage('noAncestorsNotSupported', [this.flags.noancestors as boolean]));
132133
}
133134
if (this.flags.durationdays) {
134-
this.ux.warn(messages.getMessage('durationDaysNotSupported', [this.flags.durationdays]));
135+
this.ux.warn(messages.getMessage('durationDaysNotSupported', [this.flags.durationdays as number]));
135136
}
136137
}
137138

138-
private lowerToUpper(object: Record<string, unknown>): Record<string, unknown> {
139-
// the API has keys defined in capital camel case, while the definition schema has them as lower camel case
140-
// we need to convert lower camel case to upper before merging options so they will override properly
141-
Object.keys(object).map((key) => {
142-
const upperCase = key.charAt(0).toUpperCase();
143-
if (key.charAt(0) !== upperCase) {
144-
const capitalKey = upperCase + key.slice(1);
145-
object[capitalKey] = object[key];
146-
delete object[key];
147-
}
148-
});
149-
return object;
150-
}
151-
152139
private createSandboxRequest(): SandboxRequest {
153140
this.logger.debug('Create Varargs: %s ', this.varargs);
154141
let sandboxDefFileContents = this.readJsonDefFile();
155142
let capitalizedVarArgs = {};
156143

157144
if (sandboxDefFileContents) {
158-
sandboxDefFileContents = this.lowerToUpper(sandboxDefFileContents);
145+
sandboxDefFileContents = lowerToUpper(sandboxDefFileContents);
159146
}
160147
if (this.varargs) {
161-
capitalizedVarArgs = this.lowerToUpper(this.varargs);
148+
capitalizedVarArgs = lowerToUpper(this.varargs);
162149
}
163150
// varargs override file input
164151
const sandboxReq: SandboxRequest = { SandboxName: undefined, ...sandboxDefFileContents, ...capitalizedVarArgs };
@@ -184,7 +171,9 @@ export class Create extends SfdxCommand {
184171
// `on` doesn't support synchronous methods
185172
// eslint-disable-next-line @typescript-eslint/require-await
186173
lifecycle.on(SandboxEvents.EVENT_ASYNC_RESULT, async (results: SandboxProcessObject) => {
187-
this.ux.log(messages.getMessage('sandboxSuccess', [results.Id, results.SandboxName, this.flags.targetusername]));
174+
this.ux.log(
175+
messages.getMessage('sandboxSuccess', [results.Id, results.SandboxName, this.flags.targetusername as string])
176+
);
188177
});
189178

190179
// eslint-disable-next-line @typescript-eslint/require-await
@@ -208,7 +197,7 @@ export class Create extends SfdxCommand {
208197
if (results.sandboxRes?.authUserName) {
209198
if (this.flags.setalias) {
210199
const stateAggregator = await StateAggregator.getInstance();
211-
stateAggregator.aliases.set(this.flags.setalias, results.sandboxRes.authUserName);
200+
stateAggregator.aliases.set(this.flags.setalias as string, results.sandboxRes.authUserName);
212201
const result = await stateAggregator.aliases.write();
213202
this.logger.debug('Set Alias: %s result: %s', this.flags.setalias, result);
214203
}
@@ -227,15 +216,15 @@ export class Create extends SfdxCommand {
227216
const wait = this.flags.wait as Duration;
228217

229218
try {
230-
return prodOrg.createSandbox(sandboxReq, { wait });
219+
return await prodOrg.createSandbox(sandboxReq, { wait });
231220
} catch (e) {
232221
// guaranteed to be SfdxError from core;
233222
const err = e as SfError;
234223
if (err?.message.includes('The org cannot be found')) {
235224
// there was most likely an issue with DNS when auth'ing to the new sandbox, but it was created.
236225
if (this.flags.setalias && this.sandboxAuth) {
237226
const stateAggregator = await StateAggregator.getInstance();
238-
stateAggregator.aliases.set(this.flags.setalias, this.sandboxAuth.authUserName);
227+
stateAggregator.aliases.set(this.flags.setalias as string, this.sandboxAuth.authUserName);
239228
const result = await stateAggregator.aliases.write();
240229
this.logger.debug('Set Alias: %s result: %s', this.flags.setalias, result);
241230
}
@@ -256,7 +245,7 @@ export class Create extends SfdxCommand {
256245
// the -f option
257246
if (this.flags.definitionfile) {
258247
this.logger.debug('Reading JSON DefFile %s ', this.flags.definitionfile);
259-
return JSON.parse(fs.readFileSync(this.flags.definitionfile, 'utf-8')) as Record<string, unknown>;
248+
return JSON.parse(fs.readFileSync(this.flags.definitionfile as string, 'utf-8')) as Record<string, unknown>;
260249
}
261250
}
262251

src/commands/force/org/display.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import * as os from 'os';
99
import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
1010
import { AuthInfo, Messages, sfdc, SfError } from '@salesforce/core';
1111
import { camelCaseToTitleCase } from '@salesforce/kit';
12-
1312
import { OrgDisplayReturn, ScratchOrgFields } from '../../../shared/orgTypes';
1413
import { getAliasByUsername } from '../../../shared/utils';
1514
import { getStyledValue } from '../../../shared/orgHighlighter';
@@ -76,6 +75,8 @@ export class OrgDisplayCommand extends SfdxCommand {
7675
.sort() // this command always alphabetizes the table rows
7776
.map((key) => ({
7877
key: camelCaseToTitleCase(key),
78+
// TS won't infer types of the values of OrgDisplayReturn, even thought it's typed (they're all string or date)
79+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument
7980
value: getStyledValue(key, result[key]),
8081
}));
8182

src/commands/force/org/list.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class OrgListCommand extends SfdxCommand {
7979
};
8080
this.ux.styledHeader('Orgs');
8181

82-
this.printOrgTable(result.nonScratchOrgs, this.flags.skipconnectionstatus);
82+
this.printOrgTable(result.nonScratchOrgs, this.flags.skipconnectionstatus as boolean);
8383
// separate the table by a blank line.
8484
this.ux.log();
8585

@@ -160,6 +160,7 @@ export class OrgListCommand extends SfdxCommand {
160160
}
161161
}
162162

163+
// eslint-disable-next-line class-methods-use-this
163164
private extractDefaultOrgStatus(val: ExtendedAuthFields): void {
164165
if (val.isDefaultDevHubUsername) {
165166
val.defaultMarker = '(D)';

src/commands/force/org/open.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ export class OrgOpenCommand extends SfdxCommand {
3131
char: 'p',
3232
description: messages.getMessage('cliPath'),
3333
env: 'FORCE_OPEN_URL',
34-
parse: (input: string): Promise<string> => {
35-
return Promise.resolve(encodeURIComponent(decodeURIComponent(input)));
36-
},
34+
parse: (input: string): Promise<string> => Promise.resolve(encodeURIComponent(decodeURIComponent(input))),
3735
}),
3836
urlonly: flags.boolean({
3937
char: 'r',
@@ -75,14 +73,16 @@ export class OrgOpenCommand extends SfdxCommand {
7573
const sfdcUrl = new SfdcUrl(url);
7674
await sfdcUrl.checkLightningDomain();
7775
} catch (err) {
78-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
79-
if (err.message?.includes('timeout')) {
80-
const domain = `https://${/https?:\/\/([^.]*)/.exec(url)[1]}.lightning.force.com`;
81-
const timeout = new Duration(new Env().getNumber('SFDX_DOMAIN_RETRY', 240), Duration.Unit.SECONDS);
82-
this.logger.debug(`Did not find IP for ${domain} after ${timeout.seconds} seconds`);
83-
throw new SfError(messages.getMessage('domainTimeoutError'), 'domainTimeoutError');
76+
if (err instanceof Error) {
77+
if (err.message?.includes('timeout')) {
78+
const domain = `https://${/https?:\/\/([^.]*)/.exec(url)[1]}.lightning.force.com`;
79+
const timeout = new Duration(new Env().getNumber('SFDX_DOMAIN_RETRY', 240), Duration.Unit.SECONDS);
80+
this.logger.debug(`Did not find IP for ${domain} after ${timeout.seconds} seconds`);
81+
throw new SfError(messages.getMessage('domainTimeoutError'), 'domainTimeoutError');
82+
}
83+
throw SfError.wrap(err);
8484
}
85-
throw SfError.wrap(err);
85+
throw err;
8686
}
8787

8888
const openOptions =

src/commands/force/org/status.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class OrgStatusCommand extends SfdxCommand {
7373
if (results.sandboxRes?.authUserName) {
7474
if (this.flags.setalias) {
7575
const stateAggregator = await StateAggregator.getInstance();
76-
stateAggregator.aliases.set(this.flags.setalias, results.sandboxRes.authUserName);
76+
stateAggregator.aliases.set(this.flags.setalias as string, results.sandboxRes.authUserName);
7777
await stateAggregator.aliases.write();
7878
this.logger.debug('Set Alias: %s result: %s', this.flags.setalias, results.sandboxRes.authUserName);
7979
}
@@ -87,7 +87,9 @@ export class OrgStatusCommand extends SfdxCommand {
8787
});
8888

8989
this.logger.debug('Calling auth for SandboxName args: %s ', this.flags.sandboxname);
90-
const results = await this.org.sandboxStatus(this.flags.sandboxname, { wait: this.flags.wait as Duration });
90+
const results = await this.org.sandboxStatus(this.flags.sandboxname as string, {
91+
wait: this.flags.wait as Duration,
92+
});
9193
this.logger.debug('Results for auth call: %s ', results);
9294
if (!results) {
9395
this.ux.styledHeader('Sandbox Org Creation Status');

0 commit comments

Comments
 (0)