From d6aceb5995b7bd18a3286b433dc14c3d2a408dc9 Mon Sep 17 00:00:00 2001 From: mingxuanzhang Date: Thu, 7 Mar 2024 14:23:02 -0800 Subject: [PATCH 1/3] chore: change exported.ts to index.ts --- scripts/build.js | 2 +- scripts/updateForBundling.js | 27 +++++++++++++++++++ src/{exported.ts => index.ts} | 0 test/perf/logger/main.test.ts | 2 +- test/unit/config/configAggregatorTest.ts | 2 +- .../unit/config/configFileConcurrency.test.ts | 2 +- test/unit/config/configFileTest.ts | 2 +- test/unit/config/configTest.ts | 2 +- test/unit/projectTest.ts | 2 +- 9 files changed, 34 insertions(+), 7 deletions(-) rename src/{exported.ts => index.ts} (100%) diff --git a/scripts/build.js b/scripts/build.js index 05689e14ff..e525206b62 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -15,7 +15,7 @@ new Generator({ }).generate(); const sharedConfig = { - entryPoints: ['src/exported.ts'], + entryPoints: ['src/index.ts'], bundle: true, // minify: true, plugins: [ diff --git a/scripts/updateForBundling.js b/scripts/updateForBundling.js index 9a244560bf..dd6b48e37d 100644 --- a/scripts/updateForBundling.js +++ b/scripts/updateForBundling.js @@ -1,4 +1,5 @@ const fs = require('fs'); +const path = require('path'); // Function to update package.json function updatePackageJson() { @@ -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(); diff --git a/src/exported.ts b/src/index.ts similarity index 100% rename from src/exported.ts rename to src/index.ts diff --git a/test/perf/logger/main.test.ts b/test/perf/logger/main.test.ts index 2c8e9741d6..11b1ad04a7 100644 --- a/test/perf/logger/main.test.ts +++ b/test/perf/logger/main.test.ts @@ -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(); diff --git a/test/unit/config/configAggregatorTest.ts b/test/unit/config/configAggregatorTest.ts index 723a7638fa..836a05ce11 100644 --- a/test/unit/config/configAggregatorTest.ts +++ b/test/unit/config/configAggregatorTest.ts @@ -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 diff --git a/test/unit/config/configFileConcurrency.test.ts b/test/unit/config/configFileConcurrency.test.ts index f9f47ef29e..8314b8a879 100644 --- a/test/unit/config/configFileConcurrency.test.ts +++ b/test/unit/config/configFileConcurrency.test.ts @@ -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'); diff --git a/test/unit/config/configFileTest.ts b/test/unit/config/configFileTest.ts index 1a35fbdada..1b6c9d6c70 100644 --- a/test/unit/config/configFileTest.ts +++ b/test/unit/config/configFileTest.ts @@ -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', () => { diff --git a/test/unit/config/configTest.ts b/test/unit/config/configTest.ts index 8519484d9b..760ea90103 100644 --- a/test/unit/config/configTest.ts +++ b/test/unit/config/configTest.ts @@ -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"}'; diff --git a/test/unit/projectTest.ts b/test/unit/projectTest.ts index 24a7abe4d7..9624992c1d 100644 --- a/test/unit/projectTest.ts +++ b/test/unit/projectTest.ts @@ -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'; From 4e96bf06547ab5bfdebce6ac0dbf7b41b749ddb8 Mon Sep 17 00:00:00 2001 From: mingxuanzhang Date: Thu, 7 Mar 2024 14:59:10 -0800 Subject: [PATCH 2/3] chore: update --- package.json | 4 ++-- scripts/build.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 4d6d00d239..2f7bebc43b 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/scripts/build.js b/scripts/build.js index e525206b62..61b9efdbbd 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -11,7 +11,7 @@ const { Generator } = require('npm-dts'); const fs = require('fs'); new Generator({ - output: 'lib/exported.d.ts', + output: 'lib/index.d.ts', }).generate(); const sharedConfig = { @@ -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; From 3c7e03c0d669823af516db9f1ec96807a0d4f92f Mon Sep 17 00:00:00 2001 From: mingxuanzhang Date: Tue, 12 Mar 2024 13:15:04 -0700 Subject: [PATCH 3/3] chore: add testSetup in bundling process --- scripts/updateForBundling.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scripts/updateForBundling.js b/scripts/updateForBundling.js index dd6b48e37d..fa16a0f73f 100644 --- a/scripts/updateForBundling.js +++ b/scripts/updateForBundling.js @@ -88,7 +88,22 @@ function updateLoadMessagesParam() { }); } +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();