From 309ae969d19a21bd66742159b1b9509eebbf2e5e Mon Sep 17 00:00:00 2001 From: Martin Kutter Date: Thu, 18 Jan 2024 16:12:17 +0100 Subject: [PATCH 1/3] =?UTF-8?q?fix=20#383=20=E2=80=93=20ensure=20files=20a?= =?UTF-8?q?re=20not=20matched=20twice=20(https://github.com/siddharthkp/bu?= =?UTF-8?q?ndlesize/issues/383)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 ++ package.json | 2 +- src/files.js | 14 +++--- tests/fixtures/12/build/file-241B.js | 19 ++++++++ tests/fixtures/12/build/file-734B.js | 28 ++++++++++++ tests/fixtures/12/bundlesize.config.json | 16 +++++++ tests/index.js | 6 +++ tests/snapshots/index.js.md | 56 ++--------------------- tests/snapshots/index.js.snap | Bin 668 -> 515 bytes 9 files changed, 86 insertions(+), 60 deletions(-) create mode 100644 tests/fixtures/12/build/file-241B.js create mode 100644 tests/fixtures/12/build/file-734B.js create mode 100644 tests/fixtures/12/bundlesize.config.json 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 b5e9cca983ae1c54891589ec14e6fa7670de7768..8a4206a06a3657ed4eb6f1c77c958d3c1ef93c59 100644 GIT binary patch literal 515 zcmV+e0{s0!RzVMl z_1b(LR$0v#o0e!VVyxf72o~K6#Ixg`MJRF3yOtnSF~{&)UoIn9^c@htiu|aYb*6op z#fw#s{ZH`LFoH!RfYz;S+EWy{yyHa05!;4E%O-d;f<+GjvH6E}O0KPb%*vnS@-NNu zn#%|l)nQ^_NU^;s&H3xrga=ZrsvO)i-59~58-dugBu^@%)n|j_9qXo!C9+zKU{Nz> z28Q=cmAySn(%($%Wz0G0y{Ni9E-ZBseKrliu$oD}`!jMBX9VhE+1oMDicO>}TV3@A&@OUWq{Kqzx(a004l5OfI3kgB$tJEg=0h9oV;_qM000000009! zz{tQL$k6#c;fS!GoK{vLMm>QM{Dsgpi8yE1}Bi-35` z@9UmIi}#paVtrweQQy9h5iGhEhAX zlREP3OkEzXGTSBsv+050&((O|&y!=+Wb=*|z)p z3r4W$Um)Hazq-_Zq1F7FXHKmAPOe;xV9|6Y28OE#!`NH?biG+OU+;kT?b>yWV9_@~ z+~@t_sPHkTO^;_Pv(?>aXJ!P87BVw1+;zP+Ux!sz^Tnnm+KU+Lw=jZ5w*c|%xMvYc zob#?F2vy86yw;b?2o`+{#IGVhDrcQ(UuN-Q)noq?yfutq(Qp<9hLufwiXxYHoTxZr z+puWa1aC&L=s_Sh|FBNUwbhSV`IB7!rCDBc8Ns63tPBh(wl}3Yf8Cn!K#EnBgL|eM zBUp3;5Sy0dNoBP9Y;e3|-PEx}R*MlL%ErLJ%)kzgD@IlZK}PKW$KYTEg|y6^R9!>8 ztYRw#BXa{M1sjFj#ERg|s#FDI10Yu;y(+Un6IG*|qo)s4qY*-*9bBW4DRzyzNH!Wn zG@6(q+X&H^RFq$mlZmR;6v<8#uvQaeb7VUqj?K$gNY2kKC`v6Z&dkr##OYsCQv4f( zq|uB}NGWh}DIlviBFQEsUn1Lt6tt)|A*;t871Z(***29!Y)UH4%t_Ht&M3{xE{0IL z$r%QD*+d5?#DKEYyp;SR-Hb%j3{nENoD?%maoSF@^GDP0Xc`{sX&3 Date: Fri, 19 Jan 2024 09:42:18 +0100 Subject: [PATCH 2/3] fix typo Co-authored-by: Bettina Helgenlechner <7873316+helgenlechner@users.noreply.github.com> --- tests/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/index.js b/tests/index.js index 871aae20..5e6efaf0 100644 --- a/tests/index.js +++ b/tests/index.js @@ -104,7 +104,7 @@ test.skip('10. bug repro: bundlesize should dedup files', t => { t.snapshot(stdout) }) -test('11. bug repro: files should not be matched twice, order should matters (https://github.com/siddharthkp/bundlesize/issues/383)', t => { +test('11. bug repro: files should not be matched twice, order should matter (https://github.com/siddharthkp/bundlesize/issues/383)', t => { const { stdout, exitCode } = run(12) t.is(exitCode, 0) // this is failing t.snapshot(stdout) From 59990eb585899b6a6a9b417dfc3f3ee4c934c020 Mon Sep 17 00:00:00 2001 From: Martin Kutter Date: Fri, 19 Jan 2024 09:44:31 +0100 Subject: [PATCH 3/3] improve "why this fork exists" section in readme --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 659c7ac0..e8ffb51d 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,10 @@   #### Why this fork exists? -It seems there is no active maintenance of the original repository. This fork is intended to fix. +It seems that the original repository is no longer actively maintained. This fork is intended to fix the following: + * remove deprecated brotli compression to improve performance -* [fix wrong multiple matches](https://github.com/siddharthkp/bundlesize/issues/383) +* [fix fuzzy matching logic to not include paths that match other patterns](https://github.com/siddharthkp/bundlesize/issues/383) #### Setup