Skip to content

Commit 3542c73

Browse files
authored
fix: remove extra blank line in terminal when output is empty (#383)
1 parent 5b831e1 commit 3542c73

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

packages/size-limit/create-reporter.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import bytes from 'bytes-iec'
22
import { join } from 'node:path'
3+
import readline from 'node:readline'
34
import pc from 'picocolors'
45

56
const { bgGreen, bgRed, black, bold, gray, green, red, yellow } = pc
@@ -42,10 +43,13 @@ function getFixText(prefix, config) {
4243

4344
return prefix
4445
}
45-
4646
function createHumanReporter(process, isSilentMode = false) {
47+
let output = ''
48+
4749
function print(...lines) {
48-
process.stdout.write(' ' + lines.join('\n ') + '\n')
50+
let value = ' ' + lines.join('\n ') + '\n'
51+
output += value
52+
process.stdout.write(value)
4953
}
5054

5155
function formatBytes(size) {
@@ -190,6 +194,12 @@ function createHumanReporter(process, isSilentMode = false) {
190194
print(`Webpack Stats file was saved to ${statsFilepath}`)
191195
print('You can review it using https://webpack.github.io/analyse')
192196
}
197+
198+
// clean the blank line in silent mode if the output is empty
199+
if (isSilentMode && !output.trim()) {
200+
readline.moveCursor(process.stdout, 0, -1)
201+
readline.clearLine(process.stdout, 0)
202+
}
193203
}
194204
}
195205
}

packages/size-limit/test/__snapshots__/create-reporter.test.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ exports[`renders list of failed checks in silent mode 1`] = `
134134

135135
exports[`renders list of success checks in silent mode 1`] = `
136136
"
137-
"
137+
[1A[2K"
138138
`;
139139

140140
exports[`renders result for file with gzip 1`] = `

packages/size-limit/test/__snapshots__/run.test.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ Check out docs for more complicated cases
305305

306306
exports[`shows nothing in silent mode and success check 1`] = `
307307
"
308-
"
308+
[1A[2K"
309309
`;
310310

311311
exports[`shows size-limit dependency warning 1`] = `""`;

0 commit comments

Comments
 (0)