Skip to content

Commit fe35838

Browse files
committed
Unbreak .default require usage, 3.2.1
1 parent 0083ad1 commit fe35838

6 files changed

Lines changed: 46 additions & 11 deletions

File tree

CHANGELOG.md

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

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

5+
### [3.2.1](https://github.com/doesdev/rollup-plugin-analyzer/compare/3.2.0...3.2.1)
6+
7+
> 12 September 2019
8+
9+
- Explicitly add `.default` property to `plugin` in CJS output
10+
- Because my previous unbreaking change broke things
11+
- Clarify import and require usage in README
12+
513
### [3.2.0](https://github.com/doesdev/rollup-plugin-analyzer/compare/3.1.2...3.2.0)
614

715
> 12 September 2019

README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,20 @@ $ npm install --save-dev rollup-plugin-analyzer
2727

2828
## Usage
2929

30-
### from rollup config
30+
### Importing or Requiring
31+
32+
#### Import as ES Module
3133
```js
3234
import analyze from 'rollup-plugin-analyzer'
35+
```
36+
37+
#### Requiring as CJS
38+
```js
39+
const analyze = require('rollup-plugin-analyzer')
40+
```
3341

42+
### Usage from rollup config
43+
```js
3444
export default {
3545
entry: 'module.js',
3646
dest: 'index.js',
@@ -39,11 +49,8 @@ export default {
3949
}
4050
```
4151

42-
### from build script
52+
### Usage from build script
4353
```js
44-
import { rollup } from 'rollup'
45-
import analyze from 'rollup-plugin-analyzer'
46-
4754
rollup({
4855
entry: 'main.js',
4956
plugins: [analyze()]
@@ -52,19 +59,17 @@ rollup({
5259

5360
### CI usage example
5461
```js
55-
import { rollup } from 'rollup'
56-
import analyze from 'rollup-plugin-analyzer'
5762
const limitBytes = 1e6
5863

59-
const onAnalysis = ({bundleSize}) => {
64+
const onAnalysis = ({ bundleSize }) => {
6065
if (bundleSize < limitBytes) return
6166
console.log(`Bundle size exceeds ${limitBytes} bytes: ${bundleSize} bytes`)
6267
return process.exit(1)
6368
}
6469

6570
rollup({
6671
entry: 'main.js',
67-
plugins: [analyze({onAnalysis, skipFormatted: true})]
72+
plugins: [analyze({ onAnalysis, skipFormatted: true })]
6873
}).then(...)
6974
```
7075

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,6 @@ const plugin = (opts = {}) => {
187187

188188
Object.assign(plugin, { plugin, analyze, formatted, reporter });
189189

190+
plugin.default = plugin;
191+
190192
module.exports = plugin;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rollup-plugin-analyzer",
3-
"version": "3.2.0",
3+
"version": "3.2.1",
44
"description": "Mad metrics for your rollup bundles, know all the things",
55
"engines" : { "node" : ">=8.0.0" },
66
"main": "index.js",

rollup.config.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,20 @@
22

33
import analyzer from './module'
44

5+
const appendExportPlugin = () => {
6+
return {
7+
name: 'append-export-default',
8+
transform: (code) => {
9+
return { code: `${code}\nplugin.default = plugin` }
10+
}
11+
}
12+
}
13+
514
export default {
6-
plugins: [analyzer()],
15+
plugins: [
16+
analyzer(),
17+
appendExportPlugin()
18+
],
719
input: 'module.js',
820
output: {
921
file: 'index.js',

test/test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ const rollers = [
3636
{ rollup: rollup100, version: '1.0.x', opts: baseOpts }
3737
]
3838

39+
test('require signature works destructured, direct, and as .default', (assert) => {
40+
const { plugin: destructured } = require('./../index')
41+
const direct = require('./../index')
42+
assert.true(typeof destructured === 'function')
43+
assert.true(typeof direct === 'function')
44+
assert.true(typeof direct.default === 'function')
45+
})
46+
3947
// main
4048
rollers.forEach(({ rollup, version, opts, noTreeshake }) => {
4149
test(`${version}: formatted returns expected string`, async (assert) => {

0 commit comments

Comments
 (0)