Skip to content

Commit

Permalink
chore: updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mingxuanzhangsfdx committed Mar 7, 2024
1 parent 5ae6122 commit df30677
Show file tree
Hide file tree
Showing 37 changed files with 559 additions and 50 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@salesforce/core",
"name": "@salesforce/core-bundle",
"version": "6.7.0",
"description": "Core libraries to interact with SFDX projects, orgs, and APIs.",
"main": "lib/exported",
Expand All @@ -18,8 +18,6 @@
"lint": "wireit",
"lint-fix": "yarn sf-lint --fix",
"postcompile": "tsc -p typedocExamples",
"prepack": "sf-prepack",
"prepare": "sf-install",
"test": "wireit",
"test:only": "wireit",
"test:perf": "ts-node test/perf/logger/main.test.ts"
Expand Down Expand Up @@ -66,6 +64,10 @@
"@types/proper-lockfile": "^4.1.4",
"benchmark": "^2.1.4",
"chai-string": "^1.5.0",
"esbuild": "^0.19.5",
"esbuild-plugin-pino": "^2.1.0",
"esbuild-plugin-tsc": "^0.4.0",
"npm-dts": "^1.3.12",
"ts-node": "^10.9.2",
"ts-patch": "^3.1.1",
"typescript": "^5.3.3"
Expand Down
27 changes: 27 additions & 0 deletions scripts/updateForBundling.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fs = require('fs');
const path = require('path');

// Function to update package.json
function updatePackageJson() {
Expand Down Expand Up @@ -62,6 +63,32 @@ function updateLoggerTs() {
});
}

function updateLoadMessagesParam() {
const dirs = ['./src', './test'];
function replaceTextInFile(filePath) {
const data = fs.readFileSync(filePath, 'utf8');
const result = data.replace(
/Messages\.loadMessages\('@salesforce\/core'/g,
"Messages.loadMessages('@salesforce/core-bundle'"
);
fs.writeFileSync(filePath, result, 'utf8');
}
function traverseDirectory(directory) {
fs.readdirSync(directory).forEach((file) => {
const fullPath = path.join(directory, file);
if (fs.lstatSync(fullPath).isDirectory()) {
traverseDirectory(fullPath);
} else if (path.extname(fullPath) === '.ts') {
replaceTextInFile(fullPath);
}
});
}
dirs.forEach((dir) => {
traverseDirectory(dir);
});
}

// Run the update functions
updatePackageJson();
updateLoggerTs();
updateLoadMessagesParam();
2 changes: 1 addition & 1 deletion src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { ConfigContents, ConfigValue, Key } from './configStackTypes';
import { LWWState, stateFromContents } from './lwwMap';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'config');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'config');

const SFDX_CONFIG_FILE_NAME = 'sfdx-config.json';
const CONFIG_FILE_NAME = 'config.json';
Expand Down
2 changes: 1 addition & 1 deletion src/config/configAggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { EnvVars } from './envVars';
import { Config, ConfigPropertyMeta } from './config';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'config');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'config');

/**
* Information about a config property.
Expand Down
2 changes: 1 addition & 1 deletion src/config/envVars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Messages } from '../messages';
import { Lifecycle } from '../lifecycleEvents';

Messages.importMessagesDirectory(pathJoin(__dirname));
const messages = Messages.loadMessages('@salesforce/core', 'envVars');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'envVars');

export enum EnvironmentVariable {
'FORCE_OPEN_URL' = 'FORCE_OPEN_URL',
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const detectCryptoVersion = (pwd?: string): void => {
};

Messages.importMessagesDirectory(pathJoin(__dirname));
const messages = Messages.loadMessages('@salesforce/core', 'encryption');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'encryption');

interface CredType {
username: string;
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/keyChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Messages } from '../messages';
import { KeyChain, keyChainImpl } from './keyChainImpl';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'encryption');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'encryption');

/**
* Gets the os level keychain impl.
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/keyChainImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { SfError } from '../sfError';
import { Messages } from '../messages';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'encryption');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'encryption');

export type FsIfc = Pick<typeof nodeFs, 'statSync'>;

Expand Down
2 changes: 1 addition & 1 deletion src/deviceOauthService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { SfError } from './sfError';
import { Messages } from './messages';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'auth');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'auth');

export interface DeviceCodeResponse extends JsonMap {
device_code: string;
Expand Down
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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
*/
export * from './exported';
export * from './testSetup';
2 changes: 1 addition & 1 deletion src/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export class Logger {
transport: {
pipeline: [
{
target: path.join('..', '..', 'lib', 'logger', 'transformStream'),
target: './transformStream',
},
getWriteStream(level),
],
Expand Down
2 changes: 1 addition & 1 deletion src/org/authInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { OrgConfigProperties } from './orgConfigProperties';
import { Org, SandboxFields } from './org';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'core');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'core');

/**
* Fields for authorization, org, and local information.
Expand Down
2 changes: 1 addition & 1 deletion src/org/authRemover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { OrgConfigProperties } from './orgConfigProperties';
import { AuthFields } from './authInfo';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'auth');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'auth');

/**
* Handles the removing of authorizations, which includes deleting the auth file
Expand Down
2 changes: 1 addition & 1 deletion src/org/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { AuthFields, AuthInfo } from './authInfo';
import { OrgConfigProperties } from './orgConfigProperties';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'connection');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'connection');

const clientId = `sfdx toolbelt:${process.env.SFDX_SET_CLIENT_IDS ?? ''}`;
export const SFDX_HTTP_HEADERS = {
Expand Down
2 changes: 1 addition & 1 deletion src/org/org.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { scratchOrgCreate, ScratchOrgCreateOptions, ScratchOrgCreateResult } fro
import { OrgConfigProperties } from './orgConfigProperties';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'org');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'org');

export type OrganizationInformation = {
Name: string;
Expand Down
2 changes: 1 addition & 1 deletion src/org/orgConfigProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { SfdcUrl } from '../util/sfdcUrl';
import { validateApiVersion } from '../util/sfdc';

Messages.importMessagesDirectory(pathJoin(__dirname));
const messages = Messages.loadMessages('@salesforce/core', 'config');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'config');

export enum OrgConfigProperties {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/org/permissionSetAssignment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { SfError } from '../sfError';
import { Org } from './org';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'permissionSetAssignment');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'permissionSetAssignment');

/**
* Map of fields name for a permission set assignment
Expand Down
2 changes: 1 addition & 1 deletion src/org/scratchOrgCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { ScratchOrgCache } from './scratchOrgCache';
import { validateScratchOrgInfoForResume } from './scratchOrgErrorCodes';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'scratchOrgCreate');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'scratchOrgCreate');

export const DEFAULT_STREAM_TIMEOUT_MINUTES = 6;

Expand Down
4 changes: 2 additions & 2 deletions src/org/scratchOrgErrorCodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { emit } from './scratchOrgLifecycleEvents';
const WORKSPACE_CONFIG_FILENAME = 'sfdx-project.json';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'scratchOrgErrorCodes');
const namedMessages = Messages.loadMessages('@salesforce/core', 'scratchOrgErrorCodes');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'scratchOrgErrorCodes');
const namedMessages = Messages.loadMessages('@salesforce/core-bundle', 'scratchOrgErrorCodes');

// getMessage will throw when the code isn't found
// and we don't know whether a given code takes arguments or not
Expand Down
2 changes: 1 addition & 1 deletion src/org/scratchOrgFeatureDeprecation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { isString } from '@salesforce/ts-types';
// Local
import { Messages } from '../messages';
Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'scratchOrgFeatureDeprecation');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'scratchOrgFeatureDeprecation');
const FEATURE_TYPES = {
// simpleFeatureMapping holds a set of direct replacement values for features.
simpleFeatureMapping: {
Expand Down
4 changes: 2 additions & 2 deletions src/org/scratchOrgInfoApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export interface JsForceError extends Error {
}

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'scratchOrgInfoApi');
const errorCodes = Messages.loadMessages('@salesforce/core', 'scratchOrgErrorCodes');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'scratchOrgInfoApi');
const errorCodes = Messages.loadMessages('@salesforce/core-bundle', 'scratchOrgErrorCodes');

/**
* Returns the url to be used to authorize into the new scratch org
Expand Down
2 changes: 1 addition & 1 deletion src/org/scratchOrgInfoGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ScratchOrgFeatureDeprecation } from './scratchOrgFeatureDeprecation';
import { DEFAULT_CONNECTED_APP_INFO } from './authInfo';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'scratchOrgInfoGenerator');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'scratchOrgInfoGenerator');

type PartialScratchOrgInfo = Pick<
ScratchOrgInfo,
Expand Down
2 changes: 1 addition & 1 deletion src/org/scratchOrgSettingsGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export default class SettingsGenerator {
}) {
this.logger = Logger.childFromRoot('SettingsGenerator');
if (options?.capitalizeRecordTypes === undefined) {
const messages = Messages.loadMessages('@salesforce/core', 'scratchOrgSettingsGenerator');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'scratchOrgSettingsGenerator');
void Lifecycle.getInstance().emitWarning(messages.getMessage('noCapitalizeRecordTypeConfigVar'));
this.capitalizeRecordTypes = true;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/org/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const scimEndpoint = '/services/scim/v1/Users';
const scimHeaders = { 'auto-approve-user': 'true' };

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'user');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'user');

/**
* A Map of Required Salesforce User fields.
Expand Down
4 changes: 2 additions & 2 deletions src/sfProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import { Messages } from './messages';
import { findUpperCaseKeys } from './util/findUppercaseKeys';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'config');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'config');

const coreMessages = Messages.loadMessages('@salesforce/core', 'core');
const coreMessages = Messages.loadMessages('@salesforce/core-bundle', 'core');

export type PackageDirDependency = {
[k: string]: unknown;
Expand Down
2 changes: 1 addition & 1 deletion src/stateAggregator/accessors/orgAccessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export abstract class BaseOrgAccessor<T extends ConfigFile, P extends ConfigCont
const config = this.configs.get(username);
if (throwOnNotFound && config?.keys().length === 0) {
Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'core');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'core');
throw messages.createError('namedOrgNotFound', [username]);
}
if (config) {
Expand Down
2 changes: 1 addition & 1 deletion src/status/streamingClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { CometClient, CometSubscription, Message, StatusResult, StreamingExtensi
export { CometClient, CometSubscription, Message, StatusResult, StreamingExtension, StreamProcessor };

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'streaming');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'streaming');

/**
* Inner streaming client interface. This implements the Cometd behavior.
Expand Down
2 changes: 1 addition & 1 deletion src/util/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Messages } from '../messages';
import { SfError } from '../sfError';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'config');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'config');

/**
* The name of the project config file.
Expand Down
2 changes: 1 addition & 1 deletion src/webOAuthServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { SfProjectJson } from './sfProject';
import { JwtOAuth2Config } from './org/authInfo';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'auth');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'auth');

// Server ignores requests for site icons
const iconPaths = ['/favicon.ico', '/apple-touch-icon-precomposed.png'];
Expand Down
4 changes: 2 additions & 2 deletions test/unit/config/configAggregatorTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const testEnvVars = ['SF_TARGET_ORG', 'SFDX_MAX_QUERY_LIMIT', 'SF_ORG_MAX_QUERY_
chaiConfig.truncateThreshold = 0;

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'config');
const envMessages = Messages.loadMessages('@salesforce/core', 'envVars');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'config');
const envMessages = Messages.loadMessages('@salesforce/core-bundle', 'envVars');

const telemetryConfigFilter = (i: ConfigInfo) => i.key !== 'disable-telemetry';

Expand Down
2 changes: 1 addition & 1 deletion test/unit/config/envVarsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Lifecycle } from '../../../src/lifecycleEvents';
import { Messages } from '../../../src/messages';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'envVars');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'envVars');

describe('envVars', () => {
const testEnvVars = ['foo', 'SFDX_ACCESS_TOKEN', 'SF_ACCESS_TOKEN'];
Expand Down
8 changes: 6 additions & 2 deletions test/unit/crypto/cryptoTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ describe('CryptoTests', function () {

it('Decrypt should fail without env var, and add extra message', async () => {
setCryptoVersionEnvVar(envVarValue);
const message = Messages.loadMessages('@salesforce/core', 'encryption').getMessage('macKeychainOutOfSync');
const message = Messages.loadMessages('@salesforce/core-bundle', 'encryption').getMessage(
'macKeychainOutOfSync'
);
const err = Error('Failed to decipher auth data. reason: Unsupported state or unable to authenticate data.');
const sfdxErr = SfError.wrap(err);
sfdxErr.actions = [];
Expand All @@ -220,7 +222,9 @@ describe('CryptoTests', function () {
it('Decrypt should fail but not add extra message with env var', async () => {
setCryptoVersionEnvVar(envVarValue);
process.env.SF_USE_GENERIC_UNIX_KEYCHAIN = 'false';
const message: string = Messages.loadMessages('@salesforce/core', 'encryption').getMessage('authDecryptError');
const message: string = Messages.loadMessages('@salesforce/core-bundle', 'encryption').getMessage(
'authDecryptError'
);
const errorMessage: object = SfError.wrap(new Error(message));
stubMethod($$.SANDBOX, os, 'platform').returns('darwin');
stubMethod($$.SANDBOX, crypto, 'decrypt').callsFake(() => ({
Expand Down
2 changes: 1 addition & 1 deletion test/unit/org/orgTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { Lifecycle } from '../../../src/lifecycleEvents';

chaiConfig.truncateThreshold = 0;
Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'org');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'org');

describe('Org Tests', () => {
const $$ = new TestContext();
Expand Down
4 changes: 2 additions & 2 deletions test/unit/org/scratchOrgInfoApiTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import { Messages } from '../../../src/messages';
import { SfError } from '../../../src/sfError';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'scratchOrgInfoApi');
const errorCodesMessages = Messages.loadMessages('@salesforce/core', 'scratchOrgErrorCodes');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'scratchOrgInfoApi');
const errorCodesMessages = Messages.loadMessages('@salesforce/core-bundle', 'scratchOrgErrorCodes');

const scratchOrgInfoId = '2SRK0000001QZxF';
const TEMPLATE_SCRATCH_ORG_INFO: ScratchOrgInfo = {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/org/scratchOrgInfoGeneratorTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const packageVersionSubscriberId = '04tB0000000cWwnIAE';
const badPackageId = '03iB0000000cWwnIAE';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'scratchOrgInfoGenerator');
const messages = Messages.loadMessages('@salesforce/core-bundle', 'scratchOrgInfoGenerator');

describe('scratchOrgInfoGenerator', () => {
const $$ = new TestContext();
Expand Down
2 changes: 1 addition & 1 deletion test/unit/projectTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ describe('SfProject', () => {
shouldThrowSync(() => project.getPackageDirectories());
} catch (e) {
expect((e as Error).message).to.equal(
Messages.loadMessages('@salesforce/core', 'config').getMessage('singleNonDefaultPackage')
Messages.loadMessages('@salesforce/core-bundle', 'config').getMessage('singleNonDefaultPackage')
);
}
});
Expand Down
Loading

0 comments on commit df30677

Please sign in to comment.