Skip to content

Commit

Permalink
perf: defer message loading
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Nov 14, 2023
1 parent 067eac1 commit a0cd401
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/shared/deleteUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import { fileURLToPath } from 'node:url';
import { Messages, Connection } from '@salesforce/core';
import { JsForceError } from './orgShapeListUtils.js';

Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
const messages = Messages.loadMessages('@salesforce/plugin-signups', 'shape.delete');

type ShapeRepresentation = {
Id: string;
Status: string;
Expand Down Expand Up @@ -52,6 +49,9 @@ export const deleteAll = async (conn: Connection, username: string): Promise<Del
} catch (err) {
const JsForceErr = err as JsForceError;
if (JsForceErr.errorCode && JsForceErr.errorCode === 'INVALID_TYPE') {
Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
const messages = Messages.loadMessages('@salesforce/plugin-signups', 'shape.delete');

// ShapeExportPref is not enabled, or user does not have CRUD access
throw messages.createError('noAccess', [username]);
}
Expand Down
7 changes: 4 additions & 3 deletions src/shared/orgShapeListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import { fileURLToPath } from 'node:url';
import { AuthInfo, Connection, Logger, Messages, Org, OrgAuthorization, SfError } from '@salesforce/core';
import { settleAll } from '@salesforce/kit';

Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
const messages = Messages.loadMessages('@salesforce/plugin-signups', 'messages');

interface OrgShape {
Id: string;
CreatedBy: {
Expand Down Expand Up @@ -64,6 +61,8 @@ export async function getAllShapesFromOrg(orgAuth: OrgAuthorization): Promise<Or
} else {
logger.error(false, 'Error finding org shapes', JsForceErr);
const error = SfError.wrap(JsForceErr);
Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
const messages = Messages.loadMessages('@salesforce/plugin-signups', 'messages');
error.message = messages.getMessage('errorWithOrg', [orgAuth.username, JsForceErr.message]);
return Promise.reject(error);
}
Expand All @@ -87,6 +86,8 @@ export const getAllOrgShapesFromAuthenticatedOrgs = async (): Promise<{
}> => {
const orgs = await AuthInfo.listAllAuthorizations((orgAuth) => !orgAuth.error && !orgAuth.isScratchOrg);
if (orgs.length === 0) {
Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
const messages = Messages.loadMessages('@salesforce/plugin-signups', 'messages');
throw messages.createError('noAuthFound');
}
const shapes = await settleAll<OrgShapeListResult[]>(orgs.map((o) => getAllShapesFromOrg(o)));
Expand Down

0 comments on commit a0cd401

Please sign in to comment.