diff --git a/src/registry/presets/decomposeExternalServiceRegistrationBeta.json b/src/registry/presets/decomposeExternalServiceRegistrationBeta.json index 577e7f79cf..310af0b9f3 100644 --- a/src/registry/presets/decomposeExternalServiceRegistrationBeta.json +++ b/src/registry/presets/decomposeExternalServiceRegistrationBeta.json @@ -11,6 +11,7 @@ "id": "yaml", "isAddressable": false, "name": "OAS Yaml Schema", + "strictDirectoryName": true, "suffix": "yaml", "xmlElementName": "schema" } diff --git a/src/resolve/metadataResolver.ts b/src/resolve/metadataResolver.ts index 036f5b0788..3837140857 100644 --- a/src/resolve/metadataResolver.ts +++ b/src/resolve/metadataResolver.ts @@ -357,7 +357,7 @@ const resolveType = // It is likely that the metadata file is misspelled or has the wrong suffix. // A common occurrence is that a misspelled metadata file will fall back to // `EmailServicesFunction` because that is the default for the `.xml` suffix - if (resolvedType?.strictDirectoryName === true) { + if (resolvedType?.strictDirectoryName === true && !fsPath.split(sep).includes(resolvedType.directoryName)) { resolvedType = undefined; } } diff --git a/test/resolve/metadataResolver.test.ts b/test/resolve/metadataResolver.test.ts index 529dd73670..3bc49202cc 100644 --- a/test/resolve/metadataResolver.test.ts +++ b/test/resolve/metadataResolver.test.ts @@ -22,12 +22,14 @@ import { createSandbox } from 'sinon'; import { ComponentSet, MetadataResolver, + presetMap, registry, RegistryAccess, SourceComponent, VirtualDirectory, VirtualTreeContainer, } from '../../src'; +import { getEffectiveRegistry } from '../../src/registry/variants'; import { bundle, decomposedtoplevel, @@ -1044,4 +1046,30 @@ describe('MetadataResolver', () => { expect(components[0].name).to.equal('myComponent'); }); }); + + describe('decomposeExternalServiceRegistrationBeta preset', () => { + const esrRegistry = new RegistryAccess( + getEffectiveRegistry({ presets: [presetMap.get('decomposeExternalServiceRegistrationBeta')!] }) + ); + + it('should not resolve a .yaml file outside externalServiceRegistrations as ExternalServiceRegistration', () => { + const yamlPath = join('force-app', 'main', 'default', 'customMetadata', 'stateTransition', 'transitions.yaml'); + const tree = VirtualTreeContainer.fromFilePaths([yamlPath]); + const resolver = new MetadataResolver(esrRegistry, tree, false); + + expect(() => resolver.getComponentsFromPath(yamlPath)).to.throw('Could not infer a metadata type'); + }); + + it('should resolve a .yaml file inside externalServiceRegistrations as ExternalServiceRegistration', () => { + const esrDir = join('force-app', 'main', 'default', 'externalServiceRegistrations'); + const yamlPath = join(esrDir, 'MyService.yaml'); + const metaPath = join(esrDir, 'MyService.externalServiceRegistration-meta.xml'); + const tree = VirtualTreeContainer.fromFilePaths([yamlPath, metaPath]); + const resolver = new MetadataResolver(esrRegistry, tree, false); + + const components = resolver.getComponentsFromPath(yamlPath); + expect(components).to.have.lengthOf(1); + expect(components[0].type.name).to.equal('ExternalServiceRegistration'); + }); + }); });