Browse Source

Merge pull request #724 from operandom/debug-cli-external

Handle options.external is a function.
semi-dynamic-namespace-imports
Rich Harris 9 years ago
committed by GitHub
parent
commit
1a79c69d02
  1. 13
      bin/src/runRollup.js
  2. 4
      test/cli/config-external-function/_config.js
  3. 8
      test/cli/config-external-function/_expected.js
  4. 6
      test/cli/config-external-function/main.js
  5. 25
      test/cli/config-external-function/rollup.config.js

13
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(id) || 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 );
});
}
}

4
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'
};

8
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();

6
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();

25
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 );
}
}
]
};
Loading…
Cancel
Save