Skip to content

Commit 3e542c3

Browse files
authored
fix: wildcard metadata retrieves will now fetch source not in the project (#177)
* fix: wildcard retrieves will now fetch source not in the project * chore: bump SDR to 4.1.1 * chore: update manifest create NUT for SDR changes
1 parent e0f1d08 commit 3e542c3

File tree

5 files changed

+43
-38
lines changed

5 files changed

+43
-38
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"@oclif/config": "^1",
99
"@salesforce/command": "^4.0.4",
1010
"@salesforce/core": "^2.26.1",
11-
"@salesforce/source-deploy-retrieve": "^4.1.0",
11+
"@salesforce/source-deploy-retrieve": "^4.1.1",
1212
"chalk": "^4.1.1",
1313
"cli-ux": "^5.6.3",
1414
"open": "^8.2.1",

src/componentSetBuilder.ts

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import * as path from 'path';
99
import { ComponentSet, RegistryAccess } from '@salesforce/source-deploy-retrieve';
10-
import { ComponentLike } from '@salesforce/source-deploy-retrieve/lib/src/resolve/types';
1110
import { fs, SfdxError, Logger } from '@salesforce/core';
1211

1312
export type ManifestOption = {
@@ -38,64 +37,69 @@ export class ComponentSetBuilder {
3837
*/
3938
public static async build(options: ComponentSetOptions): Promise<ComponentSet> {
4039
const logger = Logger.childFromRoot('createComponentSet');
41-
const csAggregator: ComponentLike[] = [];
40+
let componentSet: ComponentSet;
4241

4342
const { sourcepath, manifest, metadata, packagenames, apiversion, sourceapiversion } = options;
4443
try {
4544
if (sourcepath) {
4645
logger.debug(`Building ComponentSet from sourcepath: ${sourcepath.toString()}`);
46+
const fsPaths: string[] = [];
4747
sourcepath.forEach((filepath) => {
48-
if (fs.fileExistsSync(filepath)) {
49-
csAggregator.push(...ComponentSet.fromSource(path.resolve(filepath)));
50-
} else {
48+
if (!fs.fileExistsSync(filepath)) {
5149
throw new SfdxError(`The sourcepath "${filepath}" is not a valid source file path.`);
5250
}
51+
fsPaths.push(path.resolve(filepath));
5352
});
53+
componentSet = ComponentSet.fromSource({ fsPaths });
5454
}
5555

5656
// Return empty ComponentSet and use packageNames in the library via `.retrieve` options
5757
if (packagenames) {
5858
logger.debug(`Building ComponentSet for packagenames: ${packagenames.toString()}`);
59-
csAggregator.push(...new ComponentSet([]));
59+
componentSet ??= new ComponentSet();
6060
}
6161

6262
// Resolve manifest with source in package directories.
6363
if (manifest) {
6464
logger.debug(`Building ComponentSet from manifest: ${manifest.manifestPath}`);
6565
const directoryPaths = options.manifest.directoryPaths;
6666
logger.debug(`Searching in packageDir: ${directoryPaths.join(', ')} for matching metadata`);
67-
const compSet = await ComponentSet.fromManifest({
67+
componentSet = await ComponentSet.fromManifest({
6868
manifestPath: manifest.manifestPath,
6969
resolveSourcePaths: options.manifest.directoryPaths,
7070
forceAddWildcards: true,
7171
});
72-
csAggregator.push(...compSet);
7372
}
7473

7574
// Resolve metadata entries with source in package directories.
7675
if (metadata) {
7776
logger.debug(`Building ComponentSet from metadata: ${metadata.metadataEntries.toString()}`);
7877
const registry = new RegistryAccess();
78+
const compSetFilter = new ComponentSet();
79+
componentSet ??= new ComponentSet();
7980

8081
// Build a Set of metadata entries
81-
const filter = new ComponentSet();
82-
metadata.metadataEntries.forEach((entry) => {
83-
const splitEntry = entry.split(':');
84-
// try and get the type by name to ensure no typos or errors in type name
85-
// matches toolbelt functionality
82+
metadata.metadataEntries.forEach((rawEntry) => {
83+
const splitEntry = rawEntry.split(':');
84+
// The registry will throw if it doesn't know what this type is.
8685
registry.getTypeByName(splitEntry[0]);
87-
filter.add({
86+
const entry = {
8887
type: splitEntry[0],
8988
fullName: splitEntry.length === 1 ? '*' : splitEntry[1],
90-
});
89+
};
90+
// Add to the filtered ComponentSet for resolved source paths,
91+
// and the unfiltered ComponentSet to build the correct manifest.
92+
compSetFilter.add(entry);
93+
componentSet.add(entry);
9194
});
9295

9396
const directoryPaths = options.metadata.directoryPaths;
9497
logger.debug(`Searching for matching metadata in directories: ${directoryPaths.join(', ')}`);
95-
const fromSource = ComponentSet.fromSource({ fsPaths: directoryPaths, include: filter });
96-
// If no matching metadata is found, default to the original component set
97-
const finalized = fromSource.size > 0 ? fromSource : filter;
98-
csAggregator.push(...finalized);
98+
const resolvedComponents = ComponentSet.fromSource({ fsPaths: directoryPaths, include: compSetFilter });
99+
componentSet.forceIgnoredPaths = resolvedComponents.forceIgnoredPaths;
100+
for (const comp of resolvedComponents) {
101+
componentSet.add(comp);
102+
}
99103
}
100104
} catch (e) {
101105
if ((e as Error).message.includes('Missing metadata type definition in registry for id')) {
@@ -108,8 +112,6 @@ export class ComponentSetBuilder {
108112
}
109113
}
110114

111-
const componentSet = new ComponentSet(csAggregator);
112-
113115
// This is only for debug output of matched files based on the command flags.
114116
// It will log up to 20 file matches.
115117
if (logger.debugEnabled && componentSet.size) {

test/commands/source/componentSetBuilder.test.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ describe('ComponentSetBuilder', () => {
5858
metadata: undefined,
5959
});
6060

61-
const expectedPath = path.resolve(sourcepath[0]);
62-
expect(fromSourceStub.calledOnceWith(expectedPath)).to.equal(true);
61+
const expectedArg = { fsPaths: [path.resolve(sourcepath[0])] };
62+
expect(fromSourceStub.calledOnceWith(expectedArg)).to.equal(true);
6363
expect(compSet.size).to.equal(1);
6464
expect(compSet.has(apexClassComponent)).to.equal(true);
6565
});
@@ -78,9 +78,8 @@ describe('ComponentSetBuilder', () => {
7878
});
7979
const expectedPath1 = path.resolve(sourcepath[0]);
8080
const expectedPath2 = path.resolve(sourcepath[1]);
81-
expect(fromSourceStub.calledTwice).to.equal(true);
82-
expect(fromSourceStub.firstCall.args[0]).to.equal(expectedPath1);
83-
expect(fromSourceStub.secondCall.args[0]).to.equal(expectedPath2);
81+
const expectedArg = { fsPaths: [expectedPath1, expectedPath2] };
82+
expect(fromSourceStub.calledOnceWith(expectedArg)).to.equal(true);
8483
expect(compSet.size).to.equal(2);
8584
expect(compSet.has(apexClassComponent)).to.equal(true);
8685
expect(compSet.has(customObjectComponent)).to.equal(true);
@@ -98,8 +97,8 @@ describe('ComponentSetBuilder', () => {
9897
};
9998

10099
const compSet = await ComponentSetBuilder.build(options);
101-
const expectedPath = path.resolve(sourcepath[0]);
102-
expect(fromSourceStub.calledOnceWith(expectedPath)).to.equal(true);
100+
const expectedArg = { fsPaths: [path.resolve(sourcepath[0])] };
101+
expect(fromSourceStub.calledOnceWith(expectedArg)).to.equal(true);
103102
expect(compSet.size).to.equal(0);
104103
expect(compSet.apiVersion).to.equal(options.apiversion);
105104
});
@@ -116,8 +115,8 @@ describe('ComponentSetBuilder', () => {
116115
};
117116

118117
const compSet = await ComponentSetBuilder.build(options);
119-
const expectedPath = path.resolve(sourcepath[0]);
120-
expect(fromSourceStub.calledOnceWith(expectedPath)).to.equal(true);
118+
const expectedArg = { fsPaths: [path.resolve(sourcepath[0])] };
119+
expect(fromSourceStub.calledOnceWith(expectedArg)).to.equal(true);
121120
expect(compSet.size).to.equal(0);
122121
expect(compSet.sourceApiVersion).to.equal(options.sourceapiversion);
123122
});
@@ -173,8 +172,9 @@ describe('ComponentSetBuilder', () => {
173172
filter.add({ type: 'ApexClass', fullName: '*' });
174173
expect(fromSourceArgs).to.have.property('include');
175174
expect(fromSourceArgs.include.getSourceComponents()).to.deep.equal(filter.getSourceComponents());
176-
expect(compSet.size).to.equal(1);
175+
expect(compSet.size).to.equal(2);
177176
expect(compSet.has(apexClassComponent)).to.equal(true);
177+
expect(compSet.has({ type: 'ApexClass', fullName: '*' })).to.equal(true);
178178
});
179179

180180
it('should throw an error when it cant resolve a metadata type (Metadata)', async () => {
@@ -242,9 +242,10 @@ describe('ComponentSetBuilder', () => {
242242
filter.add({ type: 'CustomObject', fullName: '*' });
243243
expect(fromSourceArgs).to.have.property('include');
244244
expect(fromSourceArgs.include.getSourceComponents()).to.deep.equal(filter.getSourceComponents());
245-
expect(compSet.size).to.equal(2);
245+
expect(compSet.size).to.equal(3);
246246
expect(compSet.has(apexClassComponent)).to.equal(true);
247247
expect(compSet.has(customObjectComponent)).to.equal(true);
248+
expect(compSet.has({ type: 'CustomObject', fullName: '*' })).to.equal(true);
248249
});
249250

250251
it('should create ComponentSet from metadata and multiple package directories', async () => {
@@ -270,9 +271,10 @@ describe('ComponentSetBuilder', () => {
270271
filter.add({ type: 'ApexClass', fullName: '*' });
271272
expect(fromSourceArgs).to.have.property('include');
272273
expect(fromSourceArgs.include.getSourceComponents()).to.deep.equal(filter.getSourceComponents());
273-
expect(compSet.size).to.equal(2);
274+
expect(compSet.size).to.equal(3);
274275
expect(compSet.has(apexClassComponent)).to.equal(true);
275276
expect(compSet.has(apexClassComponent2)).to.equal(true);
277+
expect(compSet.has({ type: 'ApexClass', fullName: '*' })).to.equal(true);
276278
});
277279

278280
it('should create ComponentSet from manifest', async () => {

test/nuts/create.nut.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const apexManifest =
1616
'<?xml version="1.0" encoding="UTF-8"?>\n' +
1717
'<Package xmlns="http://soap.sforce.com/2006/04/metadata">\n' +
1818
' <types>\n' +
19+
' <members>*</members>\n' +
1920
' <members>GeocodingService</members>\n' +
2021
' <members>GeocodingServiceTest</members>\n' +
2122
' <members>PagedResult</members>\n' +

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -843,10 +843,10 @@
843843
unzipper "0.10.11"
844844
xmldom-sfdx-encoding "^0.1.29"
845845

846-
"@salesforce/source-deploy-retrieve@^4.1.0":
847-
version "4.1.0"
848-
resolved "https://registry.npmjs.org/@salesforce/source-deploy-retrieve/-/source-deploy-retrieve-4.1.0.tgz#b28b8e1c9c810884315c564751e8854c4e1e16d3"
849-
integrity sha512-dLdCNs8KZl2AlI5nxzqjPFTt/RiOQqlbIFsmsbnY/i0Vk15/Fqyxu1cBU0stV3+NxHYV/ijzz2jRVq87G7+jRg==
846+
"@salesforce/source-deploy-retrieve@^4.1.1":
847+
version "4.1.1"
848+
resolved "https://registry.yarnpkg.com/@salesforce/source-deploy-retrieve/-/source-deploy-retrieve-4.1.1.tgz#8c5b23cec488dcd4aea5e15df49e014bf00a7929"
849+
integrity sha512-tfuPtmdtWU/1HwuB+ZM6gvCXUBZh+XOiBLPz98KU3khKi81CRnJyXQCL+tiBZpIwzGaQV1emOIZD2WsjTEY9oA==
850850
dependencies:
851851
"@salesforce/core" "2.25.1"
852852
"@salesforce/kit" "^1.5.0"

0 commit comments

Comments
 (0)