Skip to content

Commit

Permalink
fix: package:installed:list command
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Aug 5, 2022
1 parent e84ac87 commit 3169872
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 34 deletions.
28 changes: 0 additions & 28 deletions messages/package_installed_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,3 @@ $ sfdx force:package:installed:list -u me@example.com
# username

a username or alias for the target org

# id

ID

# subscriberPackageId

Package ID

# subscriberPackageName

Package Name

# subscriberPackageNamespace

Namespace

# subscriberPackageVersionId

Package Version ID

# subscriberPackageVersionName

Version Name

# subscriberPackageVersionNumber

Version
48 changes: 42 additions & 6 deletions src/commands/force/package/beta/installed/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,58 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { Messages, SfdxPropertyKeys } from '@salesforce/core';
import { Messages } from '@salesforce/core';
import { SfdxCommand } from '@salesforce/command';
import { packageInstalledList, PackagingSObjects } from '@salesforce/packaging';
import { CliUx } from '@oclif/core';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_installed_list');

type InstalledPackage = PackagingSObjects.InstalledPackage;

export type PackageInstalledListResult = {
Id: string;
SubscriberPackageId: string;
SubscriberPackageName: string;
SubscriberPackageNamespace: string;
SubscriberPackageVersionId: string;
SubscriberPackageVersionName: string;
SubscriberPackageVersionNumber: string;
};

export class PackageInstalledListCommand extends SfdxCommand {
public static readonly description = messages.getMessage('cliDescription');
public static readonly longDescription = messages.getMessage('cliLongDescription');
public static readonly help = messages.getMessage('help');
public static readonly orgType = SfdxPropertyKeys.DEFAULT_USERNAME;
public static readonly requiresUsername = true;
public static readonly requiresProject = true;

public async run(): Promise<unknown> {
process.exitCode = 1;
return Promise.resolve('Not yet implemented');
public async run(): Promise<PackageInstalledListResult[]> {
// TODO: fix types once Packaging is published
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
const result: InstalledPackage[] = (await packageInstalledList(this.org.getConnection())).records;

const records: PackageInstalledListResult[] = result.map((record: InstalledPackage) => ({
Id: record.Id,
SubscriberPackageId: record.SubscriberPackageId,
SubscriberPackageName: record.SubscriberPackage.Name,
SubscriberPackageNamespace: record.SubscriberPackage.NamespacePrefix,
SubscriberPackageVersionId: record.SubscriberPackageVersion.Id,
SubscriberPackageVersionName: record.SubscriberPackageVersion.Name,
SubscriberPackageVersionNumber: `${record.SubscriberPackageVersion.MajorVersion}.${record.SubscriberPackageVersion.MinorVersion}.${record.SubscriberPackageVersion.PatchVersion}.${record.SubscriberPackageVersion.BuildNumber}`,
}));

const tableOptions: CliUx.Table.table.Options = {
Id: { header: 'ID' },
SubscriberPackageId: { header: 'Package ID' },
SubscriberPackageName: { header: 'Package Name' },
SubscriberPackageNamespace: { header: 'Namespace' },
SubscriberPackageVersionId: { header: 'Package Version ID' },
SubscriberPackageVersionName: { header: 'Version Name' },
SubscriberPackageVersionNumber: { header: 'Version' },
};
this.ux.table(records, tableOptions);

return records;
}
}

0 comments on commit 3169872

Please sign in to comment.