Skip to content

Commit

Permalink
fix: remove an undefined TypeError (#1081)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc authored Feb 12, 2024
1 parent c65eb9a commit 88e6c34
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/formatters/source/pushResultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
DeployResult,
FileResponse,
FileResponseFailure,
FileResponseSuccess,
MetadataResolver,
SourceComponent,
VirtualTreeContainer,
Expand All @@ -23,7 +24,7 @@ import { ensureArray } from '@salesforce/kit';
import { Ux } from '@salesforce/sf-plugins-core';
import { ResultFormatter, ResultFormatterOptions } from '../resultFormatter.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-source', 'push');

export type PushResponse = {
Expand Down Expand Up @@ -132,33 +133,32 @@ export class PushResultFormatter extends ResultFormatter {
}
// "content" property of the bundles as a string
const contentFilePathFromDeployedBundles = this.componentsFromFilenames(
// the .filter(isString) should ensure only strings are present, but TS isn't finding that
bundlesDeployed.map((fileResponse) => fileResponse.filePath as string)
bundlesDeployed.map((fileResponse) => fileResponse.filePath).filter(isString)
)
.map((c) => c.content)
.filter(isString);

// there may be deletes not represented in the file responses (if bundle type)
const resolver = new MetadataResolver(undefined, VirtualTreeContainer.fromFilePaths(this.deletes));
return (
this.deletes
.map((filePath) => {
const cmp = this.resolveComponentsOrWarn(filePath, resolver)[0];
if (
cmp.type.strategies?.adapter === 'bundle' &&
contentFilePathFromDeployedBundles.includes(pathResolve(cmp.content ?? ''))
) {
return {
state: ComponentStatus.Deleted,
fullName: cmp.fullName,
type: cmp.type.name,
filePath,
} as FileResponse;
}
})
.filter((fileResponse) => fileResponse)
// we can be sure there's no undefined responses because of the filter above
.concat(withoutUnchanged) as FileResponse[]

return withoutUnchanged.concat(
this.deletes.flatMap((filePath) =>
this.resolveComponentsOrWarn(filePath, resolver)
.filter(
(cmp) =>
cmp.type.strategies?.adapter === 'bundle' &&
contentFilePathFromDeployedBundles.includes(pathResolve(cmp.content ?? ''))
)
.map(
(cmp) =>
({
state: ComponentStatus.Deleted,
fullName: cmp.fullName,
type: cmp.type.name,
filePath,
} satisfies FileResponseSuccess)
)
)
);
}

Expand Down

0 comments on commit 88e6c34

Please sign in to comment.