Skip to content

Commit 2011caa

Browse files
fix: trim metadata type, and name to prevent unnecessary errors (#179)
* fix: trim metadata type, and name to prevent unnecessary errors * chore: map and trim
1 parent 25c8201 commit 2011caa

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/componentSetBuilder.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class ComponentSetBuilder {
8080

8181
// Build a Set of metadata entries
8282
metadata.metadataEntries.forEach((rawEntry) => {
83-
const splitEntry = rawEntry.split(':');
83+
const splitEntry = rawEntry.split(':').map((entry) => entry.trim());
8484
// The registry will throw if it doesn't know what this type is.
8585
registry.getTypeByName(splitEntry[0]);
8686
const entry = {

test/commands/source/componentSetBuilder.test.ts

+25
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,31 @@ describe('ComponentSetBuilder', () => {
177177
expect(compSet.has({ type: 'ApexClass', fullName: '*' })).to.equal(true);
178178
});
179179

180+
it('should create ComponentSet from metadata with spaces between : (ApexClass: MyApexClass)', async () => {
181+
componentSet.add(apexClassComponent);
182+
fromSourceStub.returns(componentSet);
183+
const packageDir1 = path.resolve('force-app');
184+
185+
const compSet = await ComponentSetBuilder.build({
186+
sourcepath: undefined,
187+
manifest: undefined,
188+
metadata: {
189+
metadataEntries: ['ApexClass: MyApexClass'],
190+
directoryPaths: [packageDir1],
191+
},
192+
});
193+
expect(fromSourceStub.calledOnce).to.equal(true);
194+
const fromSourceArgs = fromSourceStub.firstCall.args[0] as FromSourceOptions;
195+
expect(fromSourceArgs).to.have.deep.property('fsPaths', [packageDir1]);
196+
const filter = new ComponentSet();
197+
filter.add({ type: 'ApexClass', fullName: 'MyApexClass' });
198+
expect(fromSourceArgs).to.have.property('include');
199+
expect(fromSourceArgs.include.getSourceComponents()).to.deep.equal(filter.getSourceComponents());
200+
expect(compSet.size).to.equal(2);
201+
expect(compSet.has(apexClassComponent)).to.equal(true);
202+
expect(compSet.has({ type: 'ApexClass', fullName: 'MyApexClass' })).to.equal(true);
203+
});
204+
180205
it('should throw an error when it cant resolve a metadata type (Metadata)', async () => {
181206
const packageDir1 = path.resolve('force-app');
182207

0 commit comments

Comments
 (0)