Skip to content

Commit

Permalink
fix: update manifest resolver to identify InFolder parents with trail…
Browse files Browse the repository at this point in the history
…ing slashes
  • Loading branch information
shetzel committed Aug 30, 2024
1 parent f63be1d commit 9520084
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 7 deletions.
36 changes: 29 additions & 7 deletions src/resolve/manifestResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export class ManifestResolver {
const type = this.registry.getTypeByName(typeMembers.name);
const parentType = type.folderType ? this.registry.getTypeByName(type.folderType) : undefined;
return ensureArray(typeMembers.members).map((fullName, _index, members) => ({
fullName,
type: parentType && isMemberNestedInFolder(fullName, type, parentType, members) ? parentType : type,
fullName: resolveFullName(fullName, parentType),
type: !parentType ? type : resolveType(fullName, type, members, parentType),
}));
});

Expand Down Expand Up @@ -113,6 +113,33 @@ const getValidatedType =
return typeMembers;
};

// Mostly for parents of InFolder types to strip off trailing "/" characters
// in fullNames. Otherwise just returns the fullName.
const resolveFullName = (fullName: string, parentType?: MetadataType): string =>
parentType?.folderContentType && fullName.endsWith('/') ? fullName.substring(0, fullName.length - 1) : fullName;

// Resolve the correct metadata type from metadata entries in a manifest.
// Parents of InFolder types can be detected by looking for a trailing "/"
// character.
const resolveType = (
fullName: string,
type: MetadataType,
members: string[],
parentType?: MetadataType
): MetadataType => {
// Quick short-circuit for non-parent types and non-folderTypes
if (!parentType || !type.folderType) {
return type;
}

// Detect parents of InFolder types by looking for a trailing slash on InFolder types
if (parentType?.folderContentType && fullName.endsWith('/')) {
return parentType;
}

return isMemberNestedInFolder(fullName, type, parentType, members) ? parentType : type;
};

// Use the folderType instead of the type from the manifest when:
// 1. InFolder types: (report, dashboard, emailTemplate, document)
// 1a. type.inFolder === true (from metadataRegistry.json) AND
Expand All @@ -129,11 +156,6 @@ const isMemberNestedInFolder = (
parentType: MetadataType,
members: string[]
): boolean => {
// Quick short-circuit for non-folderTypes
if (!type.folderType) {
return false;
}

const isInFolderType = type.inFolder;
const isNestedInFolder = !fullName.includes('/') || members.some((m) => m.includes(`${fullName}/`));
const isNonMatchingFolder = parentType && parentType.folderType !== parentType.id;
Expand Down
58 changes: 58 additions & 0 deletions test/resolve/manifestResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,64 @@ describe('ManifestResolver', () => {
expect(result.components).to.deep.equal(expected);
});

it('should resolve nested InFolder types with trailing slashes', async () => {
const registry = new RegistryAccess();
const reportType = registry.getTypeByName('report');
const reportFolderType = registry.getTypeByName('reportFolder');
const folderManifest: VirtualFile = {
name: 'reports-package.xml',
data: Buffer.from(`<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>foo/</members>
<members>foo/subfoo/</members>
<members>foo/subfoo/MySubFooReport1</members>
<members>foo/subfoo/MySubFooReport2</members>
<members>bar/MyBarReport1</members>
<members>bar/MyBarReport2</members>
<name>Report</name>
</types>
<version>52.0</version>
</Package>\n`),
};
const tree = new VirtualTreeContainer([
{
dirPath: '.',
children: [folderManifest],
},
]);
const resolver = new ManifestResolver(tree);
const result = await resolver.resolve(folderManifest.name);
const expected: MetadataComponent[] = [
{
fullName: 'foo',
type: reportFolderType,
},
{
fullName: 'foo/subfoo',
type: reportFolderType,
},
{
fullName: 'foo/subfoo/MySubFooReport1',
type: reportType,
},
{
fullName: 'foo/subfoo/MySubFooReport2',
type: reportType,
},
{
fullName: 'bar/MyBarReport1',
type: reportType,
},
{
fullName: 'bar/MyBarReport2',
type: reportType,
},
];

expect(result.components).to.deep.equal(expected);
});

it('should resolve folderType types (Territory2*)', async () => {
const registry = new RegistryAccess();
const t2ModelType = registry.getTypeByName('Territory2Model');
Expand Down

2 comments on commit 9520084

@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: 9520084 Previous: f63be1d Ratio
eda-componentSetCreate-linux 232 ms 235 ms 0.99
eda-sourceToMdapi-linux 2379 ms 2320 ms 1.03
eda-sourceToZip-linux 1889 ms 1867 ms 1.01
eda-mdapiToSource-linux 3085 ms 2921 ms 1.06
lotsOfClasses-componentSetCreate-linux 421 ms 429 ms 0.98
lotsOfClasses-sourceToMdapi-linux 3758 ms 3675 ms 1.02
lotsOfClasses-sourceToZip-linux 3223 ms 3212 ms 1.00
lotsOfClasses-mdapiToSource-linux 3607 ms 3609 ms 1.00
lotsOfClassesOneDir-componentSetCreate-linux 765 ms 759 ms 1.01
lotsOfClassesOneDir-sourceToMdapi-linux 6664 ms 6444 ms 1.03
lotsOfClassesOneDir-sourceToZip-linux 5989 ms 5580 ms 1.07
lotsOfClassesOneDir-mdapiToSource-linux 6708 ms 6550 ms 1.02

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: 9520084 Previous: f63be1d Ratio
eda-componentSetCreate-win32 682 ms 663 ms 1.03
eda-sourceToMdapi-win32 4682 ms 4345 ms 1.08
eda-sourceToZip-win32 3201 ms 2981 ms 1.07
eda-mdapiToSource-win32 6401 ms 5546 ms 1.15
lotsOfClasses-componentSetCreate-win32 1311 ms 1165 ms 1.13
lotsOfClasses-sourceToMdapi-win32 8350 ms 7633 ms 1.09
lotsOfClasses-sourceToZip-win32 5392 ms 4936 ms 1.09
lotsOfClasses-mdapiToSource-win32 8451 ms 7854 ms 1.08
lotsOfClassesOneDir-componentSetCreate-win32 2088 ms 2052 ms 1.02
lotsOfClassesOneDir-sourceToMdapi-win32 13784 ms 13634 ms 1.01
lotsOfClassesOneDir-sourceToZip-win32 9175 ms 9247 ms 0.99
lotsOfClassesOneDir-mdapiToSource-win32 14044 ms 14055 ms 1.00

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

Please sign in to comment.