Skip to content

Commit 9b9c2ca

Browse files
committed
Integrate plugin, add related (failing) test
1 parent eed1240 commit 9b9c2ca

4 files changed

Lines changed: 40 additions & 3 deletions

File tree

index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,16 @@ const analyze = (bundle, opts = {}, format = false) => {
6767

6868
const formatted = (bndl, opts) => analyze(bndl, opts, true);
6969

70+
const plugin = (opts = {}) => {
71+
let log = opts.writeTo || (opts.stdout ? console.log : console.error);
72+
return {
73+
name: 'rollup-analyzer-plugin',
74+
ongenerate: ({bundle}) => {
75+
return formatted(bundle, opts).then(log)
76+
}
77+
}
78+
};
79+
7080
exports.analyze = analyze;
7181
exports.formatted = formatted;
82+
exports.plugin = plugin;

module.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,13 @@ export const analyze = (bundle, opts = {}, format = false) => {
6464
}
6565

6666
export const formatted = (bndl, opts) => analyze(bndl, opts, true)
67+
68+
export const plugin = (opts = {}) => {
69+
let log = opts.writeTo || (opts.stdout ? console.log : console.error)
70+
return {
71+
name: 'rollup-analyzer-plugin',
72+
ongenerate: ({bundle}) => {
73+
return formatted(bundle, opts).then(log)
74+
}
75+
}
76+
}

test/index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
// setup
44
import test from 'ava'
5+
import { analyze, formatted, plugin } from './../index'
56
import { resolve, join } from 'path'
67
import { rollup as rollupLatest } from 'rollup'
78
import { rollup as rollup60 } from 'rollup60'
89
import { rollup as rollup55 } from 'rollup55'
910
import { rollup as rollup50 } from 'rollup50'
1011
import { rollup as rollup45 } from 'rollup45'
1112
import { rollup as rollup40 } from 'rollup40'
12-
import { analyze, formatted } from './../index'
1313
const fixtures = resolve(__dirname, 'fixtures')
1414
const baseOpts = {
1515
input: join(fixtures, 'bundle.js'),
@@ -19,6 +19,11 @@ const oldOpts = {
1919
entry: join(fixtures, 'bundle.js'),
2020
format: 'cjs'
2121
}
22+
const expectHeader = `
23+
-----------------------------
24+
Rollup File Analysis
25+
-----------------------------
26+
`.trim()
2227

2328
// test against many versions of rollup
2429
const rollers = [
@@ -91,6 +96,17 @@ rollers.forEach(({rollup, version, opts}) => {
9196
assert.is(typeof results, 'string')
9297
})
9398

99+
let shouldFailPlugin = {latest: true, '0.60.x': true}
100+
let pluginTest = shouldFailPlugin[version] ? test.failing : test
101+
pluginTest(`${version}: plugin writes expected results`, async (assert) => {
102+
let results
103+
let writeTo = (r) => { results = r }
104+
let rollOpts = Object.assign({plugins: [plugin({writeTo})]}, opts)
105+
let bundle = await rollup(rollOpts)
106+
await bundle.generate({format: 'cjs'})
107+
assert.is(results.substr(0, expectHeader.length), expectHeader)
108+
})
109+
94110
test.failing(`${version}: tree shaking is accounted for`, async (assert) => {
95111
let bundle = await rollup(opts)
96112
let results = await analyze(bundle)

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,8 +1864,8 @@ p-finally@^1.0.0:
18641864
resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae"
18651865

18661866
p-limit@^1.1.0:
1867-
version "1.2.0"
1868-
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.2.0.tgz#0e92b6bedcb59f022c13d0f1949dc82d15909f1c"
1867+
version "1.3.0"
1868+
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.3.0.tgz#b86bd5f0c25690911c7590fcbfc2010d54b3ccb8"
18691869
dependencies:
18701870
p-try "^1.0.0"
18711871

0 commit comments

Comments
 (0)