Skip to content

Commit

Permalink
fix: allow more undefined from adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Aug 1, 2024
1 parent 1727cd3 commit fffaea9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
13 changes: 6 additions & 7 deletions src/resolve/adapters/baseSourceAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { basename, dirname, sep } from 'node:path';
import { Messages, SfError } from '@salesforce/core';
import { Lifecycle, Messages, SfError } from '@salesforce/core';
import { ensureString } from '@salesforce/ts-types';
import { MetadataXml } from '../types';
import { parseMetadataXml, parseNestedFullName } from '../../utils/path';
import { SourceComponent } from '../sourceComponent';
import { SourcePath } from '../../common/types';
import { MetadataType } from '../../registry/types';
import { RegistryAccess, typeAllowsMetadataWithContent } from '../../registry/registryAccess';
import { FindRootMetadata, GetComponent } from './types';
import { FindRootMetadata, MaybeGetComponent } from './types';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/source-deploy-retrieve', 'sdr');
Expand Down Expand Up @@ -76,17 +76,16 @@ export const trimPathToContent =
return pathParts.slice(0, typeFolderIndex + offset).join(sep);
};

export const getComponent: GetComponent =
export const getComponent: MaybeGetComponent =
(context) =>
({ type, path, metadataXml: findRootMetadata = defaultFindRootMetadata }) => {
// find rootMetadata
const metadataXml = typeof findRootMetadata === 'function' ? findRootMetadata(type, path) : findRootMetadata;
if (!metadataXml) {
throw SfError.create({
message: messages.getMessage('error_parsing_xml', [path, type.name]),
name: 'MissingXml',
});
void Lifecycle.getInstance().emitWarning(messages.getMessage('error_parsing_xml', [path, type.name]));
return;
}

if (context.forceIgnore?.denies(metadataXml.path)) {
throw SfError.create({
message: messages.getMessage('error_no_metadata_xml_ignore', [metadataXml.path, path]),
Expand Down
2 changes: 1 addition & 1 deletion src/resolve/adapters/digitalExperienceSourceAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const getDigitalExperienceComponent: MaybeGetComponent =
? ensure(parseMetadataXmlForDEB(context.registry)(type)(metaFilePath))
: ({ path: metaFilePath, fullName: 'foo' } satisfies MetadataXml);
const sourceComponent = getComponent(context)({ type, path, metadataXml: rootMetaXml });
return populate(context)(type)(path, sourceComponent);
return sourceComponent ? populate(context)(type)(path, sourceComponent) : undefined;
};

const getNonDEBRoot = (type: MetadataType, path: SourcePath): SourcePath => {
Expand Down
2 changes: 1 addition & 1 deletion src/resolve/adapters/matchingContentSourceAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const removeMetaXmlSuffix = (fsPath: SourcePath): SourcePath => fsPath.slice(0,
export const getMatchingContentComponent: GetComponent =
(context) =>
({ type, path }) => {
const sourceComponent = getComponent(context)({ type, path, metadataXml: findRootMetadata });
const sourceComponent = ensure(getComponent(context)({ type, path, metadataXml: findRootMetadata }));
return populate(context)(type)(path, sourceComponent);
};

Expand Down

2 comments on commit fffaea9

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: fffaea9 Previous: 174a93b Ratio
eda-componentSetCreate-linux 178 ms 236 ms 0.75
eda-sourceToMdapi-linux 2323 ms 2332 ms 1.00
eda-sourceToZip-linux 1850 ms 1818 ms 1.02
eda-mdapiToSource-linux 2865 ms 2814 ms 1.02
lotsOfClasses-componentSetCreate-linux 364 ms 427 ms 0.85
lotsOfClasses-sourceToMdapi-linux 3732 ms 3774 ms 0.99
lotsOfClasses-sourceToZip-linux 3098 ms 3139 ms 0.99
lotsOfClasses-mdapiToSource-linux 3560 ms 3567 ms 1.00
lotsOfClassesOneDir-componentSetCreate-linux 636 ms 730 ms 0.87
lotsOfClassesOneDir-sourceToMdapi-linux 6368 ms 6572 ms 0.97
lotsOfClassesOneDir-sourceToZip-linux 5592 ms 5773 ms 0.97
lotsOfClassesOneDir-mdapiToSource-linux 6355 ms 6385 ms 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: fffaea9 Previous: 174a93b Ratio
eda-componentSetCreate-win32 454 ms 687 ms 0.66
eda-sourceToMdapi-win32 4536 ms 4185 ms 1.08
eda-sourceToZip-win32 2998 ms 3224 ms 0.93
eda-mdapiToSource-win32 6016 ms 6072 ms 0.99
lotsOfClasses-componentSetCreate-win32 921 ms 1280 ms 0.72
lotsOfClasses-sourceToMdapi-win32 7890 ms 8162 ms 0.97
lotsOfClasses-sourceToZip-win32 4954 ms 5429 ms 0.91
lotsOfClasses-mdapiToSource-win32 8026 ms 8361 ms 0.96
lotsOfClassesOneDir-componentSetCreate-win32 1465 ms 2308 ms 0.63
lotsOfClassesOneDir-sourceToMdapi-win32 14323 ms 14636 ms 0.98
lotsOfClassesOneDir-sourceToZip-win32 9038 ms 9752 ms 0.93
lotsOfClassesOneDir-mdapiToSource-win32 13321 ms 14804 ms 0.90

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.