Skip to content

Commit

Permalink
fix: md names handle spaces, colons, and both
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Apr 25, 2024
1 parent ace734e commit c0941dd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/collections/componentSetBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,16 @@ export const entryToTypeAndName =
(reg: RegistryAccess) =>
(rawEntry: string): MetadataTypeAndMetadataName => {
// split on the first colon, and then join the rest back together to support names that include colons
const [typeName, ...name] = rawEntry.split(':').map((entry) => entry.trim());
const type = reg.getTypeByName(typeName);
const parent = reg.getParentType(typeName);
const [typeName, ...name] = rawEntry.split(':');
const type = reg.getTypeByName(typeName.trim());
const parent = reg.getParentType(type.name);
// If a user is requesting a child type that is unaddressable (more common with custom registries to create proper behavior)
// throw an error letting them know to use the entire parent instead
// or if they're requesting a COFT, unadressable without parent, don't throw because the parent could be requested - we don't know at this point
if (type.isAddressable === false && parent !== undefined && !type.unaddressableWithoutParent) {
throw new Error(`Cannot use this type, instead use ${parent.name}`);
}
return { type, metadataName: name.length ? name.join(':') : '*' };
return { type, metadataName: name.length ? name.join(':').trim() : '*' };
};

const typeAndNameToMetadataComponents =
Expand Down
30 changes: 30 additions & 0 deletions test/collections/componentSetBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,4 +546,34 @@ describe('entryToTypeAndName', () => {
metadataName: '*',
});
});
it('leading spaces in name are trimmed', () => {
expect(entryToTypeAndName(reg)('Layout: My Layout')).to.deep.equal({
type: reg.getTypeByName('Layout'),
metadataName: 'My Layout',
});
});
it('trailing spaces in name are trimmed', () => {
expect(entryToTypeAndName(reg)('Layout:My Layout ')).to.deep.equal({
type: reg.getTypeByName('Layout'),
metadataName: 'My Layout',
});
});
it('spaces in name', () => {
expect(entryToTypeAndName(reg)('Layout:My Layout')).to.deep.equal({
type: reg.getTypeByName('Layout'),
metadataName: 'My Layout',
});
});
it('colons in name', () => {
expect(entryToTypeAndName(reg)('Layout:My:Colon:Layout')).to.deep.equal({
type: reg.getTypeByName('Layout'),
metadataName: 'My:Colon:Layout',
});
});
it('colons and spaces in name', () => {
expect(entryToTypeAndName(reg)('Layout:My : Colon : Layout')).to.deep.equal({
type: reg.getTypeByName('Layout'),
metadataName: 'My : Colon : Layout',
});
});
});

2 comments on commit c0941dd

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: c0941dd Previous: 153feb1 Ratio
eda-componentSetCreate-linux 182 ms 190 ms 0.96
eda-sourceToMdapi-linux 1945 ms 1990 ms 0.98
eda-sourceToZip-linux 1420 ms 1411 ms 1.01
eda-mdapiToSource-linux 2735 ms 2850 ms 0.96
lotsOfClasses-componentSetCreate-linux 361 ms 386 ms 0.94
lotsOfClasses-sourceToMdapi-linux 3753 ms 3780 ms 0.99
lotsOfClasses-sourceToZip-linux 3030 ms 3121 ms 0.97
lotsOfClasses-mdapiToSource-linux 3485 ms 3577 ms 0.97
lotsOfClassesOneDir-componentSetCreate-linux 630 ms 637 ms 0.99
lotsOfClassesOneDir-sourceToMdapi-linux 6534 ms 6607 ms 0.99
lotsOfClassesOneDir-sourceToZip-linux 5633 ms 5883 ms 0.96
lotsOfClassesOneDir-mdapiToSource-linux 6311 ms 6386 ms 0.99

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: c0941dd Previous: 153feb1 Ratio
eda-componentSetCreate-win32 407 ms 383 ms 1.06
eda-sourceToMdapi-win32 3614 ms 3543 ms 1.02
eda-sourceToZip-win32 2162 ms 2124 ms 1.02
eda-mdapiToSource-win32 6384 ms 5719 ms 1.12
lotsOfClasses-componentSetCreate-win32 832 ms 853 ms 0.98
lotsOfClasses-sourceToMdapi-win32 7547 ms 7589 ms 0.99
lotsOfClasses-sourceToZip-win32 4756 ms 4842 ms 0.98
lotsOfClasses-mdapiToSource-win32 7490 ms 7400 ms 1.01
lotsOfClassesOneDir-componentSetCreate-win32 1504 ms 1512 ms 0.99
lotsOfClassesOneDir-sourceToMdapi-win32 14047 ms 13853 ms 1.01
lotsOfClassesOneDir-sourceToZip-win32 9098 ms 8936 ms 1.02
lotsOfClassesOneDir-mdapiToSource-win32 13951 ms 13688 ms 1.02

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.