Skip to content

Commit 1adfd60

Browse files
committed
fix: some install command work
1 parent dfe9826 commit 1adfd60

File tree

1 file changed

+45
-7
lines changed

1 file changed

+45
-7
lines changed

src/commands/force/package/beta/install.ts

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
*/
77

88
import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
9-
import { Messages } from '@salesforce/core';
9+
import { Messages, SfProject } from '@salesforce/core';
10+
import { Package, PackagingSObjects, PackageInstallOptions } from '@salesforce/packaging';
11+
import PackageInstallRequest = PackagingSObjects.PackageInstallRequest;
12+
import PackageInstallCreateRequest = PackagingSObjects.PackageInstallCreateRequest;
1013

1114
Messages.importMessagesDirectory(__dirname);
1215
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_install');
@@ -42,35 +45,70 @@ export class PackageInstallCommand extends SfdxCommand {
4245
char: 'p',
4346
description: messages.getMessage('package'),
4447
longDescription: messages.getMessage('packageLong'),
48+
required: true,
4549
}),
4650
apexcompile: flags.enum({
4751
char: 'a',
4852
description: messages.getMessage('apexCompile'),
4953
longDescription: messages.getMessage('apexCompileLong'),
50-
5154
default: 'all',
5255
options: ['all', 'package'],
5356
}),
5457
securitytype: flags.enum({
5558
char: 's',
5659
description: messages.getMessage('securityType'),
5760
longDescription: messages.getMessage('securityTypeLong'),
58-
5961
default: 'AdminsOnly',
6062
options: ['AllUsers', 'AdminsOnly'],
6163
}),
6264
upgradetype: flags.enum({
6365
char: 't',
6466
description: messages.getMessage('upgradeType'),
6567
longDescription: messages.getMessage('upgradeTypeLong'),
66-
6768
default: 'Mixed',
6869
options: ['DeprecateOnly', 'Mixed', 'Delete'],
6970
}),
7071
};
7172

72-
public async run(): Promise<unknown> {
73-
process.exitCode = 1;
74-
return Promise.resolve('Not yet implemented');
73+
public async run(): Promise<PackageInstallRequest> {
74+
const connection = this.org.getConnection();
75+
const pkg = new Package({ connection });
76+
77+
const request: PackageInstallCreateRequest = {
78+
SubscriberPackageVersionKey: await this.resolveSubscriberPackageVersionKey(this.flags.package)
79+
};
80+
81+
const installOptions: PackageInstallOptions = {
82+
pollingTimeout: this.flags.wait,
83+
};
84+
85+
return pkg.install(request, installOptions);
86+
}
87+
88+
// Given a package version ID (04t) or an alias for the package,
89+
// return the package version ID (aka SubscriberPackageVersionKey).
90+
private async resolveSubscriberPackageVersionKey(idOrAlias: string): Promise<string> {
91+
if (idOrAlias.startsWith('04t')) {
92+
return idOrAlias;
93+
} else {
94+
let packageAliases: { [k: string ]: string };
95+
try {
96+
const projectJson = SfProject.getInstance().getSfProjectJson();
97+
packageAliases = projectJson.getContents().packageAliases ?? {};
98+
} catch (e) {
99+
// If not within a package, provide that error
100+
}
101+
const id = packageAliases[idOrAlias];
102+
if (!id) {
103+
// throw NotFound error
104+
}
105+
if (!id.startsWith('04t')) {
106+
// throw InvalidSubscriberPackageVersion - doesn't start with 04t
107+
}
108+
if ([15,18].includes(id.length)) {
109+
// throw InvalidSubscriberPackageVersion - incorrect length
110+
}
111+
return id;
112+
}
75113
}
76114
}

0 commit comments

Comments
 (0)