Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: devScripts update #1261

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@oclif/plugin-command-snapshot": "^5.2.9",
"@oclif/plugin-help": "^6.2.3",
"@salesforce/cli-plugins-testkit": "^5.3.20",
"@salesforce/dev-scripts": "^10.2.8",
"@salesforce/dev-scripts": "^10.2.9",
"@salesforce/plugin-command-reference": "^3.1.10",
"@salesforce/source-testkit": "^2.2.41",
"@salesforce/ts-sinon": "1.4.22",
Expand Down
17 changes: 9 additions & 8 deletions src/commands/force/mdapi/retrieve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
RetrieveResult,
RetrieveVersionData,
} from '@salesforce/source-deploy-retrieve';
import { Optional, ensure } from '@salesforce/ts-types';
import { Optional, ensure, ensureString } from '@salesforce/ts-types';
import { Flags, loglevel, requiredOrgFlagWithDeprecations, Ux } from '@salesforce/sf-plugins-core';
import { Interfaces } from '@oclif/core';
import { resolveZipFileName, SourceCommand } from '../../../sourceCommand.js';
Expand Down Expand Up @@ -100,7 +100,7 @@ export class Retrieve extends SourceCommand {

protected retrieveResult: RetrieveResult | undefined;
private sourceDir: string | undefined;
private retrieveTargetDir: string | undefined;
private retrieveTargetDir!: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moving the setting of this to the top of the run method will justify !

private zipFileName: string | undefined;
private unzip: boolean | undefined;
// will be set to `flags.wait` (which has a default value) when executed.
Expand All @@ -111,6 +111,7 @@ export class Retrieve extends SourceCommand {
private org!: Org | undefined;
public async run(): Promise<RetrieveCommandCombinedResult> {
this.flags = (await this.parse(Retrieve)).flags;
this.retrieveTargetDir = this.resolveOutputDir(this.flags.retrievetargetdir);
this.org = this.flags['target-org'];
await this.retrieve();
this.resolveSuccess();
Expand Down Expand Up @@ -185,7 +186,7 @@ export class Retrieve extends SourceCommand {
unzip: this.unzip,
});

this.log(`Retrieve ID: ${this.mdapiRetrieve.id}`);
this.log(`Retrieve ID: ${this.mdapiRetrieve.id ?? ''}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preserves existing behavior (no value present)


if (this.isAsync) {
this.spinner.stop('queued');
Expand Down Expand Up @@ -216,11 +217,11 @@ export class Retrieve extends SourceCommand {
protected formatResult(): RetrieveCommandResult | RetrieveCommandAsyncResult {
// async result
if (this.isAsync) {
let cmdFlags = `--jobid ${this.mdapiRetrieve?.id} --retrievetargetdir ${this.retrieveTargetDir}`;
const targetusernameFlag = this.flags['target-org'];
if (targetusernameFlag) {
cmdFlags += ` --targetusername ${targetusernameFlag.getUsername()}`;
}
const targetUsername = this.flags['target-org'].getUsername();

const cmdFlags = `--jobid ${ensureString(this.mdapiRetrieve?.id)} --retrievetargetdir ${this.retrieveTargetDir}${
targetUsername ? ` --targetusername ${targetUsername}` : ''
}`;
this.log('');
this.log(messages.getMessage('checkStatus', [cmdFlags]));
return {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/force/source/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const resultConverter = (input: StatusOutputRow): StatusResult => {
type,
// this string became the place to store information.
// The JSON now breaks out that info but preserves this property for backward compatibility
state: `${origin} ${actualState}${conflict ? ' (Conflict)' : ''}` as StatusStateString,
state: `${origin} ${actualState as string}${conflict ? ' (Conflict)' : ''}` as StatusStateString,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the map is complete, but Map.get() doesn't guarantee presence

ignored,
filePath,
origin,
Expand Down
2 changes: 1 addition & 1 deletion src/deployCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const reportsFormatters = Object.keys(DefaultReportOptions);
export abstract class DeployCommand extends SourceCommand {
protected displayDeployId = once((id?: string) => {
if (!this.jsonEnabled()) {
this.log(`Deploy ID: ${id}`);
this.log(`Deploy ID: ${id ?? '<not present>'}`);
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/formatters/deployCancelResultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class DeployCancelResultFormatter extends ResultFormatter {
}

public display(): void {
const deployId = getString(this.result, 'response.id');
const deployId = this.result.response.id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that we have types we don't need the goofy get on objects

if (this.isSuccess()) {
this.ux.log(`Successfully canceled ${deployId}`);
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/formatters/deployProgressStatusFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ export class DeployProgressStatusFormatter extends ProgressFormatter {
const testsTotal = getNumber(data, 'numberTestsTotal');
const testsCompleted = getNumber(data, 'numberTestsCompleted');
const testErrors = getNumber(data, 'numberTestErrors');
const deploys = `${componentsDeployed}/${componentsTotal} components deployed.`;
const deployErrors = componentErrors === 1 ? `${componentErrors} error.` : `${componentErrors} errors.`;
const tests = `${testsCompleted}/${testsTotal} tests completed.`;
const testErrs = testErrors === 1 ? `${testErrors} error.` : `${testErrors} errors.`;
const deploys = `${componentsDeployed ?? 0}/${componentsTotal ?? 0} components deployed.`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zeros seemed right?

const deployErrors = componentErrors === 1 ? `${componentErrors} error.` : `${componentErrors ?? 0} errors.`;
const tests = `${testsCompleted ?? 0}/${testsTotal ?? 0} tests completed.`;
const testErrs = testErrors === 1 ? `${testErrors} error.` : `${testErrors ?? 0} errors.`;
this.ux.log(`${deploys} ${deployErrors}`);
this.ux.log(`${tests} ${testErrs}`);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/formatters/deployResultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export class DeployResultFormatter extends ResultFormatter {
if (deployMessages.length > failures.length) {
// if there's additional failures in the API response, find the failure and add it to the output
deployMessages.map((deployMessage) => {
if (!fileResponseFailures.has(`${deployMessage.componentType}#${deployMessage.fullName}`)) {
if (!fileResponseFailures.has(`${deployMessage.componentType ?? ''}#${deployMessage.fullName}`)) {
// duplicate the problem message to the error property for displaying in the table
failures.push(Object.assign(deployMessage, { error: deployMessage.problem }));
}
Expand Down Expand Up @@ -277,7 +277,7 @@ export class DeployResultFormatter extends ResultFormatter {

this.ux.log('');
this.ux.styledHeader(
chalk.red(`Test Failures [${asString(this.result.response.details.runTestResult?.numFailures)}]`)
chalk.red(`Test Failures [${asString(this.result.response.details.runTestResult?.numFailures) ?? ''}]`)
);
this.ux.table(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down
4 changes: 3 additions & 1 deletion src/formatters/mdapi/mdDeployResultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ export class MdDeployResultFormatter extends ResultFormatter {
const tests = this.sortTestResults(failures);

this.ux.log('');
this.ux.styledHeader(chalk.red(`Test Failures [${this.result.response.details.runTestResult?.numFailures}]`));
this.ux.styledHeader(
chalk.red(`Test Failures [${this.result.response.details.runTestResult?.numFailures ?? 0}]`)
);
this.ux.table(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Expand Down
6 changes: 3 additions & 3 deletions src/formatters/mdapi/retrieveResultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ export type RetrieveResultFormatterOptions = {
retrieveTargetDir: string;
zipFileName?: string;
unzip?: boolean;
} & ResultFormatterOptions
} & ResultFormatterOptions;

export type RetrieveCommandAsyncResult = {
done: boolean;
id: string;
state: RequestStatus | 'Queued';
status: RequestStatus | 'Queued';
timedOut: boolean;
}
};

export class RetrieveResultFormatter extends RetrieveFormatter {
protected zipFilePath: string;
Expand Down Expand Up @@ -67,7 +67,7 @@ export class RetrieveResultFormatter extends RetrieveFormatter {
this.ux.log(`Wrote retrieve zip to ${this.zipFilePath}`);
if (this.options.unzip) {
const extractPath = join(this.options.retrieveTargetDir, parse(this.options.zipFileName ?? '').name);
this.ux.log(`Extracted ${this.options.zipFileName} to: ${extractPath}`);
this.ux.log(`Extracted ${this.options.zipFileName ?? '<missing zipFileName>'} to: ${extractPath}`);
}
if (this.options.verbose) {
const retrievedFiles = ensureArray(this.result.fileProperties);
Expand Down
2 changes: 1 addition & 1 deletion src/formatters/source/pushResultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export class PushResultFormatter extends ResultFormatter {
if (deployMessages.length > failures.length) {
// if there's additional failures in the API response, find the failure and add it to the output
deployMessages.map((deployMessage) => {
if (!fileResponseFailures.has(`${deployMessage.componentType}#${deployMessage.fullName}`)) {
if (!fileResponseFailures.has(`${deployMessage.componentType ?? ''}#${deployMessage.fullName}`)) {
// duplicate the problem message to the error property for displaying in the table
failures.push(
Object.assign(deployMessage, { error: deployMessage.problem }) as unknown as FileResponseFailure
Expand Down
2 changes: 1 addition & 1 deletion src/trackingFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const processConflicts = (conflicts: ChangeResult[], ux: Ux, message: string): v
const conflictMap = new Map<string, ConflictResponse>();
conflicts.forEach((c) => {
c.filenames?.forEach((f) => {
conflictMap.set(`${c.name}#${c.type}#${f}`, {
conflictMap.set(`${c.name ?? ''}#${c.type ?? ''}#${f}`, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also preserve existing behaior

state: 'Conflict',
fullName: c.name as string,
type: c.type as string,
Expand Down
Loading