From ac6c2d03db179036905843bdd7851c445f26b83f Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Mon, 21 Sep 2015 22:40:31 -0400 Subject: [PATCH] add bundle.modules - fixes #128 --- src/rollup.js | 3 +++ test/function/has-modules-array/_config.js | 13 +++++++++++++ test/function/has-modules-array/foo.js | 1 + test/function/has-modules-array/main.js | 2 ++ test/test.js | 5 ++--- 5 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 test/function/has-modules-array/_config.js create mode 100644 test/function/has-modules-array/foo.js create mode 100644 test/function/has-modules-array/main.js diff --git a/src/rollup.js b/src/rollup.js index ee2b3b0..32faf33 100644 --- a/src/rollup.js +++ b/src/rollup.js @@ -17,6 +17,9 @@ export function rollup ( options ) { return { imports: bundle.externalModules.map( module => module.id ), exports: keys( bundle.entryModule.exports ), + modules: bundle.orderedModules.map( module => { + return { id: module.id }; + }), generate: options => bundle.render( options ), write: options => { diff --git a/test/function/has-modules-array/_config.js b/test/function/has-modules-array/_config.js new file mode 100644 index 0000000..df37d84 --- /dev/null +++ b/test/function/has-modules-array/_config.js @@ -0,0 +1,13 @@ +var path = require( 'path' ); +var assert = require( 'assert' ); + +module.exports = { + description: 'user-facing bundle has modules array', + bundle: function ( bundle ) { + assert.ok( bundle.modules ); + assert.deepEqual( bundle.modules, [ + { id: path.resolve( __dirname, 'foo.js' ) }, + { id: path.resolve( __dirname, 'main.js' ) } + ]); + } +}; diff --git a/test/function/has-modules-array/foo.js b/test/function/has-modules-array/foo.js new file mode 100644 index 0000000..7a4e8a7 --- /dev/null +++ b/test/function/has-modules-array/foo.js @@ -0,0 +1 @@ +export default 42; diff --git a/test/function/has-modules-array/main.js b/test/function/has-modules-array/main.js new file mode 100644 index 0000000..3206f53 --- /dev/null +++ b/test/function/has-modules-array/main.js @@ -0,0 +1,2 @@ +import foo from './foo'; +assert.equal( foo, 42 ); diff --git a/test/test.js b/test/test.js index 4e2bd25..772b5b4 100644 --- a/test/test.js +++ b/test/test.js @@ -128,9 +128,8 @@ describe( 'rollup', function () { unintendedError = new Error( 'Expected an error while executing output' ); } - if ( config.exports ) { - config.exports( module.exports ); - } + if ( config.exports ) config.exports( module.exports ); + if ( config.bundle ) config.bundle( bundle ); } catch ( err ) { if ( config.error ) { config.error( err );