From 36ea522ff441486b3d9e7f55e60f1607e42998fc Mon Sep 17 00:00:00 2001 From: Cristian Dominguez <6853656+cristiand391@users.noreply.github.com> Date: Mon, 4 Nov 2024 23:01:47 -0300 Subject: [PATCH] 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 --- src/resolve/metadataResolver.ts | 17 +++++++++++++++-- test/resolve/metadataResolver.test.ts | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/resolve/metadataResolver.ts b/src/resolve/metadataResolver.ts index a70dabc4c..7c325a6c4 100644 --- a/src/resolve/metadataResolver.ts +++ b/src/resolve/metadataResolver.ts @@ -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 diff --git a/test/resolve/metadataResolver.test.ts b/test/resolve/metadataResolver.test.ts index 81fb752f1..ae693ceb0 100644 --- a/test/resolve/metadataResolver.test.ts +++ b/test/resolve/metadataResolver.test.ts @@ -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([