Skip to content

Commit

Permalink
fix: update lifecycle event names
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Sep 12, 2022
1 parent 092753d commit 51e2a63
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 26 deletions.
6 changes: 2 additions & 4 deletions src/commands/force/package/beta/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ import {
Package,
PackageVersionCreateEventData,
PackageVersionCreateRequestResult,
PackagingSObjects,
} from '@salesforce/packaging';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_convert');
const pvcMessages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_version_create');
const Package2VersionStatus = PackagingSObjects.Package2VersionStatus;

export class PackageConvert extends SfdxCommand {
public static readonly description = messages.getMessage('cliDescription');
Expand Down Expand Up @@ -64,7 +62,7 @@ export class PackageConvert extends SfdxCommand {

public async run(): Promise<PackageVersionCreateRequestResult> {
// eslint-disable-next-line @typescript-eslint/require-await
Lifecycle.getInstance().on(Package2VersionStatus.inProgress, async (data: PackageVersionCreateEventData) => {
Lifecycle.getInstance().on('Package/convert-in-progress', async (data: PackageVersionCreateEventData) => {
this.ux.log(
`Request in progress. Sleeping 30 seconds. Will wait a total of ${
data.timeRemaining.seconds
Expand All @@ -75,7 +73,7 @@ export class PackageConvert extends SfdxCommand {
});

// eslint-disable-next-line @typescript-eslint/require-await
Lifecycle.getInstance().on(Package2VersionStatus.success, async () => {
Lifecycle.getInstance().on('Package/convert-success', async () => {
this.ux.log('SUCCESS');
});

Expand Down
12 changes: 6 additions & 6 deletions src/commands/force/package/beta/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class Install extends SfdxCommand {
};

// eslint-disable-next-line @typescript-eslint/require-await
Lifecycle.getInstance().on('PackageInstallRequest:warning', async (warningMsg: string) => {
Lifecycle.getInstance().on('Package/install-warning', async (warningMsg: string) => {
this.ux.log(warningMsg);
});

Expand Down Expand Up @@ -133,7 +133,7 @@ export class Install extends SfdxCommand {
this.ux.startSpinner(messages.getMessage('packageInstallWaiting', [remainingTime.minutes]));

// eslint-disable-next-line @typescript-eslint/require-await
Lifecycle.getInstance().on('PackageInstallRequest:status', async (piRequest: PackageInstallRequest) => {
Lifecycle.getInstance().on('Package/install-status', async (piRequest: PackageInstallRequest) => {
const elapsedTime = Duration.milliseconds(Date.now() - timeThen);
timeThen = Date.now();
remainingTime = Duration.milliseconds(remainingTime.milliseconds - elapsedTime.milliseconds);
Expand All @@ -159,9 +159,9 @@ export class Install extends SfdxCommand {

protected async finally(err: Optional<Error>): Promise<void> {
// Remove all the event listeners or they will still handle events
Lifecycle.getInstance().removeAllListeners('PackageInstallRequest:warning');
Lifecycle.getInstance().removeAllListeners('PackageInstallRequest:status');
Lifecycle.getInstance().removeAllListeners('SubscriberPackageVersion:status');
Lifecycle.getInstance().removeAllListeners('Package/install-warning');
Lifecycle.getInstance().removeAllListeners('Package/install-status');
Lifecycle.getInstance().removeAllListeners('Package/install-subscriber-status');
await super.finally(err);
}

Expand Down Expand Up @@ -191,7 +191,7 @@ export class Install extends SfdxCommand {

private async waitForPublish(request: PackageInstallCreateRequest): Promise<void> {
// eslint-disable-next-line @typescript-eslint/require-await
Lifecycle.getInstance().on('SubscriberPackageVersion:status', async (status: string) => {
Lifecycle.getInstance().on('Package/install-subscriber-status', async (status: string) => {
const tokens = status ? [` Status = ${status}`] : [];
this.ux.log(messages.getMessage('publishWaitProgress', tokens));
});
Expand Down
2 changes: 1 addition & 1 deletion src/commands/force/package/beta/uninstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class PackageUninstallCommand extends SfdxCommand {
public async run(): Promise<UninstallResult> {
// no awaits in async method
// eslint-disable-next-line @typescript-eslint/require-await
Lifecycle.getInstance().on('packageUninstall', async (data: UninstallResult) => {
Lifecycle.getInstance().on('Package/uninstall', 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}`);
});
Expand Down
21 changes: 12 additions & 9 deletions src/commands/force/package/beta/version/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,20 @@ export class PackageVersionCreateCommand extends SfdxCommand {
this.ux.warn(messages.getMessage('skipValidationWarning'));
}
const frequency = this.flags.wait && this.flags.skipvalidation ? Duration.seconds(5) : Duration.seconds(30);
// no async methods
// eslint-disable-next-line @typescript-eslint/require-await
Lifecycle.getInstance().on('in-progress', async (data: PackageVersionCreateReportProgress) => {
if (data.Status !== Package2VersionStatus.success && data.Status !== Package2VersionStatus.error) {
this.ux.setSpinnerStatus(
messages.getMessage('packageVersionCreateWaitingStatus', [data.remainingWaitTime.minutes, data.Status])
);
Lifecycle.getInstance().on(
'PackageVersion/create-in-progress',
// no async methods
// eslint-disable-next-line @typescript-eslint/require-await
async (data: PackageVersionCreateReportProgress) => {
if (data.Status !== Package2VersionStatus.success && data.Status !== Package2VersionStatus.error) {
this.ux.setSpinnerStatus(
messages.getMessage('packageVersionCreateWaitingStatus', [data.remainingWaitTime.minutes, data.Status])
);
}
}
});
);
Lifecycle.getInstance().on(
'packageVersionCreate:preserveFiles',
'PackageVersion/create-preserveFiles',
// eslint-disable-next-line @typescript-eslint/require-await
async (data: { location: string; message: string }) => {
this.ux.log(messages.getMessage('tempFileLocation', [data.location]));
Expand Down
2 changes: 1 addition & 1 deletion src/commands/force/package1/beta/version/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class Package1VersionCreateCommand extends SfdxCommand {
if (this.flags.wait) {
// if we're waiting for the request, set up the listener
Lifecycle.getInstance().on(
'package1VersionCreate:progress',
'PackageVersion/create-progress',
// the 'on' method requires an async method, but we don't have any async calls
// eslint-disable-next-line @typescript-eslint/require-await
async (data: { timeout: number; pollingResult: PackageUploadRequest }) => {
Expand Down
10 changes: 5 additions & 5 deletions test/commands/force/package/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ describe('force:package:install', () => {
it('should listen for PackageInstallRequest:warning events and log warnings', async () => {
const warningMsg = 'test warning message';
installStub.callsFake(async () => {
await Lifecycle.getInstance().emit('PackageInstallRequest:warning', warningMsg);
await Lifecycle.getInstance().emit('Package/install-warning', warningMsg);
return pkgInstallRequest;
});

Expand All @@ -297,8 +297,8 @@ describe('force:package:install', () => {
it('should listen for PackageInstallRequest:status polling events and log statuses', async () => {
const successRequest = Object.assign({}, pkgInstallRequest, { Status: 'SUCCESS' });
installStub.callsFake(async () => {
await Lifecycle.getInstance().emit('PackageInstallRequest:status', pkgInstallRequest);
await Lifecycle.getInstance().emit('PackageInstallRequest:status', successRequest);
await Lifecycle.getInstance().emit('Package/install-status', pkgInstallRequest);
await Lifecycle.getInstance().emit('Package/install-status', successRequest);
return pkgInstallRequest;
});

Expand Down Expand Up @@ -445,8 +445,8 @@ describe('force:package:install', () => {
describe('wait for publish', () => {
it('should listen for SubscriberPackageVersion:status polling events and log statuses', async () => {
waitForPublishStub.callsFake(async () => {
await Lifecycle.getInstance().emit('SubscriberPackageVersion:status', 'PACKAGE_UNAVAILABLE');
await Lifecycle.getInstance().emit('SubscriberPackageVersion:status', 'NO_ERRORS_DETECTED');
await Lifecycle.getInstance().emit('Package/install-subscriber-status', 'PACKAGE_UNAVAILABLE');
await Lifecycle.getInstance().emit('Package/install-subscriber-status', 'NO_ERRORS_DETECTED');
});
installStub.resolves(pkgInstallRequest);

Expand Down

0 comments on commit 51e2a63

Please sign in to comment.