Skip to content

Commit

Permalink
refactor(typescript): packages/rspack/src/logging-truncateArgs (#7383)
Browse files Browse the repository at this point in the history
* refactor(typescript): packages/rspack/src/logging-truncateArgs

* chore: remove arraySum param type any
  • Loading branch information
shulaoda authored Jul 31, 2024
1 parent f8d3a69 commit 9ec49c5
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions packages/rspack/src/logging/truncateArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@
* https://github.com/webpack/webpack/blob/main/LICENSE
*/

const arraySum = (array: any) => {
const arraySum = (array: number[]) => {
let sum = 0;
for (const item of array) sum += item;
return sum;
};

/**
* @param {any[]} args items to be truncated
* @param {number} maxLength maximum length of args including spaces between
* @returns {string[]} truncated args
* @param args items to be truncated
* @param maxLength maximum length of args including spaces between
* @returns truncated args
*/
// @ts-expect-error
const truncateArgs = (args, maxLength) => {
// @ts-expect-error
const truncateArgs = (args: any[], maxLength: number): string[] => {
const lengths = args.map(a => `${a}`.length);
const availableLength = maxLength - lengths.length + 1;

Expand All @@ -36,7 +34,6 @@ const truncateArgs = (args, maxLength) => {
}

// Check if there is space for at least 4 chars per arg
// @ts-expect-error
if (availableLength < arraySum(lengths.map(i => Math.min(i, 6)))) {
// remove args
if (args.length > 1)
Expand All @@ -52,7 +49,6 @@ const truncateArgs = (args, maxLength) => {
// Try to remove chars from the longest items until it fits
while (currentLength > availableLength) {
const maxLength = Math.max(...lengths);
// @ts-expect-error
const shorterItems = lengths.filter(l => l !== maxLength);
const nextToMaxLength =
shorterItems.length > 0 ? Math.max(...shorterItems) : 0;
Expand All @@ -71,7 +67,6 @@ const truncateArgs = (args, maxLength) => {
}

// Return args reduced to length in lengths
// @ts-expect-error
return args.map((a, i) => {
const str = `${a}`;
const length = lengths[i];
Expand Down

2 comments on commit 9ec49c5

@rspack-bot
Copy link

Choose a reason for hiding this comment

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

📝 Ran ecosystem CI: Open

suite result
modernjs ❌ failure
_selftest ✅ success
nx ❌ failure
rspress ✅ success
rsbuild ✅ success
examples ✅ success

@rspack-bot
Copy link

Choose a reason for hiding this comment

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

📝 Benchmark detail: Open

Name Base (2024-07-31 9e2cbe9) Current Change
10000_development-mode + exec 2.27 s ± 20 ms 2.23 s ± 39 ms -1.97 %
10000_development-mode_hmr + exec 702 ms ± 11 ms 700 ms ± 2.8 ms -0.22 %
10000_production-mode + exec 2.76 s ± 39 ms 2.7 s ± 29 ms -2.14 %
arco-pro_development-mode + exec 1.88 s ± 66 ms 1.89 s ± 97 ms +0.31 %
arco-pro_development-mode_hmr + exec 433 ms ± 1.7 ms 434 ms ± 3.5 ms +0.33 %
arco-pro_production-mode + exec 3.45 s ± 114 ms 3.39 s ± 89 ms -1.69 %
threejs_development-mode_10x + exec 1.75 s ± 25 ms 1.76 s ± 25 ms +1.07 %
threejs_development-mode_10x_hmr + exec 863 ms ± 8.3 ms 882 ms ± 11 ms +2.30 %
threejs_production-mode_10x + exec 5.49 s ± 26 ms 5.5 s ± 27 ms +0.27 %

Please sign in to comment.