From 8d5224b26dec329634c57baef2740de592b02ab8 Mon Sep 17 00:00:00 2001 From: CodeTroopers Date: Fri, 4 Aug 2017 16:19:23 +0200 Subject: [PATCH] Fix issue : In multiple configurations context, no bundle is created --- bin/src/runRollup.js | 26 +++++++++++-------- test/cli/multiple-configs/_config.js | 4 +++ .../cli/multiple-configs/_expected/bundle1.js | 5 ++++ test/cli/multiple-configs/main.js | 1 + test/cli/multiple-configs/rollup.config.js | 14 ++++++++++ 5 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 test/cli/multiple-configs/_config.js create mode 100644 test/cli/multiple-configs/_expected/bundle1.js create mode 100644 test/cli/multiple-configs/main.js create mode 100644 test/cli/multiple-configs/rollup.config.js diff --git a/bin/src/runRollup.js b/bin/src/runRollup.js index 4b6f6a4c134..81ec51e6e21 100644 --- a/bin/src/runRollup.js +++ b/bin/src/runRollup.js @@ -92,6 +92,7 @@ export default function runRollup ( command ) { const configs = require( config ); const normalized = Array.isArray( configs ) ? configs : [configs]; + const promises = []; normalized.forEach(options => { if ( Object.keys( options ).length === 0 ) { @@ -102,8 +103,12 @@ export default function runRollup ( command ) { }); } - execute( options, command ); + promises.push(new Promise((resolve) => { + execute(options, command); + resolve(); + })); }); + Promise.all(promises).catch( handleError ); require.extensions[ '.js' ] = defaultLoader; }) @@ -193,10 +198,10 @@ function execute ( options, command ) { if ( command.watch ) { if ( !options.entry || ( !options.dest && !options.targets ) ) { - handleError({ + throw { code: 'WATCHER_MISSING_INPUT_OR_OUTPUT', message: 'must specify --input and --output when using rollup --watch' - }); + }; } try { @@ -227,16 +232,16 @@ function execute ( options, command ) { }); } catch ( err ) { if ( err.code === 'MODULE_NOT_FOUND' ) { - handleError({ + throw { code: 'ROLLUP_WATCH_NOT_INSTALLED', message: 'rollup --watch depends on the rollup-watch package, which could not be found. Install it with npm install -D rollup-watch' - }); + }; } - handleError( err ); + throw err; } } else { - bundle( options ).catch( handleError ); + return bundle( options ); } } @@ -269,10 +274,10 @@ function bundle ( options ) { } if ( options.sourceMap && options.sourceMap !== 'inline' ) { - handleError({ + throw { code: 'MISSING_OUTPUT_OPTION', message: 'You must specify an --output (-o) option when creating a file with a sourcemap' - }); + }; } return bundle.generate(options).then( ({ code, map }) => { @@ -282,6 +287,5 @@ function bundle ( options ) { process.stdout.write( code ); }); - }) - .catch( handleError ); + }); } diff --git a/test/cli/multiple-configs/_config.js b/test/cli/multiple-configs/_config.js new file mode 100644 index 00000000000..1a2122b4d47 --- /dev/null +++ b/test/cli/multiple-configs/_config.js @@ -0,0 +1,4 @@ +module.exports = { + description: 'generates output file when multiple configurations are specified and one build fails', + command: 'rollup -c' +}; diff --git a/test/cli/multiple-configs/_expected/bundle1.js b/test/cli/multiple-configs/_expected/bundle1.js new file mode 100644 index 00000000000..98deb0cc09f --- /dev/null +++ b/test/cli/multiple-configs/_expected/bundle1.js @@ -0,0 +1,5 @@ +'use strict'; + +var main = 0; + +module.exports = main; diff --git a/test/cli/multiple-configs/main.js b/test/cli/multiple-configs/main.js new file mode 100644 index 00000000000..7f810d3f328 --- /dev/null +++ b/test/cli/multiple-configs/main.js @@ -0,0 +1 @@ +export default 0; diff --git a/test/cli/multiple-configs/rollup.config.js b/test/cli/multiple-configs/rollup.config.js new file mode 100644 index 00000000000..fc54e0bdf34 --- /dev/null +++ b/test/cli/multiple-configs/rollup.config.js @@ -0,0 +1,14 @@ +export default [{ + entry: 'main.js', + format: 'cjs', + dest: '_actual/bundle1.js' +}, { + entry: 'main.js', + format: 'cjs', + plugins: [{ + resolveId(id) { + throw new Error("Unexpected Exception"); + } + }], + dest: '_actual/bundle2.js' +}];