From 345cf9ff5a4056bc1338bb2d55ad41bf1a32cfcb Mon Sep 17 00:00:00 2001 From: mshanemc Date: Tue, 30 Jul 2024 12:46:00 -0500 Subject: [PATCH] fix: nullish in template-literal --- src/commands/force/mdapi/retrieve.ts | 17 +++++++++-------- src/commands/force/source/status.ts | 2 +- src/deployCommand.ts | 2 +- src/formatters/deployCancelResultFormatter.ts | 2 +- src/formatters/deployProgressStatusFormatter.ts | 8 ++++---- src/formatters/deployResultFormatter.ts | 4 ++-- src/formatters/mdapi/mdDeployResultFormatter.ts | 4 +++- src/formatters/mdapi/retrieveResultFormatter.ts | 6 +++--- src/formatters/source/pushResultFormatter.ts | 2 +- src/trackingFunctions.ts | 2 +- 10 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/commands/force/mdapi/retrieve.ts b/src/commands/force/mdapi/retrieve.ts index 481f52d7c..519b20235 100644 --- a/src/commands/force/mdapi/retrieve.ts +++ b/src/commands/force/mdapi/retrieve.ts @@ -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'; @@ -100,7 +100,7 @@ export class Retrieve extends SourceCommand { protected retrieveResult: RetrieveResult | undefined; private sourceDir: string | undefined; - private retrieveTargetDir: string | undefined; + private retrieveTargetDir!: string; private zipFileName: string | undefined; private unzip: boolean | undefined; // will be set to `flags.wait` (which has a default value) when executed. @@ -111,6 +111,7 @@ export class Retrieve extends SourceCommand { private org!: Org | undefined; public async run(): Promise { 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(); @@ -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 ?? ''}`); if (this.isAsync) { this.spinner.stop('queued'); @@ -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 { diff --git a/src/commands/force/source/status.ts b/src/commands/force/source/status.ts index 1b6e974f6..f65b3bcdf 100644 --- a/src/commands/force/source/status.ts +++ b/src/commands/force/source/status.ts @@ -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, ignored, filePath, origin, diff --git a/src/deployCommand.ts b/src/deployCommand.ts index aa29cff0f..edef636e9 100644 --- a/src/deployCommand.ts +++ b/src/deployCommand.ts @@ -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 ?? ''}`); } }); diff --git a/src/formatters/deployCancelResultFormatter.ts b/src/formatters/deployCancelResultFormatter.ts index 2a413bef8..43186da4f 100644 --- a/src/formatters/deployCancelResultFormatter.ts +++ b/src/formatters/deployCancelResultFormatter.ts @@ -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; if (this.isSuccess()) { this.ux.log(`Successfully canceled ${deployId}`); } else { diff --git a/src/formatters/deployProgressStatusFormatter.ts b/src/formatters/deployProgressStatusFormatter.ts index 8706ee56f..2dde8a3c2 100644 --- a/src/formatters/deployProgressStatusFormatter.ts +++ b/src/formatters/deployProgressStatusFormatter.ts @@ -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.`; + 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 { diff --git a/src/formatters/deployResultFormatter.ts b/src/formatters/deployResultFormatter.ts index cbc900f4a..3d53f11ba 100644 --- a/src/formatters/deployResultFormatter.ts +++ b/src/formatters/deployResultFormatter.ts @@ -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 })); } @@ -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 diff --git a/src/formatters/mdapi/mdDeployResultFormatter.ts b/src/formatters/mdapi/mdDeployResultFormatter.ts index 0f5e5e235..83085f388 100644 --- a/src/formatters/mdapi/mdDeployResultFormatter.ts +++ b/src/formatters/mdapi/mdDeployResultFormatter.ts @@ -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 diff --git a/src/formatters/mdapi/retrieveResultFormatter.ts b/src/formatters/mdapi/retrieveResultFormatter.ts index cf9906f85..e84b5dc22 100644 --- a/src/formatters/mdapi/retrieveResultFormatter.ts +++ b/src/formatters/mdapi/retrieveResultFormatter.ts @@ -24,7 +24,7 @@ export type RetrieveResultFormatterOptions = { retrieveTargetDir: string; zipFileName?: string; unzip?: boolean; -} & ResultFormatterOptions +} & ResultFormatterOptions; export type RetrieveCommandAsyncResult = { done: boolean; @@ -32,7 +32,7 @@ export type RetrieveCommandAsyncResult = { state: RequestStatus | 'Queued'; status: RequestStatus | 'Queued'; timedOut: boolean; -} +}; export class RetrieveResultFormatter extends RetrieveFormatter { protected zipFilePath: string; @@ -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 ?? ''} to: ${extractPath}`); } if (this.options.verbose) { const retrievedFiles = ensureArray(this.result.fileProperties); diff --git a/src/formatters/source/pushResultFormatter.ts b/src/formatters/source/pushResultFormatter.ts index a5e867e4a..f0e17aae1 100644 --- a/src/formatters/source/pushResultFormatter.ts +++ b/src/formatters/source/pushResultFormatter.ts @@ -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 diff --git a/src/trackingFunctions.ts b/src/trackingFunctions.ts index 58c8a236a..fbc1ae66e 100644 --- a/src/trackingFunctions.ts +++ b/src/trackingFunctions.ts @@ -138,7 +138,7 @@ const processConflicts = (conflicts: ChangeResult[], ux: Ux, message: string): v const conflictMap = new Map(); conflicts.forEach((c) => { c.filenames?.forEach((f) => { - conflictMap.set(`${c.name}#${c.type}#${f}`, { + conflictMap.set(`${c.name ?? ''}#${c.type ?? ''}#${f}`, { state: 'Conflict', fullName: c.name as string, type: c.type as string,