Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(resolver): ignore non-component XML files in project #1452

Merged
merged 4 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for an XML file, suffixType would return the emailservicesfunction entry:

"xml": "emailservicesfunction",


// 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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if registry.getTypeBySuffix entry didn't match, check for strictFolderTypes.

snapshot tests caught an issue with CustomSite where getTypeBySuffix would return sitedotcom (no match with the directoryName), this will return the strict folder types -> find if one with directoryName and suffix matches (and isn't suffixType).

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
Loading