diff --git a/bin/runRollup.js b/bin/runRollup.js index 220c378..ea8ade9 100644 --- a/bin/runRollup.js +++ b/bin/runRollup.js @@ -143,6 +143,16 @@ function bundle ( options ) { return bundle.write( options ); } + if ( options.targets ) { + var result = null; + + options.targets.forEach( function ( target ) { + result = bundle.write(target); + }); + + return result; + } + if ( options.sourceMap && options.sourceMap !== 'inline' ) { handleError({ code: 'MISSING_OUTPUT_OPTION' }); } diff --git a/src/rollup.js b/src/rollup.js index 77a97bd..8a05ac4 100644 --- a/src/rollup.js +++ b/src/rollup.js @@ -27,6 +27,7 @@ const ALLOWED_KEYS = [ 'plugins', 'preferConst', 'sourceMap', + 'targets', 'treeshake', 'useStrict' ]; diff --git a/test/cli/multiple-targets/_config.js b/test/cli/multiple-targets/_config.js new file mode 100644 index 0000000..73d5d28 --- /dev/null +++ b/test/cli/multiple-targets/_config.js @@ -0,0 +1,4 @@ +module.exports = { + description: 'generates multiple output files when multiple targets are specified', + command: 'rollup -c' +}; diff --git a/test/cli/multiple-targets/_expected/cjs.js b/test/cli/multiple-targets/_expected/cjs.js new file mode 100644 index 0000000..98deb0c --- /dev/null +++ b/test/cli/multiple-targets/_expected/cjs.js @@ -0,0 +1,5 @@ +'use strict'; + +var main = 0; + +module.exports = main; diff --git a/test/cli/multiple-targets/_expected/es6.js b/test/cli/multiple-targets/_expected/es6.js new file mode 100644 index 0000000..d326592 --- /dev/null +++ b/test/cli/multiple-targets/_expected/es6.js @@ -0,0 +1,3 @@ +var main = 0; + +export default main; diff --git a/test/cli/multiple-targets/main.js b/test/cli/multiple-targets/main.js new file mode 100644 index 0000000..7f810d3 --- /dev/null +++ b/test/cli/multiple-targets/main.js @@ -0,0 +1 @@ +export default 0; diff --git a/test/cli/multiple-targets/rollup.config.js b/test/cli/multiple-targets/rollup.config.js new file mode 100644 index 0000000..db165db --- /dev/null +++ b/test/cli/multiple-targets/rollup.config.js @@ -0,0 +1,13 @@ +export default { + entry: 'main.js', + targets: [ + { + format: 'cjs', + dest: '_actual/cjs.js' + }, + { + format: 'es6', + dest: '_actual/es6.js' + } + ] +}; diff --git a/test/test.js b/test/test.js index 22239fe..d571f7f 100644 --- a/test/test.js +++ b/test/test.js @@ -76,7 +76,7 @@ describe( 'rollup', function () { return rollup.rollup({ entry: 'x', plUgins: [] }).then( function () { throw new Error( 'Missing expected error' ); }, function ( err ) { - assert.equal( err.message, 'Unexpected key \'plUgins\' found, expected one of: banner, dest, entry, exports, external, footer, format, globals, indent, intro, moduleId, moduleName, noConflict, onwarn, outro, plugins, preferConst, sourceMap, treeshake, useStrict' ); + assert.equal( err.message, 'Unexpected key \'plUgins\' found, expected one of: banner, dest, entry, exports, external, footer, format, globals, indent, intro, moduleId, moduleName, noConflict, onwarn, outro, plugins, preferConst, sourceMap, targets, treeshake, useStrict' ); }); }); }); @@ -353,9 +353,13 @@ describe( 'rollup', function () { PATH: path.resolve( __dirname, '../bin' ) + path.delimiter + process.env.PATH } }, function ( err, code, stderr ) { - if ( err || config.error ) { - config.error( err ); - return done(); + if ( err ) { + if ( config.error ) { + config.error( err ); + return done(); + } else { + throw err; + } } if ( stderr ) console.error( stderr ); @@ -409,6 +413,20 @@ describe( 'rollup', function () { } } + else if ( sander.existsSync( '_expected' ) && sander.statSync( '_expected' ).isDirectory() ) { + var error = null; + sander.readdirSync( '_expected' ).forEach( child => { + var expected = sander.readFileSync( path.join( '_expected', child ) ).toString(); + var actual = sander.readFileSync( path.join( '_actual', child ) ).toString(); + try { + assert.equal( normaliseOutput( actual ), normaliseOutput( expected ) ); + } catch ( err ) { + error = err; + } + }); + done( error ); + } + else { var expected = sander.readFileSync( '_expected.js' ).toString(); try {