From 87983313895ca2aea0ad0fb3c732636e96bc2e49 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Thu, 23 Jun 2016 09:02:32 +0300 Subject: [PATCH] Warn on namespace conflicts --- src/Bundle.js | 7 +------ src/rollup.js | 3 +-- test/function/double-named-export-from/_config.js | 9 ++++----- test/test.js | 2 +- 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/Bundle.js b/src/Bundle.js index 1f7c78a..988ef7e 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -26,8 +26,6 @@ export default class Bundle { }); } - this.failOnExportAllDup = Boolean( options.failOnExportAllDup ); - this.plugins = ensureArray( options.plugins ); this.plugins.forEach( plugin => { @@ -213,9 +211,6 @@ export default class Bundle { this.moduleById.set( id, module ); return this.fetchAllDependencies( module ).then( () => { - if ( !this.failOnExportAllDup ) { - return module; - } module.exportsAll = blank(); keys( module.exports ).forEach( name => { module.exportsAll[name] = module.id; @@ -225,7 +220,7 @@ export default class Bundle { const exportAllModule = this.moduleById.get( id ); keys( exportAllModule.exportsAll ).forEach( name => { if ( name in module.exportsAll ) { - throw new Error( `A module cannot have multiple exports with the same name ('${name}')` + + this.onwarn( `A module cannot have multiple exports with the same name ('${name}')` + ` from ${module.exportsAll[ name ] } and ${exportAllModule.exportsAll[ name ]}` ); } module.exportsAll[ name ] = exportAllModule.exportsAll[ name ]; diff --git a/src/rollup.js b/src/rollup.js index 5399dc3..a9c50fd 100644 --- a/src/rollup.js +++ b/src/rollup.js @@ -31,8 +31,7 @@ const ALLOWED_KEYS = [ 'sourceMapFile', 'targets', 'treeshake', - 'useStrict', - 'failOnExportAllDup' + 'useStrict' ]; export function rollup ( options ) { diff --git a/test/function/double-named-export-from/_config.js b/test/function/double-named-export-from/_config.js index 0aaa1f5..183bb4c 100644 --- a/test/function/double-named-export-from/_config.js +++ b/test/function/double-named-export-from/_config.js @@ -6,12 +6,11 @@ function normalize( file ) { } module.exports = { + solo: true, description: 'throws on duplicate export * from', - options: { - failOnExportAllDup: true - }, - error: err => { - assert.equal( err.message, `A module cannot have multiple exports with the same name ('foo')` + + warnings(warnings) { + assert.equal( warnings[0], `A module cannot have multiple exports with the same name ('foo')` + ` from ${normalize( 'foo.js' )} and ${normalize( 'deep.js' )}` ); + assert.equal( warnings.length, 1 ); } }; diff --git a/test/test.js b/test/test.js index 6bd60b1..30ec5f2 100644 --- a/test/test.js +++ b/test/test.js @@ -76,7 +76,7 @@ describe( 'rollup', function () { return rollup.rollup({ entry: 'x', plUgins: [] }).then( function () { throw new Error( 'Missing expected error' ); }, function ( err ) { - assert.equal( err.message, 'Unexpected key \'plUgins\' found, expected one of: acorn, banner, cache, dest, entry, exports, external, footer, format, globals, indent, intro, moduleId, moduleName, noConflict, onwarn, outro, plugins, preferConst, sourceMap, sourceMapFile, targets, treeshake, useStrict, failOnExportAllDup' ); + assert.equal( err.message, 'Unexpected key \'plUgins\' found, expected one of: acorn, banner, cache, dest, entry, exports, external, footer, format, globals, indent, intro, moduleId, moduleName, noConflict, onwarn, outro, plugins, preferConst, sourceMap, sourceMapFile, targets, treeshake, useStrict' ); }); }); });