Skip to content

Commit

Permalink
fix(resolver): ignore non-component XML files in project (#1452)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
cristiand391 and shetzel authored Nov 5, 2024
1 parent 60e5fcc commit 36ea522
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/resolve/metadataResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,21 @@ const resolveType =
*/
const parseAsContentMetadataXml =
(registry: RegistryAccess) =>
(fsPath: string): boolean =>
Boolean(registry.getTypeBySuffix(extName(fsPath)));
(fsPath: string): boolean => {
const suffixType = registry.getTypeBySuffix(extName(fsPath));
if (!suffixType) return false;

const matchesSuffixType = fsPath.split(sep).includes(suffixType.directoryName);
if (matchesSuffixType) return matchesSuffixType;

// it might be a type that requires strict parent folder name.
const strictFolderSuffixType = registry
.getStrictFolderTypes()
.find((l) => l.suffix === suffixType.suffix && l.directoryName && l.name !== suffixType.name);
if (!strictFolderSuffixType) return false;

return fsPath.split(sep).includes(strictFolderSuffixType.directoryName);
};

/**
* If this file should be considered as a metadata file then return the metadata type
Expand Down
18 changes: 18 additions & 0 deletions test/resolve/metadataResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,24 @@ describe('MetadataResolver', () => {
expect(access.getComponentsFromPath(path).length).to.equal(0);
});

it('Should not throw TypeInferenceError for a non-metadata file that is not part of an inclusive filter', () => {
const emailservicesPath = join('unpackaged', 'emailservices', 'MyEmailServices.xml');
const nonMetadataDirPath = join('unpackaged', 'datasets');
const nonMetadataFilePath = join(nonMetadataDirPath, 'myDS.xml');
const emailservicesComponent = new SourceComponent(
{
name: 'MyEmailServices',
type: registry.types.emailservicesfunction,
xml: emailservicesPath,
},
VirtualTreeContainer.fromFilePaths([emailservicesPath])
);
const filter = new ComponentSet([emailservicesComponent]);
const treeContainer = VirtualTreeContainer.fromFilePaths([emailservicesPath, nonMetadataFilePath]);
const mdResolver = new MetadataResolver(undefined, treeContainer, false);
expect(mdResolver.getComponentsFromPath(nonMetadataDirPath, filter)).to.deep.equal([]);
});

it('Should not return a component if path to folder metadata xml is forceignored', () => {
const path = xmlInFolder.FOLDER_XML_PATH;
const access = testUtil.createMetadataResolver([
Expand Down

0 comments on commit 36ea522

Please sign in to comment.