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

fix: resolve strictDirectoryName types in mdapi format #601

Merged
merged 4 commits into from
Apr 1, 2022
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
5 changes: 2 additions & 3 deletions METADATA_SUPPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,6 @@ v55 introduces the following new types. Here's their current level of support
|ExpressionSetDefinition|✅||
|ExpressionSetDefinitionVersion|✅||
|ExternalDataSrcDescriptor|❌|Not supported, but support could be added|
|ExternalDataTranField|❌|Not supported, but support could be added|
|ExternalDataTranObject|❌|Not supported, but support could be added|
|FlowTest|✅||
|ForecastingFilter|❌|Not supported, but support could be added|
|ForecastingFilterCondition|❌|Not supported, but support could be added|
Expand All @@ -511,10 +509,11 @@ v55 introduces the following new types. Here's their current level of support
|MessagingChannel|undefined|undefined|
|PaymentsManagementEnabledSettings|✅||
|RegisteredExternalService|❌|Not supported, but support could be added|
|SchedulingObjective|❌|Not supported, but support could be added|
|SchedulingObjective|undefined|undefined|
|StreamingAppDataConnector|❌|Not supported, but support could be added|
|SubscriptionManagementSettings|✅||
|VoiceSettings|✅||
|WarrantyLifecycleMgmtSettings|✅||

## Additional Types

Expand Down
4 changes: 2 additions & 2 deletions src/resolve/metadataResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ export class MetadataResolver {
// any of the following 3 options is considered a good match
// mixedContent and bundles don't have a suffix to match
['mixedContent', 'bundle'].includes(type.strategies?.adapter) ||
// the suffix matches the type we think it is
(type.suffix && fsPath.endsWith(`${type.suffix}${META_XML_SUFFIX}`)) ||
// the file suffix (in source or mdapi format) matches the type suffix we think it is
(type.suffix && [type.suffix, `${type.suffix}${META_XML_SUFFIX}`].some((s) => fsPath.endsWith(s))) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

that exception is that little punk emailServicesFunction for whom .xml is the suffix.

now that we're testing with a real registry, can you make sure that it's handled correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested manually and added a unit test for it. The fix doesn't affect it since the matching wouldn't get that far with the EmailServicesFunction type; it's not defined as "strictDirectoryName": true

Copy link
Contributor

Choose a reason for hiding this comment

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

FYI, I was wanting it in a strictDir. ESF has a habit of matching way too promiscuously and I'm trying to keep that from happening.

https://github.com/forcedotcom/source-deploy-retrieve/pull/595/files#diff-af7a780a5aa66c4831707c3ccd4e24d4f88a6639346bc0b1897c287efcbe14c9

So...what would happen if it were in strictDir?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Testing would help us out, but I think it would still work just fine because it would only get to the suffix matching if the path contained the expected directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After testing, ESF still retrieves and deploys successfully when defined as a strictDirectoryName.

// the type has children and the path also includes THAT directory
(type.children?.types &&
Object.values(type.children?.types)
Expand Down
55 changes: 55 additions & 0 deletions test/resolve/metadataResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,61 @@ describe('MetadataResolver', () => {
expect(access.getComponentsFromPath(path)).to.deep.equal([matchingContentFile.COMPONENT]);
});

it('Should determine type for metadata file with known suffix and strictDirectoryName', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made sure the test failed without the fix.

// CustomSite is an example. The conditions are:
// 1. Type has "strictDirectoryName": true
// 2. Type strategy adapter is neither "mixedContent" nor "bundle"
// 3. Type doesn't have children
// 4. mdapi format file path (E_Bikes.site)
const path = join('unpackaged', 'sites', 'E_Bikes.site');
const treeContainer = VirtualTreeContainer.fromFilePaths([path]);
const mdResolver = new MetadataResolver(undefined, treeContainer);
const expectedComponent = new SourceComponent(
{
name: 'E_Bikes',
type: registry.types.customsite,
xml: path,
},
treeContainer
);
expect(mdResolver.getComponentsFromPath(path)).to.deep.equal([expectedComponent]);
});

it('Should determine type for source file with known suffix and strictDirectoryName', () => {
// CustomSite is an example. The conditions are:
// 1. Type has "strictDirectoryName": true
// 2. Type strategy adapter is neither "mixedContent" nor "bundle"
// 3. Type doesn't have children
// 4. source format file path (E_Bikes.site-meta.xml)
const path = join('unpackaged', 'sites', 'E_Bikes.site-meta.xml');
const treeContainer = VirtualTreeContainer.fromFilePaths([path]);
const mdResolver = new MetadataResolver(undefined, treeContainer);
const expectedComponent = new SourceComponent(
{
name: 'E_Bikes',
type: registry.types.customsite,
xml: path,
},
treeContainer
);
expect(mdResolver.getComponentsFromPath(path)).to.deep.equal([expectedComponent]);
});

it('Should determine type for EmailServicesFunction metadata file (mdapi format)', () => {
const path = join('unpackaged', 'emailservices', 'MyEmailServices.xml');
const treeContainer = VirtualTreeContainer.fromFilePaths([path]);
const mdResolver = new MetadataResolver(undefined, treeContainer);
const expectedComponent = new SourceComponent(
{
name: 'MyEmailServices',
type: registry.types.emailservicesfunction,
xml: path,
},
treeContainer
);
expect(mdResolver.getComponentsFromPath(path)).to.deep.equal([expectedComponent]);
});

it('Should determine type for path of mixed content type', () => {
const path = mixedContentDirectory.MIXED_CONTENT_DIRECTORY_SOURCE_PATHS[1];
const access = testUtil.createMetadataResolver([
Expand Down