diff --git a/src/Bundle.js b/src/Bundle.js index bdb7da8..7db5585 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -178,8 +178,15 @@ export default class Bundle { return mapSequence( module.sources, source => { return this.resolveId( source, module.id ) .then( resolvedId => { - // If the `resolvedId` is supposed to be external, make it so. - const forcedExternal = resolvedId && ~this.external.indexOf( resolvedId.replace( /[\/\\]/g, '/' ) ); + let externalName; + if ( resolvedId ) { + // If the `resolvedId` is supposed to be external, make it so. + externalName = resolvedId.replace( /[\/\\]/g, '/' ); + } else if ( isRelative( source ) ) { + // This could be an external, relative dependency, based on the current module's parent dir. + externalName = resolve( module.id, '..', source ); + } + const forcedExternal = externalName && ~this.external.indexOf( externalName ); if ( !resolvedId || forcedExternal ) { if ( !forcedExternal ) { diff --git a/test/function/configure-relative-external-module/_config.js b/test/function/configure-relative-external-module/_config.js new file mode 100644 index 0000000..bbcebcf --- /dev/null +++ b/test/function/configure-relative-external-module/_config.js @@ -0,0 +1,21 @@ +var assert = require( 'assert' ); +var path = require( 'path' ); + +var mockedValue = { + val: 'A value' +}; + +module.exports = { + description: 'allows a nonexistent relative module to be configured as external', + options: { + external: [ path.join( __dirname, './nonexistent-relative-dependency.js') ] + }, + context: { + require: function() { + return mockedValue; + } + }, + exports: function () { + assert.equal( mockedValue.wasAltered, true ); + } +}; diff --git a/test/function/configure-relative-external-module/main.js b/test/function/configure-relative-external-module/main.js new file mode 100644 index 0000000..317fa9f --- /dev/null +++ b/test/function/configure-relative-external-module/main.js @@ -0,0 +1,3 @@ +import relativeDep from './nonexistent-relative-dependency.js'; + +relativeDep.wasAltered = true;