From 19c56b87ac734a6cf79d9f2b2553a3f7bbe62f17 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sat, 2 Jan 2016 15:04:14 -0500 Subject: [PATCH] prevent resolution of external IDs (#410) --- .gitignore | 1 + src/Bundle.js | 7 +++---- .../function/external-ids-not-resolved/_config.js | 15 +++++++++++++++ test/function/external-ids-not-resolved/main.js | 2 ++ test/node_modules/external.js | 3 +++ 5 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 test/function/external-ids-not-resolved/_config.js create mode 100644 test/function/external-ids-not-resolved/main.js create mode 100644 test/node_modules/external.js diff --git a/.gitignore b/.gitignore index 15df9ff..55804cb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .DS_Store node_modules +!test/node_modules .gobble* dist _actual diff --git a/src/Bundle.js b/src/Bundle.js index 71cdd87..f69f0f9 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -31,9 +31,8 @@ export default class Bundle { this.entryModule = null; this.resolveId = first( - this.plugins - .map( plugin => plugin.resolveId ) - .filter( Boolean ) + [ id => ~this.external.indexOf( id ) ? false : null ] + .concat( this.plugins.map( plugin => plugin.resolveId ).filter( Boolean ) ) .concat( resolveId ) ); @@ -264,7 +263,7 @@ export default class Bundle { if ( this.transformers.length || this.bundleTransformers.length ) { map = collapseSourcemaps( map, usedModules, bundleSourcemapChain ); } - + map.sources = map.sources.map( unixizePath ); } diff --git a/test/function/external-ids-not-resolved/_config.js b/test/function/external-ids-not-resolved/_config.js new file mode 100644 index 0000000..c7a3b1d --- /dev/null +++ b/test/function/external-ids-not-resolved/_config.js @@ -0,0 +1,15 @@ +module.exports = { + description: 'does not attempt to resolve external IDs', + options: { + external: [ 'external' ], + plugins: [ + { + resolveId: function ( importee ) { + if ( importee === 'external' ) { + throw new Error( 'Attempted to resolve external module ID' ); + } + } + } + ] + } +}; diff --git a/test/function/external-ids-not-resolved/main.js b/test/function/external-ids-not-resolved/main.js new file mode 100644 index 0000000..43679e9 --- /dev/null +++ b/test/function/external-ids-not-resolved/main.js @@ -0,0 +1,2 @@ +import foo from 'external'; +assert.ok( foo.external ); diff --git a/test/node_modules/external.js b/test/node_modules/external.js new file mode 100644 index 0000000..377c158 --- /dev/null +++ b/test/node_modules/external.js @@ -0,0 +1,3 @@ +module.exports = { + external: true +};