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 1/3] 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 ); + } + } + ] +}; From 283eefa946d3cef14827181a9f69052f19793a69 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 4 Jan 2016 17:40:23 -0500 Subject: [PATCH 2/3] windows fix? --- src/Bundle.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Bundle.js b/src/Bundle.js index 02fed68..a652d90 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -59,7 +59,7 @@ export default class Bundle { this.assumedGlobals = blank(); - this.external = options.external || []; + this.external = ensureArray( options.external ).map( id => id.replace( /[\/\\]/g, '/' ) ); this.onwarn = options.onwarn || makeOnwarn(); // TODO strictly speaking, this only applies with non-ES6, non-default-only bundles @@ -172,8 +172,8 @@ export default class Bundle { const promises = module.dependencies.map( source => { return Promise.resolve( this.resolveId( source, module.id ) ) .then( resolvedId => { - // If the `resolvedId` is supposed to be exteral, make it so. - const forcedExternal = ~this.external.indexOf( resolvedId ); + // If the `resolvedId` is supposed to be external, make it so. + const forcedExternal = ~this.external.indexOf( resolvedId.replace( /[\/\\]/g, '/' ) ); if ( !resolvedId || forcedExternal ) { if ( !forcedExternal ) { From e53bd850e77fef9de8853a0d8f96a267db5af039 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 4 Jan 2016 17:47:32 -0500 Subject: [PATCH 3/3] doh --- src/Bundle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle.js b/src/Bundle.js index a652d90..529f61e 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -173,7 +173,7 @@ export default class Bundle { return Promise.resolve( this.resolveId( source, module.id ) ) .then( resolvedId => { // If the `resolvedId` is supposed to be external, make it so. - const forcedExternal = ~this.external.indexOf( resolvedId.replace( /[\/\\]/g, '/' ) ); + const forcedExternal = resolvedId && ~this.external.indexOf( resolvedId.replace( /[\/\\]/g, '/' ) ); if ( !resolvedId || forcedExternal ) { if ( !forcedExternal ) {