Skip to content

Commit ee99000

Browse files
committed
Limit does not affect filter, 4.0.0 release
1 parent bfe9d70 commit ee99000

7 files changed

Lines changed: 592 additions & 569 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
All notable changes to this project will be documented in this file. Dates are displayed in UTC.
44

5+
### [4.0.0](https://github.com/doesdev/rollup-plugin-analyzer/compare/3.3.0...4.0.0)
6+
7+
> 19 December 2020
8+
9+
- **[BREAKING]** Limit does not affect summary (unless `filterSummary === true`)
10+
- [DEV] Update dev dependencies (standard, husky)
11+
- [DEV] Fix standard style issue
12+
- [DOCS] Add FAQ to readme
13+
- [DOCS] Add TOC to readme
14+
515
### [3.3.0](https://github.com/doesdev/rollup-plugin-analyzer/compare/3.2.3...3.3.0)
616

717
> 8 July 2020

README.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@
44
55
[![npm](https://img.shields.io/npm/v/rollup-plugin-analyzer?style=for-the-badge)](https://npmjs.org/package/rollup-plugin-analyzer) [![Travis (.com)](https://img.shields.io/travis/com/doesdev/rollup-plugin-analyzer?style=for-the-badge)](https://travis-ci.com/doesdev/rollup-plugin-analyzer) [![Dependents (via libraries.io)](https://img.shields.io/librariesio/dependents/npm/rollup-plugin-analyzer?style=for-the-badge)](https://github.com/doesdev/rollup-plugin-analyzer/network/dependents) [![npm](https://img.shields.io/npm/dm/rollup-plugin-analyzer?style=for-the-badge)](https://npmcharts.com/compare/rollup-plugin-analyzer?minimal=true&interval=7)
66

7-
## rollup-plugin-analyzer
8-
9-
See what's bloating your bundle, how treeshaking has treated you, and other
10-
great stuff. Perfect for console printing an analysis of your bundle or
11-
integrating in your CI workflows.
7+
## TOC
8+
9+
- [Install](#install)
10+
- [Usage](#usage)
11+
+ [Importing or Requiring](#importing-or-requiring)
12+
- [Import as ES Module](#import-as-es-module)
13+
- [Requiring as CJS](#requiring-as-cjs)
14+
+ [Usage from rollup config](#usage-from-rollup-config)
15+
+ [Usage from build script](#usage-from-build-script)
16+
+ [CI usage example](#ci-usage-example)
17+
+ [Example results](#results)
18+
+ [Example results (with `summaryOnly` enabled)](#results--with--summaryonly--enabled-)
19+
- [Options](#options)
20+
- [FAQ](#faq)
21+
- [License](#license)
1222

1323
## Install
1424

@@ -148,7 +158,7 @@ module count: 5
148158
- **filterSummary** - *optional*
149159
- type: Boolean
150160
- default: `false`
151-
- description: If `true` the `filter` option will also remove any filtered out module data from the summary
161+
- description: If `true` the `filter` and `limit` options will also remove any filtered out module data from the summary
152162
- **root** - *optional*
153163
- type: String
154164
- default: `process.cwd()`
@@ -205,11 +215,19 @@ module count: 5
205215
- **renderedExports** *(Array)* - list of used named exports
206216
- **removedExports** *(Array)* - list of unused named exports
207217

208-
## Other considerations
218+
## FAQ
219+
220+
#### Why is the reported size not the same as the file on disk?
221+
222+
This module is geared towards the details of the individual modules that make up the bundle and their relative impact to bundle size. That's a detailed way of saying, it doesn't really care about size on disk. There are other options which focus on size on disk as well as delivery size which can be used alongside this module (or in place of if your concern is not per module impact). In particular [rollup-plugin-size-snapshot](https://github.com/TrySound/rollup-plugin-size-snapshot) seems like a great option for that.
223+
224+
Getting a bit further into the details, rather than just intent, of why the reported size differs from that on disk. We get the module data from Rollup which reports it after chunk (module) resolution and tree-shaking, but before post-processing (such as minification and compression). We then add the sizes of each of those modules together, this is the `bundle size` that we report.
225+
226+
That means it won't account for post-processing from other plugins and also won't account for post-processing by Rollup itself, which includes boilerplate / shims depending on what the output format is (CJS, ESM, iife, etc...).
227+
228+
#### Why am I seeing multiple analysis outputs emitted?
209229

210-
Rollup allows you to output to multiple files. If you are outputting to multiple
211-
files you will get a distinct analysis for each output file. Each analysis
212-
will contain data on the files imported by the respective target.
230+
Rollup allows you to output to multiple files. If you are outputting to multiple files you will get a distinct analysis for each output file. Each analysis will contain data on the files imported by the respective target.
213231

214232
## License
215233

index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const reporter = (analysis, opts) => {
5656
const summaryBar = `${id}\n${rawBar} ${m.percent} % (${size})`;
5757
const bar = !summaryOnly ? rawBar : summaryBar;
5858

59-
formatted += summaryOnly ? `${bar}\n` : '' +
59+
const detailed = !summaryOnly && '' +
6060
`${bar}\n` +
6161
`file: ${buf}${id}\n` +
6262
`bundle space: ${buf}${m.percent} %\n` +
@@ -65,6 +65,8 @@ const reporter = (analysis, opts) => {
6565
`code reduction: ${buf}${m.reduction} %\n` +
6666
`dependents: ${buf}${m.dependents.length}\n`;
6767

68+
formatted += summaryOnly ? `${bar}\n` : detailed;
69+
6870
if (!hideDeps && !summaryOnly) {
6971
m.dependents.forEach((d) => {
7072
formatted += `${tab}-${buf}${d.replace(root, '').replace(/\\/g, '/')}\n`;
@@ -126,20 +128,19 @@ const analyzer = (bundle, opts = {}) => {
126128
return { id, size, origSize, renderedExports, removedExports }
127129
}).filter((m) => m).sort((a, b) => b.size - a.size);
128130

129-
if (limit || limit === 0) modules = modules.slice(0, limit);
130-
131-
modules = modules.map((m) => {
131+
modules = modules.map((m, i) => {
132132
m.dependents = deps[m.id] || [];
133133
m.percent = Math.min(((m.size / tmpBdlSize) * 100).toFixed(2), 100);
134134
m.reduction = shakenPct(m.size, m.origSize);
135135

136136
const filtered = applyFilter && !applyFilter(filter, m);
137-
if (filtered && filterSummary) return null
137+
const limited = !Number.isNaN(+limit) && i >= limit;
138+
if ((limited || filtered) && filterSummary) return null
138139

139140
bundleSize += m.size;
140141
bundleOrigSize += m.origSize;
141142

142-
return filtered ? null : m
143+
return (limited || filtered) ? null : m
143144
}).filter((m) => m);
144145

145146
if (filterSummary) {

module.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const reporter = (analysis, opts) => {
5656
const summaryBar = `${id}\n${rawBar} ${m.percent} % (${size})`
5757
const bar = !summaryOnly ? rawBar : summaryBar
5858

59-
formatted += summaryOnly ? `${bar}\n` : '' +
59+
const detailed = !summaryOnly && '' +
6060
`${bar}\n` +
6161
`file: ${buf}${id}\n` +
6262
`bundle space: ${buf}${m.percent} %\n` +
@@ -65,6 +65,8 @@ const reporter = (analysis, opts) => {
6565
`code reduction: ${buf}${m.reduction} %\n` +
6666
`dependents: ${buf}${m.dependents.length}\n`
6767

68+
formatted += summaryOnly ? `${bar}\n` : detailed
69+
6870
if (!hideDeps && !summaryOnly) {
6971
m.dependents.forEach((d) => {
7072
formatted += `${tab}-${buf}${d.replace(root, '').replace(/\\/g, '/')}\n`
@@ -126,20 +128,19 @@ const analyzer = (bundle, opts = {}) => {
126128
return { id, size, origSize, renderedExports, removedExports }
127129
}).filter((m) => m).sort((a, b) => b.size - a.size)
128130

129-
if (limit || limit === 0) modules = modules.slice(0, limit)
130-
131-
modules = modules.map((m) => {
131+
modules = modules.map((m, i) => {
132132
m.dependents = deps[m.id] || []
133133
m.percent = Math.min(((m.size / tmpBdlSize) * 100).toFixed(2), 100)
134134
m.reduction = shakenPct(m.size, m.origSize)
135135

136136
const filtered = applyFilter && !applyFilter(filter, m)
137-
if (filtered && filterSummary) return null
137+
const limited = !Number.isNaN(+limit) && i >= limit
138+
if ((limited || filtered) && filterSummary) return null
138139

139140
bundleSize += m.size
140141
bundleOrigSize += m.origSize
141142

142-
return filtered ? null : m
143+
return (limited || filtered) ? null : m
143144
}).filter((m) => m)
144145

145146
if (filterSummary) {

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rollup-plugin-analyzer",
3-
"version": "3.3.0",
3+
"version": "4.0.0",
44
"description": "Mad metrics for your rollup bundles, know all the things",
55
"engines": {
66
"node": ">=8.0.0"
@@ -47,11 +47,11 @@
4747
},
4848
"homepage": "http://rollup-plugin-analyzer.doesdev.com/",
4949
"devDependencies": {
50-
"husky": "^4.2.5",
51-
"mvt": "4.1.0",
50+
"husky": "^4.3.6",
51+
"mvt": "4.1.1",
5252
"rollup": "npm:rollup@latest",
5353
"rollup100": "npm:rollup@1.0.x",
54-
"standard": "^14.3.4"
54+
"standard": "^16.0.3"
5555
},
5656
"dependencies": {}
5757
}

test/test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,32 @@ rollers.forEach(({ rollup, version, opts, noTreeshake }) => {
7878
assert.is((await analyze(bundle, { limit: 0 })).modules.length, 0)
7979
})
8080

81+
test(`${version}: limit does not affect summary by default`, async (assert) => {
82+
let results
83+
const writeTo = (r) => { results = r }
84+
const rollOpts = Object.assign(
85+
{ plugins: [plugin({ writeTo, limit: 0 })] },
86+
opts
87+
)
88+
const bundle = await rollup(rollOpts)
89+
await bundle.generate({ format: 'cjs' })
90+
91+
assert.doesNotContain(results, '0 Byte')
92+
})
93+
94+
test(`${version}: limit respects filterSummary`, async (assert) => {
95+
let results
96+
const writeTo = (r) => { results = r }
97+
const rollOpts = Object.assign(
98+
{ plugins: [plugin({ writeTo, limit: 0, filterSummary: true })] },
99+
opts
100+
)
101+
const bundle = await rollup(rollOpts)
102+
await bundle.generate({ format: 'cjs' })
103+
104+
assert.contains(results, '0 Byte')
105+
})
106+
81107
test(`${version}: filter with array works`, async (assert) => {
82108
const bundle = await rollup(opts)
83109
assert.is(

0 commit comments

Comments
 (0)