Skip to content

Commit db98ac3

Browse files
committed
Add tests, fix filter bugs, 1.1.0
1 parent 2a34c2d commit db98ac3

7 files changed

Lines changed: 3484 additions & 42 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ returns Promise which resolves with well formatted analysis string (for CLI prin
8686
returns Promise which resolves with array of objects describing each imported file
8787
- **bundle** *(Rollup Bundle)* - *required*
8888

89+
returned array's child analysis objects have the following properties
90+
- **id** *(String)* - path of module / rollup module id
91+
- **size** *(Number)* - size of module in bytes
92+
- **dependents** *(Array)* - list of dependent module ids / paths
93+
- **percent** *(Number)* - percentage of module size relative to entire bundle
94+
8995
## License
9096

9197
MIT © [Andrew Carpenter](https://github.com/doesdev)

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
'use strict';
4+
35
// Setup
46
const buf = ' ';
57
const tab = ' ';
@@ -46,7 +48,7 @@ function analyze (bundle, format) {
4648
let size = Buffer.byteLength(m.code, 'utf8') || 0;
4749
bundleSize += size;
4850
if (Array.isArray(filter) && !filter.some((f) => id.match(f))) return null
49-
if (filter && !id.match(filter)) return null
51+
else if (typeof filter === 'string' && !id.match(filter)) return null
5052
m.dependencies.forEach((d) => {
5153
d = d.replace(root, '');
5254
deps[d] = deps[d] || [];
@@ -55,7 +57,7 @@ function analyze (bundle, format) {
5557
return {id, size}
5658
}).filter((m) => m);
5759
modules.sort((a, b) => b.size - a.size);
58-
if (limit) modules = modules.slice(0, limit);
60+
if (limit || limit === 0) modules = modules.slice(0, limit);
5961
modules.forEach((m) => {
6062
m.dependents = deps[m.id] || [];
6163
m.percent = ((m.size / bundleSize) * 100).toFixed(2);

module.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function analyze (bundle, format) {
4848
let size = Buffer.byteLength(m.code, 'utf8') || 0
4949
bundleSize += size
5050
if (Array.isArray(filter) && !filter.some((f) => id.match(f))) return null
51-
if (filter && !id.match(filter)) return null
51+
else if (typeof filter === 'string' && !id.match(filter)) return null
5252
m.dependencies.forEach((d) => {
5353
d = d.replace(root, '')
5454
deps[d] = deps[d] || []
@@ -57,7 +57,7 @@ function analyze (bundle, format) {
5757
return {id, size}
5858
}).filter((m) => m)
5959
modules.sort((a, b) => b.size - a.size)
60-
if (limit) modules = modules.slice(0, limit)
60+
if (limit || limit === 0) modules = modules.slice(0, limit)
6161
modules.forEach((m) => {
6262
m.dependents = deps[m.id] || []
6363
m.percent = ((m.size / bundleSize) * 100).toFixed(2)

0 commit comments

Comments
 (0)