Skip to content
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

feat: use new inquirer via sf-plugins-core #537

Merged
merged 4 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^3.14.1",
"@salesforce/core": "^6.4.2",
"@salesforce/core": "^6.4.4",
"@salesforce/kit": "^3.0.15",
"@salesforce/packaging": "^3.1.0",
"@salesforce/sf-plugins-core": "^5.0.9",
"@salesforce/sf-plugins-core": "^7.0.0",
"chalk": "^5.3.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/package/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class PackageCreateCommand extends SfCommand<PackageCreate> {
};
const result: PackageCreate = await Package.create(
flags['target-dev-hub'].getConnection(flags['api-version']),
this.project,
this.project!,
options
);
this.display(result);
Expand Down
6 changes: 3 additions & 3 deletions src/commands/package/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ export class PackageDeleteCommand extends SfCommand<PackageSaveResult> {

public async run(): Promise<PackageSaveResult> {
const { flags } = await this.parse(PackageDeleteCommand);
const promptMsg = flags.undelete ? 'prompt-undelete' : 'prompt-delete';
const accepted = flags['no-prompt'] || flags.json ? true : await this.confirm(messages.getMessage(promptMsg));
const message = messages.getMessage(flags.undelete ? 'prompt-undelete' : 'prompt-delete');
const accepted = flags['no-prompt'] || flags.json ? true : await this.confirm({ message });
if (!accepted) {
throw messages.createError('prompt-delete-deny');
}

const pkg = new Package({
connection: flags['target-dev-hub'].getConnection(flags['api-version']),
project: this.project,
project: this.project!,
packageAliasOrId: flags.package,
});
const result = flags.undelete ? await pkg.undelete() : await pkg.delete();
Expand Down
4 changes: 2 additions & 2 deletions src/commands/package/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export class Install extends SfCommand<PackageInstallRequest> {
private async confirmUpgradeType(noPrompt: boolean): Promise<void> {
if ((await this.subscriberPackageVersion.getPackageType()) === 'Unlocked' && !noPrompt) {
const promptMsg = messages.getMessage('prompt-upgrade-type');
if (!(await this.confirm(promptMsg))) {
if (!(await this.confirm({ message: promptMsg }))) {
throw messages.createError('promptUpgradeTypeDeny');
}
}
Expand All @@ -265,7 +265,7 @@ export class Install extends SfCommand<PackageInstallRequest> {
let enableRss = true;
if (!noPrompt) {
const promptMsg = messages.getMessage('promptEnableRss', [extSites.join('\n')]);
enableRss = await this.confirm(promptMsg);
enableRss = await this.confirm({ message: promptMsg });
}
if (enableRss) {
request.EnableRss = enableRss;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/package/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class PackageListCommand extends SfCommand<PackageListCommandResult> {
NamespacePrefix,
ContainerOptions,
ConvertedFromPackageId,
Alias: this.project.getAliasesFromPackageId(Id).join(),
Alias: this.project!.getAliasesFromPackageId(Id).join(),
IsOrgDependent: ContainerOptions === 'Managed' ? 'N/A' : IsOrgDependent ? 'Yes' : 'No',
PackageErrorUsername,
AppAnalyticsEnabled,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/package/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class PackageUpdateCommand extends SfCommand<PackageSaveResult> {
const pkg = new Package({
packageAliasOrId: flags.package,
connection: flags['target-dev-hub'].getConnection(flags['api-version']),
project: this.project,
project: this.project!,
});

const result = await pkg.update({
Expand Down
2 changes: 1 addition & 1 deletion src/commands/package/version/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export class PackageVersionCreateCommand extends SfCommand<PackageVersionCommand
const result = await PackageVersion.create(
{
connection: flags['target-dev-hub'].getConnection(flags['api-version']),
project: this.project,
project: this.project!,
...Object.fromEntries(Object.entries(flags).map(([key, value]) => [key.replace(/-/g, ''), value])),
packageId: flags.package,
path: flags.path,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/package/version/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class PackageVersionDeleteCommand extends SfCommand<PackageSaveResult> {
const { flags } = await this.parse(PackageVersionDeleteCommand);
const packageVersion = new PackageVersion({
connection: flags['target-dev-hub'].getConnection(flags['api-version']),
project: this.project,
project: this.project!,
idOrAlias: flags.package,
});
await this.confirmDelete(flags['no-prompt'], flags.undelete);
Expand All @@ -59,7 +59,7 @@ export class PackageVersionDeleteCommand extends SfCommand<PackageSaveResult> {
return true;
}
const message = undelete ? messages.getMessage('prompt-undelete') : messages.getMessage('prompt-delete');
const accepted = await this.confirm(message);
const accepted = await this.confirm({ message });
if (!accepted) {
throw new Error(messages.getMessage('prompt-delete-deny'));
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/package/version/displayancestry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class PackageVersionDisplayAncestryCommand extends SfCommand<DisplayAnces
const { flags } = await this.parse(PackageVersionDisplayAncestryCommand);
const packageAncestry = await Package.getAncestry(
flags.package,
this.project,
this.project!,
flags['target-dev-hub'].getConnection(flags['api-version'])
);
const jsonProducer = packageAncestry.getJsonProducer();
Expand Down
4 changes: 2 additions & 2 deletions src/commands/package/version/promote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class PackageVersionPromoteCommand extends SfCommand<PackageSaveResult> {
const { flags } = await this.parse(PackageVersionPromoteCommand);
const packageVersion = new PackageVersion({
connection: flags['target-dev-hub'].getConnection(flags['api-version']),
project: this.project,
project: this.project!,
idOrAlias: flags.package,
});
const packageVersionData = await packageVersion.getData();
Expand All @@ -53,7 +53,7 @@ export class PackageVersionPromoteCommand extends SfCommand<PackageSaveResult> {
}

// Prompt for confirmation
if (!(await this.confirm(messages.getMessage('packageVersionPromoteConfirm', [flags.package])))) {
if (!(await this.confirm({ message: messages.getMessage('packageVersionPromoteConfirm', [flags.package]) }))) {
throw messages.createError('promote-deny');
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/package/version/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class PackageVersionReportCommand extends SfCommand<PackageVersionReportR
const { flags } = await this.parse(PackageVersionReportCommand);
const packageVersion = new PackageVersion({
connection: flags['target-dev-hub'].getConnection(flags['api-version']),
project: this.project,
project: this.project!,
idOrAlias: flags.package,
});
const results = await packageVersion.report(flags.verbose);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/package/version/retrieve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class PackageVersionRetrieveCommand extends SfCommand<PackageVersionRetri
};

const result: PackageVersionMetadataDownloadResult = await Package.downloadPackageVersionMetadata(
this.project,
this.project!,
options,
connection
);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/package/version/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class PackageVersionUpdateCommand extends SfCommand<PackageSaveResult> {
const { flags } = await this.parse(PackageVersionUpdateCommand);
const pv = new PackageVersion({
connection: flags['target-dev-hub'].getConnection(flags['api-version']),
project: this.project,
project: this.project!,
idOrAlias: flags.package,
});
const result = await pv.update({
Expand Down
30 changes: 15 additions & 15 deletions test/commands/package/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Config } from '@oclif/core';
import { expect } from 'chai';
import { PackageEvents, PackagingSObjects, SubscriberPackageVersion } from '@salesforce/packaging';
import sinon from 'sinon';
import { SfCommand } from '@salesforce/sf-plugins-core';
import { SfCommand, stubPrompter } from '@salesforce/sf-plugins-core';
import { Install } from '../../../src/commands/package/install.js';
import InstallValidationStatus = PackagingSObjects.InstallValidationStatus;

Expand Down Expand Up @@ -94,7 +94,7 @@ describe('package:install', () => {
const config = new Config({ root: import.meta.url });
let uxLogStub: sinon.SinonStub;
let uxWarnStub: sinon.SinonStub;
let uxConfirmStub: sinon.SinonStub;
let promptStub: ReturnType<typeof stubPrompter>;
let packageVersionStub: sinon.SinonStub;
let getExternalSitesStub: sinon.SinonStub;
let installStub: sinon.SinonStub;
Expand Down Expand Up @@ -124,7 +124,7 @@ describe('package:install', () => {
getExternalSitesStub = $$.SANDBOX.stub();
installStub = $$.SANDBOX.stub();
installStatusStub = $$.SANDBOX.stub();
uxConfirmStub = $$.SANDBOX.stub(SfCommand.prototype, 'confirm');
promptStub = stubPrompter($$.SANDBOX);

// The SubscriberPackageVersion class is tested in the packaging library, so
// we just stub the public APIs used by the command.
Expand Down Expand Up @@ -449,7 +449,7 @@ describe('package:install', () => {
stubSpinner(cmd);
const result = await cmd.run();

expect(uxConfirmStub.calledOnce).to.be.false;
expect(promptStub.confirm.callCount).to.equal(0);
expect(result).to.deep.equal(pkgInstallRequest);
});

Expand All @@ -459,13 +459,13 @@ describe('package:install', () => {
...subscriberPackageVersion,
Package2ContainerOptions: 'Unlocked',
});
uxConfirmStub.resolves(true);
promptStub.confirm.resolves(true);

const cmd = new Install(['-p', myPackageVersion04t, '-t', 'Delete', '-o', testOrg.username], config);
stubSpinner(cmd);
const result = await cmd.run();

expect(uxConfirmStub.calledOnce).to.be.true;
expect(promptStub.confirm.callCount).to.equal(1);
expect(result).to.deep.equal(pkgInstallRequest);
});

Expand All @@ -483,7 +483,7 @@ describe('package:install', () => {
const error = err as Error;
expect(error.name).to.equal('PromptUpgradeTypeDenyError');
expect(error.message).to.include('We canceled this package installation per your request.');
expect(uxConfirmStub.calledOnce).to.be.true;
expect(promptStub.confirm.callCount).to.equal(1);
}
});

Expand All @@ -500,7 +500,7 @@ describe('package:install', () => {
);
stubSpinner(cmd);
const result = await cmd.run();
expect(uxConfirmStub.calledOnce).to.be.false;
expect(promptStub.confirm.called).equal(false);
expect(result).to.deep.equal(pkgInstallRequest);
});
});
Expand All @@ -520,7 +520,7 @@ describe('package:install', () => {
const result = await cmd.run();

expect(getExternalSitesStub.calledOnce).to.be.true;
expect(uxConfirmStub.calledOnce).to.be.false;
expect(promptStub.confirm.callCount).to.equal(0);
expect(installStub.args[0][0]).to.deep.equal(expectedCreateRequest);
expect(result).to.deep.equal(pkgInstallRequest);
});
Expand All @@ -545,7 +545,7 @@ describe('package:install', () => {
stubSpinner(cmd);
const result = await cmd.run();

expect(uxConfirmStub.calledOnce).to.be.false;
expect(promptStub.confirm.called).to.be.false;
expect(installStub.args[0][0]).to.deep.equal(expectedCreateRequest);
expect(result).to.deep.equal(pkgInstallRequest);
});
Expand All @@ -558,14 +558,14 @@ describe('package:install', () => {
RemoteSiteSettings: { settings: [{ url: 'url/for/site1' }] },
CspTrustedSites: { settings: [{ endpointUrl: 'url/for/site2' }] },
});
uxConfirmStub.resolves(true);
promptStub.confirm.resolves(true);

const cmd = new Install(['-p', myPackageVersion04t, '-o', testOrg.username], config);
stubSpinner(cmd);
const result = await cmd.run();

expect(uxConfirmStub.calledOnce).to.be.true;
expect(uxConfirmStub.args[0][0]).to.include(extSites.join('\n'));
expect(promptStub.confirm.callCount).to.equal(1);
expect(promptStub.confirm.args[0][0].message).to.include(extSites.join('\n'));
expect(installStub.args[0][0]).to.deep.equal(expectedCreateRequest);
expect(result).to.deep.equal(pkgInstallRequest);
});
Expand All @@ -582,8 +582,8 @@ describe('package:install', () => {
stubSpinner(cmd);
const result = await cmd.run();

expect(uxConfirmStub.calledOnce).to.be.true;
expect(uxConfirmStub.args[0][0]).to.include(extSites.join('\n'));
expect(promptStub.confirm.callCount).equal(1);
expect(promptStub.confirm.args[0][0].message).to.include(extSites.join('\n'));
expect(installStub.args[0][0]).to.deep.equal(pkgInstallCreateRequest);
expect(result).to.deep.equal(pkgInstallRequest);
});
Expand Down
Loading