Skip to content

Commit

Permalink
fix siddharthkp#383 – ensure files are not matched twice (siddharthkp…
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Kutter committed Jan 18, 2024
1 parent 3b3b09e commit 309ae96
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 60 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
[![NPM Downloads](https://img.shields.io/npm/dm/bundlesize.svg?style=flat)](https://www.npmjs.com/package/bundlesize)
 

#### Why this fork exists?
It seems there is no active maintenance of the original repository. This fork is intended to fix.
* remove deprecated brotli compression to improve performance
* [fix wrong multiple matches](https://github.com/siddharthkp/bundlesize/issues/383)

#### Setup

```sh
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bundlesize",
"version": "1.0.0",
"version": "2.0.0",
"description": "Keep your library size in check",
"repository": {
"type": "git",
Expand Down
14 changes: 8 additions & 6 deletions src/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ config.map(file => {
silent: true
})
} else {
paths.map(path => {
const maxSize = bytes(file.maxSize) || Infinity
const compression = file.compression || 'gzip'
const size = compressedSize(fs.readFileSync(path, 'utf8'), compression)
files.push({ maxSize, path, size, compression })
})
paths
.filter(path => !files.some(file => file.path === path))
.map(path => {
const maxSize = bytes(file.maxSize) || Infinity
const compression = file.compression || 'gzip'
const size = compressedSize(fs.readFileSync(path, 'utf8'), compression)
files.push({ maxSize, path, size, compression })
})
}
})

Expand Down
19 changes: 19 additions & 0 deletions tests/fixtures/12/build/file-241B.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
The contents of this file aren't important,
what's important is the size
241B gzip
*/

const { inspect } = require('util')
const files = require('./src/files')
const reporter = require('./src/reporter')
const build = require('./src/build')

reporter(files)

process.on('unhandledRejection', function(reason) {
console.log('Unhandled Promise')
console.log(inspect(reason))
build.error()
})
28 changes: 28 additions & 0 deletions tests/fixtures/12/build/file-734B.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions tests/fixtures/12/bundlesize.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"files": [
{
"path": "build/file-734B.js",
"maxSize": "1KB"
},
{
"path": "build/file-*.js",
"maxSize": "250B"
},
{
"path": "build/file-241B.js",
"maxSize": "100B"
}
]
}
6 changes: 6 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,9 @@ test.skip('10. bug repro: bundlesize should dedup files', t => {
t.is(exitCode, 0) // this is failing
t.snapshot(stdout)
})

test('11. bug repro: files should not be matched twice, order should matters (https://github.com/siddharthkp/bundlesize/issues/383)', t => {
const { stdout, exitCode } = run(12)
t.is(exitCode, 0) // this is failing
t.snapshot(stdout)
})
56 changes: 3 additions & 53 deletions tests/snapshots/index.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,70 +10,20 @@ Generated by [AVA](https://ava.li).
'PASS file-1.js: 270B < maxSize 300B (gzip)'

## 10. pass: match by fuzzy name
## 11. bug repro: files should not be matched twice, order should matters (https://github.com/siddharthkp/bundlesize/issues/383)

> Snapshot 1
`PASS build/vendor-ha5h.js: 270B < maxSize 350B (gzip) ␊
`PASS build/file-734B.js: 734B < maxSize 1KB (gzip) ␊
PASS build/chunks/chunk-ch0nk.js: 270B < maxSize 300B (gzip)`
PASS build/file-241B.js: 241B < maxSize 250B (gzip)`

## 2. fail: single file larger than limit

> Snapshot 1
'FAIL file-2.js: 270B > maxSize 250B (gzip)'

## 3. pass: use brotli

> Snapshot 1
'PASS file-3.js: 245B < maxSize 250B (brotli)'

## 4. fail: dont use compression

> Snapshot 1
'FAIL file-4.js: 437B > maxSize 300B (no compression)'

## 5. pass: custom config file

> Snapshot 1
'PASS file-5.js: 270B < maxSize 300B (gzip)'

## 6. pass: multiple files, both smaller than limit

> Snapshot 1
`PASS file-61.js: 270B < maxSize 300B (gzip) ␊
PASS file-62.js: 270B < maxSize 300B (gzip)`

## 7. fail: multiple files, both bigger than limit

> Snapshot 1
`FAIL file-61.js: 270B > maxSize 200B (gzip) ␊
FAIL file-62.js: 270B > maxSize 200B (gzip)`

## 8. fail: multiple files, 1 smaller + 1 bigger than limit

> Snapshot 1
`PASS file-61.js: 270B < maxSize 300B (gzip) ␊
FAIL file-62.js: 270B > maxSize 200B (gzip)`

## 9. pass: catch all js files

> Snapshot 1
`PASS build/chunks/chunk-ch0nk.js: 270B < maxSize 300B (gzip) ␊
PASS build/vendor-ha5h.js: 270B < maxSize 300B (gzip)`

## 3. fail: dont use compression

> Snapshot 1
Expand Down
Binary file modified tests/snapshots/index.js.snap
Binary file not shown.

0 comments on commit 309ae96

Please sign in to comment.