From a3e7b07e850c991a69681cf8f089cf31fb0f464c Mon Sep 17 00:00:00 2001 From: Federico Brigante Date: Tue, 20 Sep 2016 09:34:07 +0700 Subject: [PATCH] Avoid exports:auto warning on format:es --- src/Bundle.js | 2 +- src/utils/getExportMode.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Bundle.js b/src/Bundle.js index a4e8c53..2f4b0f9 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -350,7 +350,7 @@ export default class Bundle { const format = options.format || 'es'; // Determine export mode - 'default', 'named', 'none' - const exportMode = getExportMode( this, options.exports, options.moduleName ); + const exportMode = getExportMode( this, options ); let magicString = new MagicStringBundle({ separator: '\n\n' }); const usedModules = []; diff --git a/src/utils/getExportMode.js b/src/utils/getExportMode.js index f37ff1e..a3d00a0 100644 --- a/src/utils/getExportMode.js +++ b/src/utils/getExportMode.js @@ -4,7 +4,7 @@ function badExports ( option, keys ) { throw new Error( `'${option}' was specified for options.exports, but entry module has following exports: ${keys.join(', ')}` ); } -export default function getExportMode ( bundle, exportMode, moduleName ) { +export default function getExportMode ( bundle, {exports: exportMode, moduleName, format} ) { const exportKeys = keys( bundle.entryModule.exports ) .concat( keys( bundle.entryModule.reexports ) ) .concat( bundle.entryModule.exportAllSources ); // not keys, but makes our job easier this way @@ -23,7 +23,7 @@ export default function getExportMode ( bundle, exportMode, moduleName ) { } else if ( exportKeys.length === 1 && exportKeys[0] === 'default' ) { exportMode = 'default'; } else { - if ( bundle.entryModule.exports.default ) { + if ( bundle.entryModule.exports.default && format !== 'es') { bundle.onwarn( `Using named and default exports together. Consumers of your bundle will have to use ${moduleName || 'bundle'}['default'] to access the default export, which may not be what you want. Use \`exports: 'named'\` to disable this warning. See https://github.com/rollup/rollup/wiki/JavaScript-API#exports for more information` ); } exportMode = 'named';