Skip to content

Commit 46c15ba

Browse files
authored
fix: set sourceApiVersion on the ComponentSet (#147)
* fix: set sourceApiVersion on the ComponentSet * fix: convert now supports sourceApiVersion * fix: update with latest SDR release
1 parent 113f48d commit 46c15ba

File tree

11 files changed

+100
-23
lines changed

11 files changed

+100
-23
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": "^3.1.3",
1010
"@salesforce/core": "^2.23.4",
11-
"@salesforce/source-deploy-retrieve": "^3.1.1",
11+
"@salesforce/source-deploy-retrieve": "^4.0.0",
1212
"chalk": "^4.1.0",
1313
"cli-ux": "^5.5.1",
1414
"tslib": "^2"

src/commands/force/source/convert.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export class Convert extends SourceCommand {
8181
}
8282

8383
this.componentSet = await ComponentSetBuilder.build({
84+
sourceapiversion: await this.getSourceApiVersion(),
8485
sourcepath: paths,
8586
manifest: manifest && {
8687
manifestPath: this.getFlag<string>('manifest'),
@@ -93,7 +94,7 @@ export class Convert extends SourceCommand {
9394
});
9495

9596
const converter = new MetadataConverter();
96-
this.convertResult = await converter.convert(this.componentSet.getSourceComponents().toArray(), 'metadata', {
97+
this.convertResult = await converter.convert(this.componentSet, 'metadata', {
9798
type: 'directory',
9899
outputDirectory: this.getFlag<string>('outputdir'),
99100
packageName: this.getFlag<string>('packagename'),

src/commands/force/source/deploy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ export class Deploy extends DeployCommand {
127127
} else {
128128
this.componentSet = await ComponentSetBuilder.build({
129129
apiversion: this.getFlag<string>('apiversion'),
130+
sourceapiversion: await this.getSourceApiVersion(),
130131
sourcepath: this.getFlag<string[]>('sourcepath'),
131132
manifest: this.flags.manifest && {
132133
manifestPath: this.getFlag<string>('manifest'),

src/commands/force/source/retrieve.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export class Retrieve extends SourceCommand {
7171
protected async retrieve(): Promise<void> {
7272
this.componentSet = await ComponentSetBuilder.build({
7373
apiversion: this.getFlag<string>('apiversion'),
74+
sourceapiversion: await this.getSourceApiVersion(),
7475
packagenames: this.getFlag<string[]>('packagenames'),
7576
sourcepath: this.getFlag<string[]>('sourcepath'),
7677
manifest: this.flags.manifest && {
@@ -89,7 +90,7 @@ export class Retrieve extends SourceCommand {
8990
usernameOrConnection: this.org.getUsername(),
9091
merge: true,
9192
output: this.project.getDefaultPackage().fullPath,
92-
packageNames: this.getFlag<string[]>('packagenames'),
93+
packageOptions: this.getFlag<string[]>('packagenames'),
9394
});
9495

9596
this.retrieveResult = await mdapiRetrieve.pollStatus(1000, this.getFlag<Duration>('wait').seconds);

src/componentSetBuilder.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export type ComponentSetOptions = {
2424
manifest?: ManifestOption;
2525
metadata?: MetadataOption;
2626
apiversion?: string;
27+
sourceapiversion?: string;
2728
};
2829

2930
export class ComponentSetBuilder {
@@ -39,7 +40,7 @@ export class ComponentSetBuilder {
3940
const logger = Logger.childFromRoot('createComponentSet');
4041
const csAggregator: ComponentLike[] = [];
4142

42-
const { sourcepath, manifest, metadata, packagenames, apiversion } = options;
43+
const { sourcepath, manifest, metadata, packagenames, apiversion, sourceapiversion } = options;
4344

4445
if (sourcepath) {
4546
logger.debug(`Building ComponentSet from sourcepath: ${sourcepath.toString()}`);
@@ -122,6 +123,10 @@ export class ComponentSetBuilder {
122123
componentSet.apiVersion = apiversion;
123124
}
124125

126+
if (sourceapiversion) {
127+
componentSet.sourceApiVersion = sourceapiversion;
128+
}
129+
125130
return componentSet;
126131
}
127132
}

src/sourceCommand.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import { SfdxCommand } from '@salesforce/command';
99
import { Lifecycle } from '@salesforce/core';
1010
import { ComponentSet } from '@salesforce/source-deploy-retrieve';
11-
import { get, getBoolean } from '@salesforce/ts-types';
11+
import { get, getBoolean, getString, Optional } from '@salesforce/ts-types';
1212
import cli from 'cli-ux';
1313

1414
export type ProgressBar = {
@@ -58,6 +58,11 @@ export abstract class SourceCommand extends SfdxCommand {
5858
return this.project.getUniquePackageDirectories().map((pDir) => pDir.fullPath);
5959
}
6060

61+
protected async getSourceApiVersion(): Promise<Optional<string>> {
62+
const projectConfig = await this.project.resolveProjectConfig();
63+
return getString(projectConfig, 'sourceApiVersion');
64+
}
65+
6166
/**
6267
* Inspects the command response to determine success.
6368
*

test/commands/source/componentSetBuilder.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,24 @@ describe('ComponentSetBuilder', () => {
104104
expect(compSet.apiVersion).to.equal(options.apiversion);
105105
});
106106

107+
it('should create ComponentSet with sourceApiVersion', async () => {
108+
fileExistsSyncStub.returns(true);
109+
fromSourceStub.returns(componentSet);
110+
const sourcepath = ['force-app'];
111+
const options = {
112+
sourcepath,
113+
manifest: undefined,
114+
metadata: undefined,
115+
sourceapiversion: '50.0',
116+
};
117+
118+
const compSet = await ComponentSetBuilder.build(options);
119+
const expectedPath = path.resolve(sourcepath[0]);
120+
expect(fromSourceStub.calledOnceWith(expectedPath)).to.equal(true);
121+
expect(compSet.size).to.equal(0);
122+
expect(compSet.sourceApiVersion).to.equal(options.sourceapiversion);
123+
});
124+
107125
it('should throw with an invalid sourcepath', async () => {
108126
fileExistsSyncStub.returns(false);
109127
const sourcepath = ['nonexistent'];

test/commands/source/convert.test.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ describe('force:source:convert', () => {
2424
const myApp = join('new', 'package', 'directory');
2525
const packageXml = 'package.xml';
2626
const oclifConfigStub = fromStub(stubInterface<IConfig>(sandbox));
27+
let resolveProjectConfigStub: sinon.SinonStub;
2728

2829
class TestConvert extends Convert {
2930
public async runIt() {
@@ -42,6 +43,7 @@ describe('force:source:convert', () => {
4243
stubInterface<SfdxProject>(sandbox, {
4344
getDefaultPackage: () => ({ path: defaultDir }),
4445
getUniquePackageDirectories: () => [{ fullPath: defaultDir }],
46+
resolveProjectConfig: resolveProjectConfigStub,
4547
})
4648
);
4749
cmd.setProject(sfdxProjectStub);
@@ -56,6 +58,7 @@ describe('force:source:convert', () => {
5658
sourcepath: [],
5759
manifest: undefined,
5860
metadata: undefined,
61+
sourceapiversion: undefined,
5962
};
6063
const expectedArgs = { ...defaultArgs, ...overrides };
6164

@@ -64,15 +67,11 @@ describe('force:source:convert', () => {
6467
};
6568

6669
beforeEach(() => {
70+
resolveProjectConfigStub = sandbox.stub();
6771
sandbox.stub(MetadataConverter.prototype, 'convert').resolves({ packagePath: 'temp' });
6872
buildComponentSetStub = stubMethod(sandbox, ComponentSetBuilder, 'build').resolves({
6973
deploy: sinon.stub(),
7074
getPackageXml: () => packageXml,
71-
getSourceComponents: () => {
72-
return {
73-
toArray: () => {},
74-
};
75-
},
7675
});
7776
});
7877

@@ -87,6 +86,17 @@ describe('force:source:convert', () => {
8786
ensureCreateComponentSetArgs({ sourcepath: [sourcepath] });
8887
});
8988

89+
it('should pass along sourceApiVersion', async () => {
90+
const sourceApiVersion = '50.0';
91+
resolveProjectConfigStub.resolves({ sourceApiVersion });
92+
const result = await runConvertCmd(['--json']);
93+
expect(result).to.deep.equal({ location: resolve('temp') });
94+
ensureCreateComponentSetArgs({
95+
sourcepath: [defaultDir],
96+
sourceapiversion: sourceApiVersion,
97+
});
98+
});
99+
90100
it('should call default package dir if no args', async () => {
91101
const result = await runConvertCmd(['--json']);
92102
expect(result).to.deep.equal({ location: resolve('temp') });

test/commands/source/deploy.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ describe('force:source:deploy', () => {
6262
let pollStub: sinon.SinonStub;
6363
let lifecycleEmitStub: sinon.SinonStub;
6464
let formatterDisplayStub: sinon.SinonStub;
65+
let resolveProjectConfigStub: sinon.SinonStub;
6566

6667
class TestDeploy extends Deploy {
6768
public async runIt() {
@@ -82,6 +83,7 @@ describe('force:source:deploy', () => {
8283
const sfdxProjectStub = fromStub(
8384
stubInterface<SfdxProject>(sandbox, {
8485
getUniquePackageDirectories: () => [{ fullPath: defaultDir }],
86+
resolveProjectConfig: resolveProjectConfigStub,
8587
})
8688
);
8789
cmd.setProject(sfdxProjectStub);
@@ -103,6 +105,7 @@ describe('force:source:deploy', () => {
103105
};
104106

105107
beforeEach(() => {
108+
resolveProjectConfigStub = sandbox.stub();
106109
pollStub = sandbox.stub().resolves(deployResult);
107110
deployStub = sandbox.stub().resolves({
108111
pollStatus: pollStub,
@@ -129,6 +132,7 @@ describe('force:source:deploy', () => {
129132
manifest: undefined,
130133
metadata: undefined,
131134
apiversion: undefined,
135+
sourceapiversion: undefined,
132136
};
133137
const expectedArgs = { ...defaultArgs, ...overrides };
134138

@@ -229,6 +233,24 @@ describe('force:source:deploy', () => {
229233
ensureProgressBar(0);
230234
});
231235

236+
it('should pass along sourceapiversion', async () => {
237+
const sourceApiVersion = '50.0';
238+
resolveProjectConfigStub.resolves({ sourceApiVersion });
239+
const manifest = 'package.xml';
240+
const result = await runDeployCmd(['--manifest', manifest, '--json']);
241+
expect(result).to.deep.equal(expectedResults);
242+
ensureCreateComponentSetArgs({
243+
sourceapiversion: sourceApiVersion,
244+
manifest: {
245+
manifestPath: manifest,
246+
directoryPaths: [defaultDir],
247+
},
248+
});
249+
ensureDeployArgs();
250+
ensureHookArgs();
251+
ensureProgressBar(0);
252+
});
253+
232254
it('should pass along all deploy options', async () => {
233255
const manifest = 'package.xml';
234256
const runTests = ['MyClassTest'];

test/commands/source/retrieve.test.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ describe('force:source:retrieve', () => {
3939
let retrieveStub: sinon.SinonStub;
4040
let pollStub: sinon.SinonStub;
4141
let lifecycleEmitStub: sinon.SinonStub;
42-
// TODO: remove the next two stubs when reverting back to SDR polling
43-
let checkStatusStub: sinon.SinonStub;
44-
let postStub: sinon.SinonStub;
42+
let resolveProjectConfigStub: sinon.SinonStub;
4543

4644
class TestRetrieve extends Retrieve {
4745
public async runIt() {
@@ -63,6 +61,7 @@ describe('force:source:retrieve', () => {
6361
stubInterface<SfdxProject>(sandbox, {
6462
getDefaultPackage: () => ({ fullPath: defaultPackagePath }),
6563
getUniquePackageDirectories: () => [{ fullPath: defaultPackagePath }],
64+
resolveProjectConfig: resolveProjectConfigStub,
6665
})
6766
);
6867
cmd.setProject(sfdxProjectStub);
@@ -80,14 +79,11 @@ describe('force:source:retrieve', () => {
8079
};
8180

8281
beforeEach(() => {
82+
resolveProjectConfigStub = sandbox.stub();
8383
pollStub = sandbox.stub().resolves(retrieveResult);
84-
checkStatusStub = sandbox.stub().resolves(retrieveResult);
85-
postStub = sandbox.stub().resolves(retrieveResult);
8684
retrieveStub = sandbox.stub().resolves({
8785
pollStatus: pollStub,
8886
retrieveId: retrieveResult.response.id,
89-
checkStatus: checkStatusStub,
90-
post: postStub,
9187
});
9288
buildComponentSetStub = stubMethod(sandbox, ComponentSetBuilder, 'build').resolves({
9389
retrieve: retrieveStub,
@@ -111,6 +107,7 @@ describe('force:source:retrieve', () => {
111107
manifest: undefined,
112108
metadata: undefined,
113109
apiversion: undefined,
110+
sourceapiversion: undefined,
114111
};
115112
const expectedArgs = { ...defaultArgs, ...overrides };
116113

@@ -124,7 +121,7 @@ describe('force:source:retrieve', () => {
124121
usernameOrConnection: username,
125122
merge: true,
126123
output: defaultPackagePath,
127-
packageNames: undefined,
124+
packageOptions: undefined,
128125
};
129126
const expectedRetrieveArgs = { ...defaultRetrieveArgs, ...overrides };
130127

@@ -195,6 +192,23 @@ describe('force:source:retrieve', () => {
195192
ensureHookArgs();
196193
});
197194

195+
it('should pass along sourceapiversion', async () => {
196+
const sourceApiVersion = '50.0';
197+
resolveProjectConfigStub.resolves({ sourceApiVersion });
198+
const manifest = 'package.xml';
199+
const result = await runRetrieveCmd(['--manifest', manifest, '--json']);
200+
expect(result).to.deep.equal(expectedResults);
201+
ensureCreateComponentSetArgs({
202+
sourceapiversion: sourceApiVersion,
203+
manifest: {
204+
manifestPath: manifest,
205+
directoryPaths: [defaultPackagePath],
206+
},
207+
});
208+
ensureRetrieveArgs();
209+
ensureHookArgs();
210+
});
211+
198212
it('should pass along packagenames', async () => {
199213
const manifest = 'package.xml';
200214
const packagenames = ['package1'];
@@ -207,7 +221,7 @@ describe('force:source:retrieve', () => {
207221
directoryPaths: [defaultPackagePath],
208222
},
209223
});
210-
ensureRetrieveArgs({ packageNames: packagenames });
224+
ensureRetrieveArgs({ packageOptions: packagenames });
211225
ensureHookArgs();
212226
});
213227

0 commit comments

Comments
 (0)