Skip to content

Commit

Permalink
fix: remove extra blank line in terminal when output is empty (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
EvgenyWas authored Jan 28, 2025
1 parent 5b831e1 commit 3542c73
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
14 changes: 12 additions & 2 deletions packages/size-limit/create-reporter.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`] = `
Expand Down
2 changes: 1 addition & 1 deletion packages/size-limit/test/__snapshots__/run.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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`] = `""`;
Expand Down

0 comments on commit 3542c73

Please sign in to comment.