diff --git a/README.md b/README.md index 7cb4aaa5..659c7ac0 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/package.json b/package.json index d527ad36..318962ad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bundlesize", - "version": "1.0.0", + "version": "2.0.0", "description": "Keep your library size in check", "repository": { "type": "git", diff --git a/src/files.js b/src/files.js index 586231fc..e877ee5f 100644 --- a/src/files.js +++ b/src/files.js @@ -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 }) + }) } }) diff --git a/tests/fixtures/12/build/file-241B.js b/tests/fixtures/12/build/file-241B.js new file mode 100644 index 00000000..351f5bad --- /dev/null +++ b/tests/fixtures/12/build/file-241B.js @@ -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() +}) diff --git a/tests/fixtures/12/build/file-734B.js b/tests/fixtures/12/build/file-734B.js new file mode 100644 index 00000000..8b6791e4 --- /dev/null +++ b/tests/fixtures/12/build/file-734B.js @@ -0,0 +1,28 @@ +/* +The contents of this file aren't important, +what's important is the size + +724B gzip +*/ + +const lps = `Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. + +Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. + +Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. + +Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. + +Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis. + +At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, At accusam aliquyam diam diam dolore dolores duo eirmod eos erat, et nonumy sed tempor et et invidunt justo labore Stet clita ea et gubergren, kasd magna no rebum. sanctus sea sed takimata ut vero voluptua. est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat. + +Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus. + +Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. + +Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. + +Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. + +Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo`; diff --git a/tests/fixtures/12/bundlesize.config.json b/tests/fixtures/12/bundlesize.config.json new file mode 100644 index 00000000..1c3939ca --- /dev/null +++ b/tests/fixtures/12/bundlesize.config.json @@ -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" + } + ] +} diff --git a/tests/index.js b/tests/index.js index 3f1c5561..871aae20 100644 --- a/tests/index.js +++ b/tests/index.js @@ -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) +}) diff --git a/tests/snapshots/index.js.md b/tests/snapshots/index.js.md index 00eb6d4c..273a1c32 100644 --- a/tests/snapshots/index.js.md +++ b/tests/snapshots/index.js.md @@ -10,13 +10,13 @@ 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 @@ -24,56 +24,6 @@ Generated by [AVA](https://ava.li). '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 diff --git a/tests/snapshots/index.js.snap b/tests/snapshots/index.js.snap index b5e9cca9..8a4206a0 100644 Binary files a/tests/snapshots/index.js.snap and b/tests/snapshots/index.js.snap differ