Skip to content

Commit

Permalink
chore: apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
mingxuanzhangsfdx committed Oct 3, 2024
1 parent 2a386f6 commit 0575b4a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 37 deletions.
46 changes: 15 additions & 31 deletions scripts/bundlingUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ function updatePackageJson() {
const packageJson = JSON.parse(data);

// Update package name if necessary
if (packageJson.name && packageJson.name === '@salesforce/core') {
if (packageJson?.name === '@salesforce/core') {
packageJson.name = '@salesforce/core-bundle';
}

// Remove 'prepack' and 'prepare' scripts
// Remove 'prepack' and 'prepare' scripts because publishing bundle does not need the actions
if (packageJson.scripts) {
delete packageJson.scripts.prepack;
delete packageJson.scripts.prepare;
}

// Remove 'exports'
// Remove 'exports' because there is only one entry file in the bundle. Redirecting the paths for core-bundle will cause mess.
if (packageJson.exports) {
delete packageJson.exports;
}
Expand All @@ -43,8 +43,8 @@ function updatePackageJson() {
});
}

// Function to check the path to transformStream
function checkTransformStreamPath() {
// make sure the path to transformStream is not changed, and update the logger path by input
function resolvePinoLogger(updateLoggerPath) {
const loggerPath = './src/logger/logger.ts';
const targetString = "target: path.join('..', '..', 'lib', 'logger', 'transformStream')";
const replacementString = "target: './transformStream'";
Expand All @@ -54,37 +54,23 @@ function checkTransformStreamPath() {
console.error(`Error reading logger.ts: ${err}`);
return;
}

// Check if the target string exists in the file
if (!data.includes(targetString)) {
console.error(
`Error: The target string "${targetString}" was not found in logger.ts.\n Please make sure to bundle transformStream by referencing the new path or reach out to IDEx Foundations Team.`
);
return;
}
});
}

// Function to update logger.ts
function updateLoggerTs() {
const loggerPath = './src/logger/logger.ts';
const targetString = "target: path.join('..', '..', 'lib', 'logger', 'transformStream')";
const replacementString = "target: './transformStream'";

fs.readFile(loggerPath, 'utf8', (err, data) => {
if (err) {
console.error(`Error reading logger.ts: ${err}`);
return;
if (updateLoggerPath) {
let updatedData = data.replace(targetString, replacementString);
fs.writeFile(loggerPath, updatedData, 'utf8', (writeErr) => {
if (writeErr) {
console.error(`Error writing to logger.ts: ${writeErr}`);
} else {
console.log('Logger.ts updated successfully.');
}
});
}
let updatedData = data.replace(targetString, replacementString);

fs.writeFile(loggerPath, updatedData, 'utf8', (writeErr) => {
if (writeErr) {
console.error(`Error writing to logger.ts: ${writeErr}`);
} else {
console.log('Logger.ts updated successfully.');
}
});
});
}

Expand Down Expand Up @@ -127,9 +113,7 @@ function addTestSetupToIndex() {
});
}

// Run the update functions
exports.updatePackageJson = updatePackageJson;
exports.checkTransformStreamPath = checkTransformStreamPath;
exports.updateLoggerTs = updateLoggerTs;
exports.resolvePinoLogger = resolvePinoLogger;
exports.updateLoadMessagesParam = updateLoadMessagesParam;
exports.addTestSetupToIndex = addTestSetupToIndex;
4 changes: 2 additions & 2 deletions scripts/scanTs.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ if (detected) {
console.log('Consider using import instead or reach out to IDEx Foundations team');
}

const { checkTransformStreamPath } = require('./bundlingUtils');
checkTransformStreamPath();
const { resolvePinoLogger } = require('./bundlingUtils');
resolvePinoLogger(false);

console.log('Scan complete');
6 changes: 2 additions & 4 deletions scripts/updateForBundling.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
const {
updatePackageJson,
checkTransformStreamPath,
updateLoggerTs,
resolvePinoLogger,
updateLoadMessagesParam,
addTestSetupToIndex,
} = require('./bundlingUtils');

updatePackageJson();
checkTransformStreamPath();
updateLoggerTs();
resolvePinoLogger(true);
updateLoadMessagesParam();
addTestSetupToIndex();

4 comments on commit 0575b4a

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger Benchmarks - ubuntu-latest

Benchmark suite Current: 0575b4a Previous: 2a386f6 Ratio
Child logger creation 500194 ops/sec (±1.00%) 497703 ops/sec (±1.17%) 1.00
Logging a string on root logger 1052909 ops/sec (±8.18%) 871530 ops/sec (±9.37%) 0.83
Logging an object on root logger 29341 ops/sec (±188.87%) 624871 ops/sec (±7.16%) 21.30
Logging an object with a message on root logger 476748 ops/sec (±7.19%) 30587 ops/sec (±182.30%) 0.0641575843003012
Logging an object with a redacted prop on root logger 596256 ops/sec (±8.64%) 516804 ops/sec (±6.49%) 0.87
Logging a nested 3-level object on root logger 12576 ops/sec (±199.97%) 20011 ops/sec (±186.62%) 1.59

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Logger Benchmarks - ubuntu-latest'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 0575b4a Previous: 2a386f6 Ratio
Logging an object on root logger 29341 ops/sec (±188.87%) 624871 ops/sec (±7.16%) 21.30

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger Benchmarks - windows-latest

Benchmark suite Current: 0575b4a Previous: 2a386f6 Ratio
Child logger creation 349201 ops/sec (±0.53%) 349109 ops/sec (±0.49%) 1.00
Logging a string on root logger 866651 ops/sec (±8.73%) 864531 ops/sec (±11.62%) 1.00
Logging an object on root logger 41799 ops/sec (±183.58%) 655960 ops/sec (±8.86%) 15.69
Logging an object with a message on root logger 382104 ops/sec (±5.05%) 16005 ops/sec (±187.21%) 0.04188650210413919
Logging an object with a redacted prop on root logger 493808 ops/sec (±9.28%) 498958 ops/sec (±7.05%) 1.01
Logging a nested 3-level object on root logger 328161 ops/sec (±5.55%) 310372 ops/sec (±5.28%) 0.95

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Logger Benchmarks - windows-latest'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 0575b4a Previous: 2a386f6 Ratio
Logging an object on root logger 41799 ops/sec (±183.58%) 655960 ops/sec (±8.86%) 15.69

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.