Skip to content

Commit 4a4de65

Browse files
authored
add message option (#376)
1 parent 22c14ee commit 4a4de65

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,9 @@ Each section in the config can have these options:
560560
Format: `100 B`, `10 kB`, `500 ms`, `1 s`.
561561
* **name**: the name of the current section. It will only be useful
562562
if you have multiple sections.
563+
* **message**: an optional custom message to display additional information,
564+
such as guidance for resolving errors, relevant links, or instructions
565+
for next steps when a limit is exceeded.
563566
* **entry**: when using a custom webpack config, a webpack entry could be given.
564567
It could be a string or an array of strings.
565568
By default, the total size of all entry points will be checked.

packages/size-limit/create-reporter.js

+3
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ function createHumanReporter(process, isSilentMode = false) {
135135
}
136136
let diff = formatBytes(check.size - check.sizeLimit)
137137
print(red(`Package size limit has exceeded by ${diff}`))
138+
if (check.message) {
139+
print(check.message)
140+
}
138141
} else if (check.highlightLess && check.size < check.sizeLimit) {
139142
let diff = formatBytes(check.sizeLimit - check.size)
140143
print(bgGreen(black(`Package size is ${diff} less than limit`)))

packages/size-limit/get-config.js

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ let OPTIONS = {
2121
ignore: ['webpack', 'esbuild'],
2222
import: ['webpack', 'esbuild'],
2323
limit: true,
24+
message: true,
2425
modifyEsbuildConfig: 'esbuild',
2526
modifyWebpackConfig: 'webpack',
2627
module: true,

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

+11
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ exports[`renders config-less result 1`] = `
7171
"
7272
`;
7373

74+
exports[`renders custom message 1`] = `
75+
"
76+
Package size limit has exceeded by 1 B
77+
see docs for additional instructions
78+
Size limit: 100 B
79+
Size: 101 B brotlied
80+
81+
Try to reduce size or increase limit at .size-limit.json
82+
"
83+
`;
84+
7485
exports[`renders failed results 1`] = `
7586
"
7687
ok

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

+18
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,24 @@ it('renders single result', () => {
263263
).toMatchSnapshot()
264264
})
265265

266+
it('renders custom message', () => {
267+
expect(
268+
results(['file'], {
269+
checks: [
270+
{
271+
message: 'see docs for additional instructions',
272+
name: 'big fail',
273+
passed: false,
274+
size: 101,
275+
sizeLimit: 100
276+
}
277+
],
278+
configPath: '.size-limit.json',
279+
failed: true
280+
})
281+
).toMatchSnapshot()
282+
})
283+
266284
it('renders config-less result', () => {
267285
expect(
268286
results(['time'], {

0 commit comments

Comments
 (0)