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

@W-15207087@ Update entry point of the project #1036

Merged
merged 3 commits into from
Mar 19, 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 @@ -2,8 +2,8 @@
"name": "@salesforce/core",
"version": "6.7.0",
"description": "Core libraries to interact with SFDX projects, orgs, and APIs.",
"main": "lib/exported",
"types": "lib/exported.d.ts",
"main": "lib/index",
"types": "lib/index.d.ts",
"license": "BSD-3-Clause",
"engines": {
"node": ">=18.0.0"
Expand Down
6 changes: 3 additions & 3 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ const { Generator } = require('npm-dts');
const fs = require('fs');

new Generator({
output: 'lib/exported.d.ts',
output: 'lib/index.d.ts',
}).generate();

const sharedConfig = {
entryPoints: ['src/exported.ts'],
entryPoints: ['src/index.ts'],
bundle: true,
// minify: true,
plugins: [
Expand All @@ -33,7 +33,7 @@ const sharedConfig = {
platform: 'node', // for CJS
outdir: 'lib',
});
const filePath = 'lib/exported.js';
const filePath = 'lib/index.js';
let bundledEntryPoint = fs.readFileSync(filePath, 'utf8');

const searchString = /\$\{process\.cwd\(\)\}\$\{require\("path"\)\.sep\}lib/g;
Expand Down
42 changes: 42 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,47 @@ 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);
});
}

function addTestSetupToIndex() {
const indexPath = './src/index.ts';
const testSetupExport = "export * from './testSetup';\n";
fs.readFile(indexPath, 'utf8', (err, data) => {
fs.appendFile(indexPath, testSetupExport, 'utf8', (err) => {
if (err) {
console.error(`Error appending to file: ${err}`);
} else {
console.log('Content successfully added to the file.');
}
});
});
}

// Run the update functions
updatePackageJson();
updateLoggerTs();
updateLoadMessagesParam();
addTestSetupToIndex();
File renamed without changes.
2 changes: 1 addition & 1 deletion test/perf/logger/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { Suite } from 'benchmark';
import { Logger } from '../../../src/exported';
import { Logger } from '../../../src';
import { cleanup } from '../../../src/logger/cleanup';

const suite = new Suite();
Expand Down
2 changes: 1 addition & 1 deletion test/unit/config/configAggregatorTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { assert, expect, config as chaiConfig } from 'chai';
import { Config, ConfigProperties, SFDX_ALLOWED_PROPERTIES, SfdxPropertyKeys } from '../../../src/config/config';
import { ConfigAggregator, ConfigInfo } from '../../../src/config/configAggregator';
import { ConfigFile } from '../../../src/config/configFile';
import { Messages, OrgConfigProperties, Lifecycle, ORG_CONFIG_ALLOWED_PROPERTIES } from '../../../src/exported';
import { Messages, OrgConfigProperties, Lifecycle, ORG_CONFIG_ALLOWED_PROPERTIES } from '../../../src';
import { TestContext } from '../../../src/testSetup';

// if you add to this, make sure you use both the old and new name
Expand Down
2 changes: 1 addition & 1 deletion test/unit/config/configFileConcurrency.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { tmpdir } from 'node:os';
import { rm } from 'node:fs/promises';
import { expect } from 'chai';
import { sleep } from '@salesforce/kit';
import { ConfigFile } from '../../../src/exported';
import { ConfigFile } from '../../../src';

const FILENAME = 'concurrency.json';
const sharedLocation = join('sfdx-core-ut', 'test', 'configFile');
Expand Down
2 changes: 1 addition & 1 deletion test/unit/config/configFileTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { expect } from 'chai';
import { assert } from '@salesforce/ts-types';
import lockfileLib from 'proper-lockfile';
import { ConfigFile } from '../../../src/config/configFile';
import { SfError } from '../../../src/exported';
import { SfError } from '../../../src';
import { shouldThrow, TestContext } from '../../../src/testSetup';

describe('Config', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/config/configTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as lockfileLib from 'proper-lockfile';
import { Config, ConfigPropertyMeta } from '../../../src/config/config';
import { ConfigFile } from '../../../src/config/configFile';
import { ConfigContents } from '../../../src/config/configStackTypes';
import { OrgConfigProperties } from '../../../src/exported';
import { OrgConfigProperties } from '../../../src';
import { shouldThrowSync, TestContext } from '../../../src/testSetup';

const configFileContentsString = '{"target-dev-hub": "configTest_devhub","target-org": "configTest_default"}';
Expand Down
2 changes: 1 addition & 1 deletion test/unit/projectTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { join, sep } from 'node:path';
import { expect } from 'chai';

import { env } from '@salesforce/kit';
import { Messages, NamedPackageDir } from '../../src/exported';
import { Messages, NamedPackageDir } from '../../src';
import { SfProject, SfProjectJson } from '../../src/sfProject';
import { shouldThrow, shouldThrowSync, TestContext } from '../../src/testSetup';

Expand Down
Loading