Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #383 – ensure files are not matched twice #1

Merged
merged 3 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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?
martinkutter marked this conversation as resolved.
Show resolved Hide resolved
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 => {
martinkutter marked this conversation as resolved.
Show resolved Hide resolved
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.
Loading