mirror of https://github.com/lukechilds/rollup.git
Rich-Harris
10 years ago
9 changed files with 59 additions and 46 deletions
@ -0,0 +1,33 @@ |
|||
import { keys } from './object'; |
|||
|
|||
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 ) { |
|||
const exportKeys = keys( bundle.entryModule.exports ); |
|||
|
|||
if ( exportMode === 'default' ) { |
|||
if ( exportKeys.length !== 1 || exportKeys[0] !== 'default' ) { |
|||
badExports( 'default', exportKeys ); |
|||
} |
|||
} else if ( exportMode === 'none' && exportKeys.length ) { |
|||
badExports( 'none', exportKeys ); |
|||
} |
|||
|
|||
if ( !exportMode || exportMode === 'auto' ) { |
|||
if ( exportKeys.length === 0 ) { |
|||
exportMode = 'none'; |
|||
} else if ( exportKeys.length === 1 && exportKeys[0] === 'default' ) { |
|||
exportMode = 'default'; |
|||
} else { |
|||
exportMode = 'named'; |
|||
} |
|||
} |
|||
|
|||
if ( !/(?:default|named|none)/.test( exportMode ) ) { |
|||
throw new Error( `options.exports must be 'default', 'named', 'none', 'auto', or left unspecified (defaults to 'auto')` ); |
|||
} |
|||
|
|||
return exportMode; |
|||
} |
@ -0,0 +1,7 @@ |
|||
export default function getIndentString ( magicString, options ) { |
|||
if ( !( 'indent' in options ) || options.indent === true ) { |
|||
return magicString.getIndentString(); |
|||
} |
|||
|
|||
return options.indent || ''; |
|||
} |
Loading…
Reference in new issue