Skip to content

Commit f4e4754

Browse files
fix: restrict yaml suffix resolution to externalServiceRegistrations directory @W-20424423@
The decomposeExternalServiceRegistrationBeta preset registered `.yaml` as a global suffix, causing all .yaml files to be inferred as ExternalServiceRegistration regardless of location. The fix adds `strictDirectoryName: true` to the yaml child type and refines the suffix-based resolution guard to only reject types when the file is NOT in the expected directory.
1 parent 851677c commit f4e4754

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/registry/presets/decomposeExternalServiceRegistrationBeta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"id": "yaml",
1212
"isAddressable": false,
1313
"name": "OAS Yaml Schema",
14+
"strictDirectoryName": true,
1415
"suffix": "yaml",
1516
"xmlElementName": "schema"
1617
}

src/resolve/metadataResolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ const resolveType =
357357
// It is likely that the metadata file is misspelled or has the wrong suffix.
358358
// A common occurrence is that a misspelled metadata file will fall back to
359359
// `EmailServicesFunction` because that is the default for the `.xml` suffix
360-
if (resolvedType?.strictDirectoryName === true) {
360+
if (resolvedType?.strictDirectoryName === true && !fsPath.split(sep).includes(resolvedType.directoryName)) {
361361
resolvedType = undefined;
362362
}
363363
}

test/resolve/metadataResolver.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ import { createSandbox } from 'sinon';
2222
import {
2323
ComponentSet,
2424
MetadataResolver,
25+
presetMap,
2526
registry,
2627
RegistryAccess,
2728
SourceComponent,
2829
VirtualDirectory,
2930
VirtualTreeContainer,
3031
} from '../../src';
32+
import { getEffectiveRegistry } from '../../src/registry/variants';
3133
import {
3234
bundle,
3335
decomposedtoplevel,
@@ -1044,4 +1046,30 @@ describe('MetadataResolver', () => {
10441046
expect(components[0].name).to.equal('myComponent');
10451047
});
10461048
});
1049+
1050+
describe('decomposeExternalServiceRegistrationBeta preset', () => {
1051+
const esrRegistry = new RegistryAccess(
1052+
getEffectiveRegistry({ presets: [presetMap.get('decomposeExternalServiceRegistrationBeta')!] })
1053+
);
1054+
1055+
it('should not resolve a .yaml file outside externalServiceRegistrations as ExternalServiceRegistration', () => {
1056+
const yamlPath = join('force-app', 'main', 'default', 'customMetadata', 'stateTransition', 'transitions.yaml');
1057+
const tree = VirtualTreeContainer.fromFilePaths([yamlPath]);
1058+
const resolver = new MetadataResolver(esrRegistry, tree, false);
1059+
1060+
expect(() => resolver.getComponentsFromPath(yamlPath)).to.throw('Could not infer a metadata type');
1061+
});
1062+
1063+
it('should resolve a .yaml file inside externalServiceRegistrations as ExternalServiceRegistration', () => {
1064+
const esrDir = join('force-app', 'main', 'default', 'externalServiceRegistrations');
1065+
const yamlPath = join(esrDir, 'MyService.yaml');
1066+
const metaPath = join(esrDir, 'MyService.externalServiceRegistration-meta.xml');
1067+
const tree = VirtualTreeContainer.fromFilePaths([yamlPath, metaPath]);
1068+
const resolver = new MetadataResolver(esrRegistry, tree, false);
1069+
1070+
const components = resolver.getComponentsFromPath(yamlPath);
1071+
expect(components).to.have.lengthOf(1);
1072+
expect(components[0].type.name).to.equal('ExternalServiceRegistration');
1073+
});
1074+
});
10471075
});

0 commit comments

Comments
 (0)