6
6
*/
7
7
8
8
import { flags , FlagsConfig , SfdxCommand } from '@salesforce/command' ;
9
- import { Messages , SfdxPropertyKeys } from '@salesforce/core' ;
9
+ import { Lifecycle , Messages } from '@salesforce/core' ;
10
+ import { getPackageIdFromAlias , PackagingSObjects , uninstallPackage } from '@salesforce/packaging' ;
11
+ import { Duration } from '@salesforce/kit' ;
12
+
13
+ type UninstallResult = PackagingSObjects . SubscriberPackageVersionUninstallRequest ;
10
14
11
15
Messages . importMessagesDirectory ( __dirname ) ;
12
16
const messages = Messages . loadMessages ( '@salesforce/plugin-packaging' , 'package_uninstall' ) ;
@@ -15,14 +19,14 @@ export class PackageUninstallCommand extends SfdxCommand {
15
19
public static readonly description = messages . getMessage ( 'cliDescription' ) ;
16
20
public static readonly longDescription = messages . getMessage ( 'cliDescriptionLong' ) ;
17
21
public static readonly help = messages . getMessage ( 'help' ) ;
18
- public static readonly ;
19
- public static readonly orgType = SfdxPropertyKeys . DEFAULT_USERNAME ;
20
22
public static readonly requiresUsername = true ;
23
+ public static readonly requiresProject = true ;
21
24
public static readonly flagsConfig : FlagsConfig = {
22
25
wait : flags . minutes ( {
23
26
char : 'w' ,
24
27
description : messages . getMessage ( 'wait' ) ,
25
28
longDescription : messages . getMessage ( 'waitLong' ) ,
29
+ default : Duration . minutes ( 0 ) ,
26
30
} ) ,
27
31
package : flags . string ( {
28
32
char : 'p' ,
@@ -32,7 +36,23 @@ export class PackageUninstallCommand extends SfdxCommand {
32
36
} ;
33
37
34
38
public async run ( ) : Promise < unknown > {
35
- process . exitCode = 1 ;
36
- return Promise . resolve ( 'Not yet implemented' ) ;
39
+ // no awaits in async method
40
+ // eslint-disable-next-line @typescript-eslint/require-await
41
+ Lifecycle . getInstance ( ) . on ( 'packageUninstall' , async ( data : UninstallResult ) => {
42
+ // Request still in progress. Just print a console message and move on. Server will be polled again.
43
+ this . ux . log ( `Waiting for the package uninstall request to get processed. Status = ${ data . Status } ` ) ;
44
+ } ) ;
45
+
46
+ const packageId = getPackageIdFromAlias ( this . flags . package , this . project ) ;
47
+ if ( ! packageId . startsWith ( '04t' ) ) {
48
+ throw messages . createError ( 'invalidIdOrPackage' , [ packageId ] ) ;
49
+ }
50
+ // TODO: fix type once packaging PR is published
51
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment
52
+ const result : UninstallResult = await uninstallPackage ( packageId , this . org . getConnection ( ) , this . flags . wait ) ;
53
+ const arg = result . Status === 'Success' ? [ result . SubscriberPackageVersionId ] : [ result . Id , this . org . getUsername ( ) ] ;
54
+ this . ux . log ( messages . getMessage ( result . Status , arg ) ) ;
55
+
56
+ return result ;
37
57
}
38
58
}
0 commit comments