Repository: ai/size-limit (js)

Issue:
Extra blank lines when using --silent
Extra blank lines appear when using the `--silent` option.

I propose add a check if (isSilentMode) in the appropriate parts of the code to fix this issue.

```ts
function createHumanReporter(process, isSilentMode = false) {
  function print(...lines) {
    if (!isSilentMode) {
      process.stdout.write('  ' + lines.join('\n  ') + '\n')
    }
  }

```
https://github.com/ai/size-limit/blob/d0d681d7d0c686773650ba1af03d892f0081e761/packages/size-limit/create-reporter.js#L48

Need advice on the correctness of this approach.

I could make PR by myself.

This gap is too БЕСИТ 😬
 
<img width="206" alt="image" src="https://github.com/ai/size-limit/assets/1056977/15105f43-48a0-44ee-a679-bf4c299a49f2">
<img width="779" alt="image" src="https://github.com/ai/size-limit/assets/1056977/ca109c5a-169b-4938-a3d6-486792d7d3d7">
<img width="426" alt="image" src="https://github.com/ai/size-limit/assets/1056977/e2a9b8f1-725c-4a7d-887b-6f0fb3369644">


Pull request:
fix: remove extra blank line in terminal when output is empty
The simpler solution is to use `process.stdout.moveCursor()` and `process.stdout.clearLine()` directly. However, i[f TTY is not available we can not use those methods](https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000645510/comments/115000530624) and consuming `readline` is a better-supported solution to do that.

Resolves #363

Patch:
diff --git a/packages/size-limit/create-reporter.js b/packages/size-limit/create-reporter.js
index 6e9f996..acd7124 100644
--- a/packages/size-limit/create-reporter.js
+++ b/packages/size-limit/create-reporter.js
@@ -1,5 +1,6 @@
 import bytes from 'bytes-iec'
 import { join } from 'node:path'
+import readline from 'node:readline'
 import pc from 'picocolors'
 
 const { bgGreen, bgRed, black, bold, gray, green, red, yellow } = pc
@@ -42,10 +43,13 @@ function getFixText(prefix, config) {
 
   return prefix
 }
-
 function createHumanReporter(process, isSilentMode = false) {
+  let output = ''
+
   function print(...lines) {
-    process.stdout.write('  ' + lines.join('\n  ') + '\n')
+    let value = '  ' + lines.join('\n  ') + '\n'
+    output += value
+    process.stdout.write(value)
   }
 
   function formatBytes(size) {
@@ -190,6 +194,12 @@ function createHumanReporter(process, isSilentMode = false) {
         print(`Webpack Stats file was saved to ${statsFilepath}`)
         print('You can review it using https://webpack.github.io/analyse')
       }
+
+      // clean the blank line in silent mode if the output is empty
+      if (isSilentMode && !output.trim()) {
+        readline.moveCursor(process.stdout, 0, -1)
+        readline.clearLine(process.stdout, 0)
+      }
     }
   }
 }


Test patch:
diff --git a/packages/size-limit/test/__snapshots__/create-reporter.test.js.snap b/packages/size-limit/test/__snapshots__/create-reporter.test.js.snap
index 7aba6c4..958d7f0 100644
--- a/packages/size-limit/test/__snapshots__/create-reporter.test.js.snap
+++ b/packages/size-limit/test/__snapshots__/create-reporter.test.js.snap
@@ -134,7 +134,7 @@ exports[`renders list of failed checks in silent mode 1`] = `
 
 exports[`renders list of success checks in silent mode 1`] = `
 "  
-"
+[1A[2K"
 `;
 
 exports[`renders result for file with gzip 1`] = `
diff --git a/packages/size-limit/test/__snapshots__/run.test.js.snap b/packages/size-limit/test/__snapshots__/run.test.js.snap
index 9bb7e6b..538ac4f 100644
--- a/packages/size-limit/test/__snapshots__/run.test.js.snap
+++ b/packages/size-limit/test/__snapshots__/run.test.js.snap
@@ -305,7 +305,7 @@ Check out docs for more complicated cases
 
 exports[`shows nothing in silent mode and success check 1`] = `
 "  
-"
+[1A[2K"
 `;
 
 exports[`shows size-limit dependency warning 1`] = `""`;