Skip to content

Commit

Permalink
fix(lib): Component XML path parsing was failing on edge case (#37)
Browse files Browse the repository at this point in the history
* fix(lib): Component XML path parsing was failing on edge case

* Fixed search string to match what `fast-glob` supports
  • Loading branch information
lvcabral authored Dec 1, 2023
1 parent a5e0217 commit bcda693
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea/
.vscode/settings.json
lib/
types/
node_modules/
Expand Down
11 changes: 8 additions & 3 deletions src/componentprocessor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ export async function getComponentDefinitionMap(
additionalDirs: string[] = [],
libraryName: string | undefined
) {
let searchString = `{components,${additionalDirs.join(",")}}`;
let searchString = "{components, }";
if (additionalDirs.length) {
searchString = `{components,${additionalDirs.join(",")}}`;
}
const componentsPattern = path.join(rootDir, searchString, "**", "*.xml");
const xmlFiles: string[] = fg.sync(componentsPattern, {});

Expand All @@ -108,11 +111,13 @@ async function processXmlTree(
// create map of just ComponentDefinition objects
nodeDefs.map((item) => {
if (item.isFulfilled && !item.isRejected) {
let name = item.value!.name!.toLowerCase();
let name = item.value?.name?.toLowerCase();
if (libraryName) {
name = `${libraryName.toLowerCase()}:${name}`;
}
nodeDefMap.set(name, item.value!);
if (name) {
nodeDefMap.set(name, item.value!);
}
}
});

Expand Down
2 changes: 1 addition & 1 deletion test/componentprocessor/componentprocessor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("component parsing support", () => {

it("only searches components if no custom directories", async () => {
fg.sync.mockImplementation((pattern, options) => {
expect(pattern.includes("{components,}")).toBeTruthy();
expect(pattern.includes("{components, }")).toBeTruthy();
return [];
});

Expand Down

0 comments on commit bcda693

Please sign in to comment.