Skip to content

Commit 21478cc

Browse files
committed
fix: resolve strict dirs before suffixes for potential metadata files
1 parent fa58e77 commit 21478cc

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

src/resolve/metadataResolver.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -370,19 +370,15 @@ const resolveType =
370370
const parseAsContentMetadataXml =
371371
(registry: RegistryAccess) =>
372372
(fsPath: string): boolean => {
373+
// just like resolveType() above, check strict folders first so we don't
374+
// have false positive matches for duplicate suffixes like "rule" or "site"
375+
const strictFolderType = resolveTypeFromStrictFolder(registry)(fsPath);
376+
if (strictFolderType) return true;
377+
373378
const suffixType = registry.getTypeBySuffix(extName(fsPath));
374379
if (!suffixType) return false;
375380

376-
const matchesSuffixType = fsPath.split(sep).includes(suffixType.directoryName);
377-
if (matchesSuffixType) return matchesSuffixType;
378-
379-
// it might be a type that requires strict parent folder name.
380-
const strictFolderSuffixType = registry
381-
.getStrictFolderTypes()
382-
.find((l) => l.suffix === suffixType.suffix && l.directoryName && l.name !== suffixType.name);
383-
if (!strictFolderSuffixType) return false;
384-
385-
return fsPath.split(sep).includes(strictFolderSuffixType.directoryName);
381+
return fsPath.split(sep).includes(suffixType.directoryName);
386382
};
387383

388384
/**

test/resolve/metadataResolver.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,29 @@ describe('MetadataResolver', () => {
476476
expect(mdResolver.getComponentsFromPath(nonMetadataDirPath, filter)).to.deep.equal([]);
477477
});
478478

479+
it('Should resolve RestrictionRules metadata in mdapi format', () => {
480+
const unpackagedPath = 'unpackaged';
481+
const packageXmlPath = join(unpackagedPath, 'package.xml');
482+
const restrictionRulesPath = join('unpackaged', 'restrictionRules');
483+
const restrictionRulePath = join(restrictionRulesPath, 'Foo.rule');
484+
const treeContainer = VirtualTreeContainer.fromFilePaths([
485+
unpackagedPath,
486+
packageXmlPath,
487+
restrictionRulesPath,
488+
restrictionRulePath,
489+
]);
490+
const restrictionRuleComponent = new SourceComponent(
491+
{
492+
name: 'Foo',
493+
type: registry.types.restrictionrule,
494+
xml: restrictionRulePath,
495+
},
496+
treeContainer
497+
);
498+
const mdResolver = new MetadataResolver(undefined, treeContainer, false);
499+
expect(mdResolver.getComponentsFromPath(unpackagedPath)).to.deep.equal([restrictionRuleComponent]);
500+
});
501+
479502
it('Should not return a component if path to folder metadata xml is forceignored', () => {
480503
const path = xmlInFolder.FOLDER_XML_PATH;
481504
const access = testUtil.createMetadataResolver([

0 commit comments

Comments
 (0)