Browse Source

Merge pull request #744 from rollup/gh-743

allow --globals to work with --external and options.external in whatever configuration
semi-dynamic-namespace-imports
Rich Harris 9 years ago
committed by GitHub
parent
commit
fabe1160be
  1. 25
      bin/src/runRollup.js
  2. 7
      test/cli/external-modules-auto-global/_config.js
  3. 3
      test/cli/external-modules-auto-global/main.js

25
bin/src/runRollup.js

@ -112,15 +112,10 @@ const equivalents = {
};
function execute ( options, command ) {
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;
let external;
const commandExternal = ( command.external || '' ).split( ',' );
const optionsExternal = options.external;
if ( command.globals ) {
let globals = Object.create( null );
@ -130,14 +125,22 @@ function execute ( options, command ) {
globals[ names[0] ] = names[1];
// Add missing Module IDs to external.
if ( external.indexOf( names[0] ) === -1 ) {
external.push( names[0] );
if ( commandExternal.indexOf( names[0] ) === -1 ) {
commandExternal.push( names[0] );
}
});
command.globals = globals;
}
if ( typeof optionsExternal === 'function' ) {
external = id => {
return optionsExternal( id ) || ~commandExternal.indexOf( id );
};
} else {
external = ( optionsExternal || [] ).concat( commandExternal );
}
options.onwarn = options.onwarn || stderr;
options.external = external;

7
test/cli/external-modules-auto-global/_config.js

@ -0,0 +1,7 @@
const assert = require( 'assert' );
module.exports = {
description: 'populates options.external with --global keys',
command: 'rollup main.js --format iife --globals mathematics:Math',
execute: true
};

3
test/cli/external-modules-auto-global/main.js

@ -0,0 +1,3 @@
import { max } from 'mathematics';
assert.equal( max( 1, 2, 3 ), 3 );
Loading…
Cancel
Save