Skip to content

Commit f720181

Browse files
authored
Merge pull request #1174 from salesforcecli/accept-dev-hub-alias
@W-21384371 Accept devhub alias and 00D char bundles
2 parents e0e6191 + 6c25047 commit f720181

3 files changed

Lines changed: 103 additions & 103 deletions

File tree

messages/bundle_install.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Install a specific version of a package bundle in the target org.
66

77
During developer preview, package bundles can be installed only in scratch orgs. To install a package bundle in a scratch org, add the PackageBundles feature to the scratch org definition file.
88

9-
# examples
9+
# examples
1010

1111
- Install a package bundle version in a scratch org and wait 10 minutes for the installation to complete:
1212

@@ -22,11 +22,11 @@ Username or alias of the org in which to install the package bundle version. Not
2222

2323
# flags.dev-hub-org.summary
2424

25-
Org ID of the Dev Hub org where the bundle was created.
25+
Username, alias, or ID of the Dev Hub org where the bundle was created.
2626

2727
# flags.dev-hub-org.description
2828

29-
Enter the Dev Hub org ID, such as 00Dxx0000000000.
29+
Enter the username, alias, or ID of the Dev Hub org, such as "admin@example.com", "myDevHub", or "00Dxx0000000000".
3030

3131
# flags.wait.summary
3232

src/commands/package/bundle/install.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
SfCommand,
2323
} from '@salesforce/sf-plugins-core';
2424
import { BundleSObjects, BundleInstallOptions, PackageBundleInstall } from '@salesforce/packaging';
25-
import { Messages, Lifecycle } from '@salesforce/core';
25+
import { Messages, Lifecycle, Org } from '@salesforce/core';
2626
import { camelCaseToTitleCase, Duration } from '@salesforce/kit';
2727

2828
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
@@ -45,12 +45,10 @@ export class PackageBundlesInstall extends SfCommand<BundleSObjects.PkgBundleVer
4545
}),
4646
'target-org': requiredOrgFlagWithDeprecations,
4747
'api-version': orgApiVersionFlagWithDeprecations,
48-
'dev-hub-org': Flags.salesforceId({
49-
length: 'both',
48+
'dev-hub-org': Flags.string({
5049
char: 'd',
5150
summary: messages.getMessage('flags.dev-hub-org.summary'),
5251
description: messages.getMessage('flags.dev-hub-org.description'),
53-
startsWith: '00D',
5452
required: true,
5553
}),
5654
wait: Flags.integer({
@@ -70,11 +68,22 @@ export class PackageBundlesInstall extends SfCommand<BundleSObjects.PkgBundleVer
7068
const targetOrg = flags['target-org'];
7169
const connection = targetOrg.getConnection(flags['api-version']);
7270

71+
const devHubInput = flags['dev-hub-org'];
72+
let devHubOrgId: string;
73+
// If the input already looks like a 15/18-char org ID starting with 00D, use it directly.
74+
// Otherwise resolve the alias or username through the auth store.
75+
if (/^00D[a-zA-Z0-9]{12,15}$/.test(devHubInput)) {
76+
devHubOrgId = devHubInput;
77+
} else {
78+
const devHubOrg = await Org.create({ aliasOrUsername: devHubInput });
79+
devHubOrgId = devHubOrg.getOrgId();
80+
}
81+
7382
const options: BundleInstallOptions = {
7483
connection,
7584
project: this.project!,
7685
PackageBundleVersion: flags.bundle,
77-
DevelopmentOrganization: flags['dev-hub-org'],
86+
DevelopmentOrganization: devHubOrgId,
7887
};
7988

8089
// Set up lifecycle events for progress tracking

test/commands/bundle/bundleInstall.test.ts

Lines changed: 86 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -21,45 +21,10 @@ import sinon from 'sinon';
2121
import { SfCommand } from '@salesforce/sf-plugins-core';
2222
import { PackageBundlesInstall } from '../../../src/commands/package/bundle/install.js';
2323

24-
const pkgBundleInstallErrorResult: BundleSObjects.PkgBundleVersionInstallReqResult = {
25-
Id: '08c3i000000fylXXXX',
26-
InstallStatus: BundleSObjects.PkgBundleVersionInstallReqStatus.error,
27-
PackageBundleVersionId: '1Q83i000000fxw1AAA',
28-
DevelopmentOrganization: '00D3i000000TNHXXXX',
29-
ValidationError: 'Installation failed due to validation errors',
30-
CreatedDate: '2022-11-03 09:21',
31-
CreatedById: '0053i000001ZIyXXXX',
32-
Error: [
33-
'PropertyController: Invalid type: Schema.Property__c',
34-
'SampleDataController: Invalid type: Schema.Property__c',
35-
],
36-
};
37-
38-
const pkgBundleInstallSuccessResult: BundleSObjects.PkgBundleVersionInstallReqResult = {
39-
Id: '08c3i000000fylgAAA',
40-
InstallStatus: BundleSObjects.PkgBundleVersionInstallReqStatus.success,
41-
PackageBundleVersionId: '1Q83i000000fxw1AAA',
42-
DevelopmentOrganization: '00D3i000000TNHYCA4',
43-
ValidationError: '',
44-
CreatedDate: '2022-11-03 09:46',
45-
CreatedById: '0053i000001ZIyGAAW',
46-
Error: [],
47-
};
48-
49-
const pkgBundleInstallQueuedResult: BundleSObjects.PkgBundleVersionInstallReqResult = {
50-
Id: '08c3i000000fylgBBB',
51-
InstallStatus: BundleSObjects.PkgBundleVersionInstallReqStatus.queued,
52-
PackageBundleVersionId: '1Q83i000000fxw1AAA',
53-
DevelopmentOrganization: '00D3i000000TNHYCA4',
54-
ValidationError: '',
55-
CreatedDate: '2022-11-03 10:00',
56-
CreatedById: '0053i000001ZIyGAAW',
57-
Error: [],
58-
};
59-
6024
describe('package:bundle:install - tests', () => {
6125
const $$ = new TestContext();
6226
const testOrg = new MockTestOrgData();
27+
const devHubOrg = new MockTestOrgData();
6328
let installStub = $$.SANDBOX.stub(PackageBundleInstall, 'installBundle');
6429
const config = new Config({ root: import.meta.url });
6530

@@ -74,7 +39,7 @@ describe('package:bundle:install - tests', () => {
7439
};
7540

7641
before(async () => {
77-
await $$.stubAuths(testOrg);
42+
await $$.stubAuths(testOrg, devHubOrg);
7843
await config.load();
7944
});
8045

@@ -89,122 +54,134 @@ describe('package:bundle:install - tests', () => {
8954

9055
describe('package:bundle:install', () => {
9156
it('should install a package bundle version successfully', async () => {
57+
const pkgBundleInstallSuccessResult: BundleSObjects.PkgBundleVersionInstallReqResult = {
58+
Id: '08c3i000000fylgAAA',
59+
InstallStatus: BundleSObjects.PkgBundleVersionInstallReqStatus.success,
60+
PackageBundleVersionId: '1Q83i000000fxw1AAA',
61+
DevelopmentOrganization: devHubOrg.orgId,
62+
ValidationError: '',
63+
CreatedDate: '2022-11-03 09:46',
64+
CreatedById: '0053i000001ZIyGAAW',
65+
Error: [],
66+
};
9267
installStub.resolves(pkgBundleInstallSuccessResult);
9368

9469
const cmd = new PackageBundlesInstall(
95-
['-b', 'TestBundle@1.0', '--target-org', 'test@org.org', '--dev-hub-org', '00D3i000000TNHYCA4'],
70+
['-b', 'TestBundle@1.0', '--target-org', testOrg.username, '--dev-hub-org', devHubOrg.username],
9671
config
9772
);
9873
stubSpinner(cmd);
9974
const res = await cmd.run();
100-
expect(res).to.deep.equal({
101-
Id: '08c3i000000fylgAAA',
102-
InstallStatus: 'Success',
103-
PackageBundleVersionId: '1Q83i000000fxw1AAA',
104-
DevelopmentOrganization: '00D3i000000TNHYCA4',
105-
ValidationError: '',
106-
CreatedDate: '2022-11-03 09:46',
107-
CreatedById: '0053i000001ZIyGAAW',
108-
Error: [],
109-
});
75+
expect(res).to.deep.equal(pkgBundleInstallSuccessResult);
11076
expect(warnStub.callCount).to.equal(0);
11177
expect(logStub.callCount).to.equal(1);
112-
expect(logStub.args[0]).to.deep.equal([
113-
'Successfully installed bundle version 1Q83i000000fxw1AAA to test@org.org',
114-
]);
78+
expect(logStub.args[0][0]).to.include('Successfully installed bundle version 1Q83i000000fxw1AAA');
11579
});
11680

11781
it('should install a package bundle version with wait option', async () => {
11882
installStub = $$.SANDBOX.stub(PackageBundleInstall, 'installBundle');
83+
const pkgBundleInstallSuccessResult: BundleSObjects.PkgBundleVersionInstallReqResult = {
84+
Id: '08c3i000000fylgAAA',
85+
InstallStatus: BundleSObjects.PkgBundleVersionInstallReqStatus.success,
86+
PackageBundleVersionId: '1Q83i000000fxw1AAA',
87+
DevelopmentOrganization: devHubOrg.orgId,
88+
ValidationError: '',
89+
CreatedDate: '2022-11-03 09:46',
90+
CreatedById: '0053i000001ZIyGAAW',
91+
Error: [],
92+
};
11993
installStub.resolves(pkgBundleInstallSuccessResult);
12094

12195
const cmd = new PackageBundlesInstall(
122-
['-b', 'TestBundle@1.0', '--target-org', 'test@org.org', '--dev-hub-org', '00D3i000000TNHYCA4', '-w', '10'],
96+
['-b', 'TestBundle@1.0', '--target-org', testOrg.username, '--dev-hub-org', devHubOrg.username, '-w', '10'],
12397
config
12498
);
12599
stubSpinner(cmd);
126100
const res = await cmd.run();
127-
expect(res).to.deep.equal({
128-
Id: '08c3i000000fylgAAA',
129-
InstallStatus: 'Success',
130-
PackageBundleVersionId: '1Q83i000000fxw1AAA',
131-
DevelopmentOrganization: '00D3i000000TNHYCA4',
132-
ValidationError: '',
133-
CreatedDate: '2022-11-03 09:46',
134-
CreatedById: '0053i000001ZIyGAAW',
135-
Error: [],
136-
});
101+
expect(res).to.deep.equal(pkgBundleInstallSuccessResult);
137102
expect(warnStub.callCount).to.equal(0);
138103
expect(logStub.callCount).to.equal(1);
139-
expect(logStub.args[0]).to.deep.equal([
140-
'Successfully installed bundle version 1Q83i000000fxw1AAA to test@org.org',
141-
]);
104+
expect(logStub.args[0][0]).to.include('Successfully installed bundle version 1Q83i000000fxw1AAA');
142105
});
143106

144107
// This test does very little to test the verbose command except make sure that it is there.
145108
it('should install a package bundle version with verbose option', async () => {
146109
installStub = $$.SANDBOX.stub(PackageBundleInstall, 'installBundle');
110+
const pkgBundleInstallSuccessResult: BundleSObjects.PkgBundleVersionInstallReqResult = {
111+
Id: '08c3i000000fylgAAA',
112+
InstallStatus: BundleSObjects.PkgBundleVersionInstallReqStatus.success,
113+
PackageBundleVersionId: '1Q83i000000fxw1AAA',
114+
DevelopmentOrganization: devHubOrg.orgId,
115+
ValidationError: '',
116+
CreatedDate: '2022-11-03 09:46',
117+
CreatedById: '0053i000001ZIyGAAW',
118+
Error: [],
119+
};
147120
installStub.resolves(pkgBundleInstallSuccessResult);
148121

149122
const cmd = new PackageBundlesInstall(
150-
['-b', 'TestBundle@1.0', '--target-org', 'test@org.org', '--dev-hub-org', '00D3i000000TNHYCA4', '--verbose'],
123+
['-b', 'TestBundle@1.0', '--target-org', testOrg.username, '--dev-hub-org', devHubOrg.username, '--verbose'],
151124
config
152125
);
153126
stubSpinner(cmd);
154127
const res = await cmd.run();
155-
expect(res).to.deep.equal({
156-
Id: '08c3i000000fylgAAA',
157-
InstallStatus: 'Success',
158-
PackageBundleVersionId: '1Q83i000000fxw1AAA',
159-
DevelopmentOrganization: '00D3i000000TNHYCA4',
160-
ValidationError: '',
161-
CreatedDate: '2022-11-03 09:46',
162-
CreatedById: '0053i000001ZIyGAAW',
163-
Error: [],
164-
});
128+
expect(res).to.deep.equal(pkgBundleInstallSuccessResult);
165129
expect(warnStub.callCount).to.equal(0);
166130
expect(logStub.callCount).to.equal(1);
167-
expect(logStub.args[0]).to.deep.equal([
168-
'Successfully installed bundle version 1Q83i000000fxw1AAA to test@org.org',
169-
]);
131+
expect(logStub.args[0][0]).to.include('Successfully installed bundle version 1Q83i000000fxw1AAA');
170132
});
171133

172134
it('should handle queued status', async () => {
173135
installStub = $$.SANDBOX.stub(PackageBundleInstall, 'installBundle');
136+
const pkgBundleInstallQueuedResult: BundleSObjects.PkgBundleVersionInstallReqResult = {
137+
Id: '08c3i000000fylgBBB',
138+
InstallStatus: BundleSObjects.PkgBundleVersionInstallReqStatus.queued,
139+
PackageBundleVersionId: '1Q83i000000fxw1AAA',
140+
DevelopmentOrganization: devHubOrg.orgId,
141+
ValidationError: '',
142+
CreatedDate: '2022-11-03 10:00',
143+
CreatedById: '0053i000001ZIyGAAW',
144+
Error: [],
145+
};
174146
installStub.resolves(pkgBundleInstallQueuedResult);
175147

176148
const cmd = new PackageBundlesInstall(
177-
['-b', 'TestBundle@1.0', '--target-org', 'test@org.org', '--dev-hub-org', '00D3i000000TNHYCA4'],
149+
['-b', 'TestBundle@1.0', '--target-org', testOrg.username, '--dev-hub-org', devHubOrg.username],
178150
config
179151
);
180152
stubSpinner(cmd);
181153
const res = await cmd.run();
182-
expect(res).to.deep.equal({
183-
Id: '08c3i000000fylgBBB',
184-
InstallStatus: 'Queued',
185-
PackageBundleVersionId: '1Q83i000000fxw1AAA',
186-
DevelopmentOrganization: '00D3i000000TNHYCA4',
187-
ValidationError: '',
188-
CreatedDate: '2022-11-03 10:00',
189-
CreatedById: '0053i000001ZIyGAAW',
190-
Error: [],
191-
});
154+
expect(res).to.deep.equal(pkgBundleInstallQueuedResult);
192155
expect(warnStub.callCount).to.equal(0);
193156
expect(logStub.callCount).to.equal(1);
194157
// Normalize CRLF to LF to make assertion OS-agnostic
195158
const queuedMsg = String(logStub.args[0][0]).replace(/\r\n/g, '\n');
196159
expect(queuedMsg).to.equal(
197-
'Bundle installation is currently Queued. You can continue to query the status using\nsf package bundle install report -i 08c3i000000fylgBBB -o test@org.org'
160+
'Bundle installation is currently Queued. You can continue to query the status using\nsf package bundle install report -i 08c3i000000fylgBBB -o ' +
161+
testOrg.username
198162
);
199163
});
200164

201165
it('should handle error status', async () => {
202166
installStub = $$.SANDBOX.stub(PackageBundleInstall, 'installBundle');
167+
const pkgBundleInstallErrorResult: BundleSObjects.PkgBundleVersionInstallReqResult = {
168+
Id: '08c3i000000fylXXXX',
169+
InstallStatus: BundleSObjects.PkgBundleVersionInstallReqStatus.error,
170+
PackageBundleVersionId: '1Q83i000000fxw1AAA',
171+
DevelopmentOrganization: devHubOrg.orgId,
172+
ValidationError: 'Installation failed due to validation errors',
173+
CreatedDate: '2022-11-03 09:21',
174+
CreatedById: '0053i000001ZIyXXXX',
175+
Error: [
176+
'PropertyController: Invalid type: Schema.Property__c',
177+
'SampleDataController: Invalid type: Schema.Property__c',
178+
],
179+
};
203180
installStub.resolves(pkgBundleInstallErrorResult);
204181

205182
try {
206183
const cmd = new PackageBundlesInstall(
207-
['-b', 'TestBundle@1.0', '--target-org', 'test@org.org', '--dev-hub-org', '00D3i000000TNHYCA4'],
184+
['-b', 'TestBundle@1.0', '--target-org', testOrg.username, '--dev-hub-org', devHubOrg.username],
208185
config
209186
);
210187
stubSpinner(cmd);
@@ -218,21 +195,35 @@ describe('package:bundle:install - tests', () => {
218195
});
219196

220197
it('should handle error status with unknown error', async () => {
221-
const errorResult = { ...pkgBundleInstallErrorResult, ValidationError: '' };
222198
installStub = $$.SANDBOX.stub(PackageBundleInstall, 'installBundle');
199+
const errorResult: BundleSObjects.PkgBundleVersionInstallReqResult = {
200+
Id: '08c3i000000fylXXXX',
201+
InstallStatus: BundleSObjects.PkgBundleVersionInstallReqStatus.error,
202+
PackageBundleVersionId: '1Q83i000000fxw1AAA',
203+
DevelopmentOrganization: devHubOrg.orgId,
204+
ValidationError: '',
205+
CreatedDate: '2022-11-03 09:21',
206+
CreatedById: '0053i000001ZIyXXXX',
207+
Error: [
208+
'PropertyController: Invalid type: Schema.Property__c',
209+
'SampleDataController: Invalid type: Schema.Property__c',
210+
],
211+
};
223212
installStub.resolves(errorResult);
224213

225214
try {
226215
const cmd = new PackageBundlesInstall(
227-
['-b', 'TestBundle@1.0', '--target-org', 'test@org.org', '--dev-hub-org', '00D3i000000TNHYCA4'],
216+
['-b', 'TestBundle@1.0', '--target-org', testOrg.username, '--dev-hub-org', devHubOrg.username],
228217
config
229218
);
230219
stubSpinner(cmd);
231220
await cmd.run();
232221
assert.fail('the above should throw an error');
233222
} catch (e) {
234223
expect((e as Error).message).to.equal(
235-
"Encountered errors installing the bundle! Bundle installation failed. Run 'sf package bundle install report -i 08c3i000000fylXXXX -o test@org.org' for more details."
224+
"Encountered errors installing the bundle! Bundle installation failed. Run 'sf package bundle install report -i 08c3i000000fylXXXX -o " +
225+
testOrg.username +
226+
"' for more details."
236227
);
237228
}
238229
});

0 commit comments

Comments
 (0)