From 1111e144a87c3bbf30b9607d8c1f3cdde907b310 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sat, 27 Jun 2015 13:07:43 -0400 Subject: [PATCH] support moduleId and moduleName via CLI (fixes #24) --- bin/runRollup.js | 4 +++- test/cli/module-name/_config.js | 4 ++++ test/cli/module-name/_expected.js | 11 +++++++++++ test/cli/module-name/main.js | 1 + test/test.js | 14 ++++++++++++++ 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 test/cli/module-name/_config.js create mode 100644 test/cli/module-name/_expected.js create mode 100644 test/cli/module-name/main.js diff --git a/bin/runRollup.js b/bin/runRollup.js index 0ace1ee..748ec1a 100644 --- a/bin/runRollup.js +++ b/bin/runRollup.js @@ -39,7 +39,9 @@ function bundle ( options, method ) { }).then( function ( bundle ) { var generateOptions = { dest: options.output, - format: options.format + format: options.format, + moduleId: options.id, + moduleName: options.name }; if ( options.output ) { diff --git a/test/cli/module-name/_config.js b/test/cli/module-name/_config.js new file mode 100644 index 0000000..49c1fa4 --- /dev/null +++ b/test/cli/module-name/_config.js @@ -0,0 +1,4 @@ +module.exports = { + description: 'generates UMD export with correct moduleName', + command: 'rollup main.js --format umd --name myBundle' +} diff --git a/test/cli/module-name/_expected.js b/test/cli/module-name/_expected.js new file mode 100644 index 0000000..b5aa08a --- /dev/null +++ b/test/cli/module-name/_expected.js @@ -0,0 +1,11 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + global.myBundle = factory(); +}(this, function () { 'use strict'; + + var main = 42; + + return main; + +})); diff --git a/test/cli/module-name/main.js b/test/cli/module-name/main.js new file mode 100644 index 0000000..7a4e8a7 --- /dev/null +++ b/test/cli/module-name/main.js @@ -0,0 +1 @@ +export default 42; diff --git a/test/test.js b/test/test.js index 28bf18f..02a92d3 100644 --- a/test/test.js +++ b/test/test.js @@ -295,6 +295,20 @@ describe( 'rollup', function () { unintendedError ? done( unintendedError ) : done(); } + + else if ( config.result ) { + try { + config.result( code ); + } catch ( err ) { + done( err ); + } + } + + else { + var expected = sander.readFileSync( '_expected.js' ).toString(); + assert.equal( code.trim(), expected.trim() ); + done(); + } }); }); });