Skip to content

Commit

Permalink
fix: add package:uninstall command
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Aug 2, 2022
1 parent e84ac87 commit 86db455
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
19 changes: 14 additions & 5 deletions messages/package_uninstall.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ Uninstalls a second-generation package from the target org. To uninstall a first
Specify the package ID for a second-generation package.

Examples:
$ sfdx force:package:uninstall -p 04t... -u me@example.com
$ sfdx force:package:uninstall -p undesirable_package_alias
$ sfdx force:package:uninstall -p "Undesirable Package Alias"
$ sfdx force:package:beta:uninstall -p 04t... -u me@example.com
$ sfdx force:package:beta:uninstall -p undesirable_package_alias
$ sfdx force:package:beta:uninstall -p "Undesirable Package Alias"

To list the org’s installed packages, run "sfdx force:package:installed:list".
To list the org’s installed packages, run "sfdx force:package:beta:installed:list".

To uninstall a first-generation package, from Setup, enter Installed Packages in the Quick Find box, then select Installed Packages.

Expand Down Expand Up @@ -61,4 +61,13 @@ Include either a %s value or a %s value.

# invalidIdOrPackage

Invalid alias or ID: %s. Either your alias is invalid or undefined, or the ID provided is invalid.
Invalid alias or ID: %s. Either your alias is invalid or undefined, or the ID provided is invalid (must start with 04t).

# InProgress

PackageUninstallRequest is currently InProgress.
You can continue to query the status using sfdx force:package:beta:uninstall:report -i %s -u %s

# Success

Successfully uninstalled package [%s]
30 changes: 25 additions & 5 deletions src/commands/force/package/beta/uninstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
*/

import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
import { Messages, SfdxPropertyKeys } from '@salesforce/core';
import { Lifecycle, Messages } from '@salesforce/core';
import { getPackageIdFromAlias, PackagingSObjects, uninstallPackage } from '@salesforce/packaging';
import { Duration } from '@salesforce/kit';

type UninstallResult = PackagingSObjects.SubscriberPackageVersionUninstallRequest;

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_uninstall');
Expand All @@ -15,14 +19,14 @@ export class PackageUninstallCommand extends SfdxCommand {
public static readonly description = messages.getMessage('cliDescription');
public static readonly longDescription = messages.getMessage('cliDescriptionLong');
public static readonly help = messages.getMessage('help');
public static readonly;
public static readonly orgType = SfdxPropertyKeys.DEFAULT_USERNAME;
public static readonly requiresUsername = true;
public static readonly requiresProject = true;
public static readonly flagsConfig: FlagsConfig = {
wait: flags.minutes({
char: 'w',
description: messages.getMessage('wait'),
longDescription: messages.getMessage('waitLong'),
default: Duration.minutes(0),
}),
package: flags.string({
char: 'p',
Expand All @@ -32,7 +36,23 @@ export class PackageUninstallCommand extends SfdxCommand {
};

public async run(): Promise<unknown> {
process.exitCode = 1;
return Promise.resolve('Not yet implemented');
// no awaits in async method
// eslint-disable-next-line @typescript-eslint/require-await
Lifecycle.getInstance().on('packageUninstall', async (data: UninstallResult) => {
// Request still in progress. Just print a console message and move on. Server will be polled again.
this.ux.log(`Waiting for the package uninstall request to get processed. Status = ${data.Status}`);
});

const packageId = getPackageIdFromAlias(this.flags.package, this.project);
if (!packageId.startsWith('04t')) {
throw messages.createError('invalidIdOrPackage', [packageId]);
}
// TODO: fix type once packaging PR is published
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment
const result: UninstallResult = await uninstallPackage(packageId, this.org.getConnection(), this.flags.wait);
const arg = result.Status === 'Success' ? [result.SubscriberPackageVersionId] : [result.Id, this.org.getUsername()];
this.ux.log(messages.getMessage(result.Status, arg));

return result;
}
}

0 comments on commit 86db455

Please sign in to comment.