From 9461ed325eb43059e4f26caea3a67396acac99ef Mon Sep 17 00:00:00 2001 From: operandom Date: Fri, 17 Jun 2016 15:11:40 +0200 Subject: [PATCH 1/3] Handle options.external is a function. --- bin/src/runRollup.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bin/src/runRollup.js b/bin/src/runRollup.js index 45c305e..7299d07 100644 --- a/bin/src/runRollup.js +++ b/bin/src/runRollup.js @@ -95,8 +95,15 @@ const equivalents = { }; function execute ( options, command ) { - let external = ( options.external || [] ) - .concat( command.external ? command.external.split( ',' ) : [] ); + let external = command.external ? + typeof options.external === 'function' ? + ((fn, a) => { + return function (id) { + return fn() || a.indexOf(id) !== -1; + }; + })(options.external, command.external.split(',')) : + (options.external || []).concat(command.external.split(',')) : + options.external; if ( command.globals ) { let globals = Object.create( null ); @@ -218,4 +225,4 @@ function bundle ( options ) { process.stdout.write( code ); }); -} +} \ No newline at end of file From a335283a73d2ef991773de8f9dd8fe2181f85565 Mon Sep 17 00:00:00 2001 From: operandom Date: Mon, 20 Jun 2016 12:25:05 +0200 Subject: [PATCH 2/3] Add test : handle external is a function in config. --- test/cli/config-external-function/_config.js | 4 +++ .../cli/config-external-function/_expected.js | 8 ++++++ test/cli/config-external-function/main.js | 6 +++++ .../config-external-function/rollup.config.js | 25 +++++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 test/cli/config-external-function/_config.js create mode 100644 test/cli/config-external-function/_expected.js create mode 100644 test/cli/config-external-function/main.js create mode 100644 test/cli/config-external-function/rollup.config.js diff --git a/test/cli/config-external-function/_config.js b/test/cli/config-external-function/_config.js new file mode 100644 index 0000000..9f21d96 --- /dev/null +++ b/test/cli/config-external-function/_config.js @@ -0,0 +1,4 @@ +module.exports = { + description: 'external option gets passed from config', + command: 'rollup -c -e assert,external-module' +}; diff --git a/test/cli/config-external-function/_expected.js b/test/cli/config-external-function/_expected.js new file mode 100644 index 0000000..d760df4 --- /dev/null +++ b/test/cli/config-external-function/_expected.js @@ -0,0 +1,8 @@ +'use strict'; + +var ___config_js = require('./_config.js'); +var assert = require('assert'); +var externalModule = require('external-module'); + +assert.ok( ___config_js.execute ); +externalModule.method(); diff --git a/test/cli/config-external-function/main.js b/test/cli/config-external-function/main.js new file mode 100644 index 0000000..cfefa8c --- /dev/null +++ b/test/cli/config-external-function/main.js @@ -0,0 +1,6 @@ +import { execute } from './_config.js'; +import { ok } from 'assert'; +import { method } from 'external-module'; + +ok( execute ); +method(); diff --git a/test/cli/config-external-function/rollup.config.js b/test/cli/config-external-function/rollup.config.js new file mode 100644 index 0000000..ea45a3a --- /dev/null +++ b/test/cli/config-external-function/rollup.config.js @@ -0,0 +1,25 @@ +import assert from 'assert'; +import { resolve, sep } from 'path'; + +var config = resolve( './_config.js' ).split(sep).join('/'); + +export default { + entry: 'main.js', + format: 'cjs', + + external: function (id) { + if (id === config) { + return true; + } + + return false; + }, + + plugins: [ + { + load: function ( id ) { + assert.notEqual( id, config ); + } + } + ] +}; From 3b1275229784d4bd38f7cfd82061f7678fac3bff Mon Sep 17 00:00:00 2001 From: operandom Date: Mon, 20 Jun 2016 12:25:24 +0200 Subject: [PATCH 3/3] Add missing parameter. --- bin/src/runRollup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/src/runRollup.js b/bin/src/runRollup.js index 7299d07..ff89f41 100644 --- a/bin/src/runRollup.js +++ b/bin/src/runRollup.js @@ -99,7 +99,7 @@ function execute ( options, command ) { typeof options.external === 'function' ? ((fn, a) => { return function (id) { - return fn() || a.indexOf(id) !== -1; + return fn(id) || a.indexOf(id) !== -1; }; })(options.external, command.external.split(',')) : (options.external || []).concat(command.external.split(',')) :