From 0b92d518d132926c43e87bcab122edab16bbf2af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Segersv=C3=A4rd?= Date: Mon, 4 Jan 2016 15:49:48 +0100 Subject: [PATCH] Force ids specified in `external` to actually _be_ external. Fixes #410 Builds on top of #417 --- src/Bundle.js | 11 ++++++++--- test/cli/config-external/_config.js | 4 ++++ test/cli/config-external/_expected.js | 6 ++++++ test/cli/config-external/main.js | 4 ++++ test/cli/config-external/rollup.config.js | 19 +++++++++++++++++++ 5 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 test/cli/config-external/_config.js create mode 100644 test/cli/config-external/_expected.js create mode 100644 test/cli/config-external/main.js create mode 100644 test/cli/config-external/rollup.config.js diff --git a/src/Bundle.js b/src/Bundle.js index f69f0f9..02fed68 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -172,9 +172,14 @@ export default class Bundle { const promises = module.dependencies.map( source => { return Promise.resolve( this.resolveId( source, module.id ) ) .then( resolvedId => { - if ( !resolvedId ) { - if ( isRelative( source ) ) throw new Error( `Could not resolve ${source} from ${module.id}` ); - if ( !~this.external.indexOf( source ) ) this.onwarn( `Treating '${source}' as external dependency` ); + // If the `resolvedId` is supposed to be exteral, make it so. + const forcedExternal = ~this.external.indexOf( resolvedId ); + + if ( !resolvedId || forcedExternal ) { + if ( !forcedExternal ) { + if ( isRelative( source ) ) throw new Error( `Could not resolve ${source} from ${module.id}` ); + if ( !~this.external.indexOf( source ) ) this.onwarn( `Treating '${source}' as external dependency` ); + } module.resolvedIds[ source ] = source; if ( !this.moduleById[ source ] ) { diff --git a/test/cli/config-external/_config.js b/test/cli/config-external/_config.js new file mode 100644 index 0000000..59df4b7 --- /dev/null +++ b/test/cli/config-external/_config.js @@ -0,0 +1,4 @@ +module.exports = { + description: 'external option gets passed from config', + command: 'rollup -c' +}; diff --git a/test/cli/config-external/_expected.js b/test/cli/config-external/_expected.js new file mode 100644 index 0000000..d90f80a --- /dev/null +++ b/test/cli/config-external/_expected.js @@ -0,0 +1,6 @@ +'use strict'; + +var ___config_js = require('./_config.js'); +var assert = require('assert'); + +assert.ok( ___config_js.execute ); diff --git a/test/cli/config-external/main.js b/test/cli/config-external/main.js new file mode 100644 index 0000000..e012c1d --- /dev/null +++ b/test/cli/config-external/main.js @@ -0,0 +1,4 @@ +import { execute } from './_config.js'; +import { ok } from 'assert'; + +ok( execute ); diff --git a/test/cli/config-external/rollup.config.js b/test/cli/config-external/rollup.config.js new file mode 100644 index 0000000..56559d2 --- /dev/null +++ b/test/cli/config-external/rollup.config.js @@ -0,0 +1,19 @@ +import assert from 'assert'; +import { resolve } from 'path'; + +var config = resolve( './_config.js' ); + +export default { + entry: 'main.js', + format: 'cjs', + + external: [ 'assert', config ], + + plugins: [ + { + load: function ( id ) { + assert.notEqual( id, config ); + } + } + ] +};