Browse Source

Try making ongenerate/onwrite more useful

semi-dynamic-namespace-imports
Pat Cavit 9 years ago
parent
commit
9acb92dcd0
  1. 7
      src/rollup.js
  2. 26
      test/test.js

7
src/rollup.js

@ -60,7 +60,7 @@ export function rollup ( options ) {
if ( plugin.ongenerate ) {
plugin.ongenerate( assign({
bundle: result
}, options ));
}, options ), rendered);
}
});
@ -79,7 +79,8 @@ export function rollup ( options ) {
}
const dest = options.dest;
let { code, map } = generate( options );
let output = generate( options );
let { code, map } = output;
let promises = [];
@ -101,7 +102,7 @@ export function rollup ( options ) {
return mapSequence( bundle.plugins.filter( plugin => plugin.onwrite ), plugin => {
return Promise.resolve( plugin.onwrite( assign({
bundle: result
}, options )));
}, options ), output));
});
});
}

26
test/test.js

@ -550,6 +550,32 @@ describe( 'rollup', function () {
});
describe( 'hooks', () => {
it( 'passes bundle & output object to ongenerate & onwrite hooks', () => {
var dest = path.join( __dirname, 'tmp/bundle.js' );
return rollup.rollup({
entry: 'entry',
plugins: [
loader({ entry: `alert('hello')` }),
{
ongenerate ( bundle, out ) {
out.ongenerate = true;
},
onwrite (bundle, out ) {
assert.equal(out.ongenerate, true);
}
}
]
}).then( bundle => {
return bundle.write({
dest
});
}).then( () => {
return sander.unlink( dest );
});
});
it( 'calls ongenerate hooks in sequence', () => {
var result = [];

Loading…
Cancel
Save