Skip to content

Commit 36ea522

Browse files
fix(resolver): ignore non-component XML files in project (#1452)
* fix: resolver respects forceignore * fix: improve metadata detection * fix: check stric types for suffix * chore: add unit test --------- Co-authored-by: Steve Hetzel <[email protected]>
1 parent 60e5fcc commit 36ea522

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/resolve/metadataResolver.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,21 @@ const resolveType =
369369
*/
370370
const parseAsContentMetadataXml =
371371
(registry: RegistryAccess) =>
372-
(fsPath: string): boolean =>
373-
Boolean(registry.getTypeBySuffix(extName(fsPath)));
372+
(fsPath: string): boolean => {
373+
const suffixType = registry.getTypeBySuffix(extName(fsPath));
374+
if (!suffixType) return false;
375+
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);
386+
};
374387

375388
/**
376389
* If this file should be considered as a metadata file then return the metadata type

test/resolve/metadataResolver.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,24 @@ describe('MetadataResolver', () => {
458458
expect(access.getComponentsFromPath(path).length).to.equal(0);
459459
});
460460

461+
it('Should not throw TypeInferenceError for a non-metadata file that is not part of an inclusive filter', () => {
462+
const emailservicesPath = join('unpackaged', 'emailservices', 'MyEmailServices.xml');
463+
const nonMetadataDirPath = join('unpackaged', 'datasets');
464+
const nonMetadataFilePath = join(nonMetadataDirPath, 'myDS.xml');
465+
const emailservicesComponent = new SourceComponent(
466+
{
467+
name: 'MyEmailServices',
468+
type: registry.types.emailservicesfunction,
469+
xml: emailservicesPath,
470+
},
471+
VirtualTreeContainer.fromFilePaths([emailservicesPath])
472+
);
473+
const filter = new ComponentSet([emailservicesComponent]);
474+
const treeContainer = VirtualTreeContainer.fromFilePaths([emailservicesPath, nonMetadataFilePath]);
475+
const mdResolver = new MetadataResolver(undefined, treeContainer, false);
476+
expect(mdResolver.getComponentsFromPath(nonMetadataDirPath, filter)).to.deep.equal([]);
477+
});
478+
461479
it('Should not return a component if path to folder metadata xml is forceignored', () => {
462480
const path = xmlInFolder.FOLDER_XML_PATH;
463481
const access = testUtil.createMetadataResolver([

0 commit comments

Comments
 (0)