-
Notifications
You must be signed in to change notification settings - Fork 12
feat: created bundle list command #976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dawson-david-salesforce
merged 3 commits into
packagingDistribution/packageBundles
from
t/packaging-distribution/W-18762471/Package-Bundle-List-command
Jun 13, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,22 @@ | ||
| # summary | ||
|
|
||
| Create a bundle. | ||
| Create a package bundle in the Dev Hub org. | ||
|
|
||
| # description | ||
|
|
||
| First, use this command to create a bunle. Then create a bundle version. | ||
|
|
||
| Your --name value must be unique within your namespace. | ||
|
|
||
| Run '<%= config.bin %> bundle list to list all bundles in the Dev Hub org. | ||
| A package bundle is an artifact that contains one or more 2GP managed packages. | ||
| A bundle can be listed on AppExchange, installed, or upgraded as a single artifact. | ||
|
|
||
| # examples | ||
|
|
||
| - Default Use Case | ||
| <%= config.bin %> <%= command.id %> --name <bundle_name> --description "<bundle_description>" --target-dev-hub <dev_hub_alias>` | ||
| Create a package bundle in the Dev Hub org; uses the Dev Hub org with the username devhub@example.com: | ||
|
|
||
| sf package bundle create --name “Your bundle name” --description "Your bundle description" --target-dev-hub devhub@example.com | ||
|
|
||
| # flags.name.summary | ||
|
|
||
| Name of the bundle to create. | ||
| Name of the package bundle. | ||
|
|
||
| # flags.description.summary | ||
|
|
||
| Description of the bundle | ||
| Description of the package bundle. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # summary | ||
|
|
||
| List all package bundles in the Dev Hub org. | ||
|
|
||
| # examples | ||
|
|
||
| List all package bundles in the specified Dev Hub org; uses the Dev Hub org with the username devhub@example.com: | ||
|
|
||
| sf package bundle list --target-dev-hub <dev_hub_alias> | ||
|
|
||
| # namespace | ||
|
|
||
| Namespace Prefix | ||
|
|
||
| # name | ||
|
|
||
| Name | ||
|
|
||
| # id | ||
|
|
||
| Id | ||
|
|
||
| # bundle-id | ||
|
|
||
| Package Bundle Id | ||
|
|
||
| # alias | ||
|
|
||
| Alias | ||
|
|
||
| # description | ||
|
|
||
| Description | ||
|
|
||
| # flags.verbose.summary | ||
|
|
||
| Display extended bundle detail. | ||
|
|
||
| # error-notification-username | ||
|
|
||
| Error Notification Username | ||
|
|
||
| # createdBy | ||
|
|
||
| Created By | ||
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "$ref": "#/definitions/BundleListCommandResults", | ||
| "definitions": { | ||
| "BundleListCommandResults": { | ||
| "type": "array", | ||
| "items": { | ||
| "$ref": "#/definitions/BundleListCommandResult" | ||
| } | ||
| }, | ||
| "BundleListCommandResult": { | ||
| "$ref": "#/definitions/BundleSObjects.Bundle" | ||
| }, | ||
| "BundleSObjects.Bundle": { | ||
| "type": "object", | ||
| "properties": { | ||
| "BundleName": { | ||
| "type": "string" | ||
| }, | ||
| "Description": { | ||
| "type": "string" | ||
| }, | ||
| "Id": { | ||
| "type": "string" | ||
| }, | ||
| "IsDeleted": { | ||
| "type": "boolean" | ||
| }, | ||
| "CreatedDate": { | ||
| "type": "string" | ||
| }, | ||
| "CreatedById": { | ||
| "type": "string" | ||
| }, | ||
| "LastModifiedDate": { | ||
| "type": "string" | ||
| }, | ||
| "LastModifiedById": { | ||
| "type": "string" | ||
| }, | ||
| "SystemModstamp": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "required": [ | ||
| "BundleName", | ||
| "Id", | ||
| "IsDeleted", | ||
| "CreatedDate", | ||
| "CreatedById", | ||
| "LastModifiedDate", | ||
| "LastModifiedById", | ||
| "SystemModstamp" | ||
| ], | ||
| "additionalProperties": false | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * Copyright (c) 2023, salesforce.com, inc. | ||
| * All rights reserved. | ||
| * Licensed under the BSD 3-Clause license. | ||
| * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
|
|
||
| import { Flags, loglevel, orgApiVersionFlagWithDeprecations, SfCommand } from '@salesforce/sf-plugins-core'; | ||
| import { Messages } from '@salesforce/core/messages'; | ||
| import { PackageBundle, BundleSObjects } from '@salesforce/packaging'; | ||
| import chalk from 'chalk'; | ||
| import { requiredHubFlag } from '../../../utils/hubFlag.js'; | ||
|
|
||
| // This is a near copy of the package list command, but with the package bundle class and messages. | ||
| // If you are looking to copy this command, mabye make an abstract class for the commands that are similar.(please) | ||
| Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); | ||
| const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'bundle_list'); | ||
|
|
||
| export type BundleListCommandResult = BundleSObjects.Bundle; | ||
| export type BundleListCommandResults = BundleListCommandResult[]; | ||
|
|
||
| export class BundleListCommand extends SfCommand<BundleListCommandResults> { | ||
| public static readonly summary = messages.getMessage('summary'); | ||
| public static readonly examples = messages.getMessages('examples'); | ||
| public static readonly deprecateAliases = true; | ||
| public static readonly aliases = ['force:package:bundle:list']; | ||
| public static readonly flags = { | ||
| loglevel, | ||
| 'target-dev-hub': requiredHubFlag, | ||
| 'api-version': orgApiVersionFlagWithDeprecations, | ||
| verbose: Flags.boolean({ | ||
| summary: messages.getMessage('flags.verbose.summary'), | ||
| }), | ||
| }; | ||
|
|
||
| public async run(): Promise<BundleListCommandResults> { | ||
| const { flags } = await this.parse(BundleListCommand); | ||
| const connection = flags['target-dev-hub'].getConnection(flags['api-version']); | ||
| const results = await PackageBundle.list(connection); | ||
| this.displayResults(results, flags.verbose); | ||
| return results; | ||
| } | ||
|
|
||
| private displayResults(results: BundleListCommandResults, verbose = false): void { | ||
| const data = results.map((r) => ({ | ||
| 'Package Bundle Name': r.BundleName, | ||
| Id: r.Id, | ||
| Description: r.Description, | ||
| ...(verbose | ||
| ? { | ||
| 'Created Date': r.CreatedDate, | ||
| 'Created By': r.CreatedById, | ||
| 'Last Modified Date': r.LastModifiedDate, | ||
| 'Last Modified By': r.LastModifiedById, | ||
| 'System Modstamp': r.SystemModstamp, | ||
| 'Is Deleted': r.IsDeleted, | ||
| } | ||
| : {}), | ||
| })); | ||
| this.table({ data, title: chalk.blue(`Package Bundles [${results.length}]`) }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * Copyright (c) 2025, salesforce.com, inc. | ||
| * All rights reserved. | ||
| * Licensed under the BSD 3-Clause license. | ||
| * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
| import { Config } from '@oclif/core'; | ||
| import { TestContext, MockTestOrgData } from '@salesforce/core/testSetup'; | ||
| import { expect } from 'chai'; | ||
| import { PackageBundle } from '@salesforce/packaging'; | ||
| import { stubSfCommandUx } from '@salesforce/sf-plugins-core'; | ||
| import sinon from 'sinon'; | ||
| import { BundleListCommand } from '../../../src/commands/package/bundle/list.js'; | ||
| describe('force:bundle:list - tests', () => { | ||
| const $$ = new TestContext(); | ||
| const testOrg = new MockTestOrgData(); | ||
| let sfCommandStubs: ReturnType<typeof stubSfCommandUx>; | ||
| let listStub: sinon.SinonStub; | ||
| const config = new Config({ root: import.meta.url }); | ||
|
|
||
| beforeEach(async () => { | ||
| await $$.stubAuths(testOrg); | ||
| await config.load(); | ||
| sfCommandStubs = stubSfCommandUx($$.SANDBOX); | ||
|
|
||
| listStub = $$.SANDBOX.stub(PackageBundle, 'list'); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| $$.restore(); | ||
| }); | ||
|
|
||
| it('should list a bundle', async () => { | ||
| const cmd = new BundleListCommand(['-v', testOrg.username], config); | ||
|
|
||
| listStub.resolves([{ BundleName: 'test-bundle', Id: 'test-id', Description: 'test-description' }]); | ||
|
|
||
| await cmd.run(); | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access | ||
| expect(sfCommandStubs.table.calledOnce).to.be.true; | ||
| }); | ||
|
|
||
| it('should throw error when test org flag is missing', async () => { | ||
| const cmd = new BundleListCommand([], config); | ||
|
|
||
| listStub.resolves([{ BundleName: 'test-bundle', Id: 'test-id', Description: 'test-description' }]); | ||
|
|
||
| try { | ||
| await cmd.run(); | ||
| expect.fail('Expected error was not thrown'); | ||
| } catch (error) { | ||
| expect((error as Error).message).to.include('No default dev hub found'); | ||
| } | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.