Skip to content

Commit

Permalink
Merge pull request #1200 from rollup/gh-1197
Browse files Browse the repository at this point in the history
warn on missing format
  • Loading branch information
Rich-Harris committed Dec 29, 2016
2 parents 979cfc2 + 708fb98 commit c597b91
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/Bundle.js
Expand Up @@ -398,8 +398,6 @@ export default class Bundle {
options.format = 'es';
}

const format = options.format || 'es';

// Determine export mode - 'default', 'named', 'none'
const exportMode = getExportMode( this, options );

Expand All @@ -409,7 +407,7 @@ export default class Bundle {
timeStart( 'render modules' );

this.orderedModules.forEach( module => {
const source = module.render( format === 'es', this.legacy );
const source = module.render( options.format === 'es', this.legacy );

if ( source.toString().length ) {
magicString.addSource( source );
Expand Down Expand Up @@ -446,7 +444,7 @@ export default class Bundle {

const indentString = getIndentString( magicString, options );

const finalise = finalisers[ format ];
const finalise = finalisers[ options.format ];
if ( !finalise ) throw new Error( `You must specify an output type - valid options are ${keys( finalisers ).join( ', ' )}` );

timeStart( 'render format' );
Expand Down
12 changes: 11 additions & 1 deletion src/rollup.js
Expand Up @@ -67,7 +67,17 @@ export function rollup ( options ) {
return bundle.build().then( () => {
timeEnd( '--BUILD--' );

function generate ( options ) {
function generate ( options = {} ) {
if ( !options.format ) {
bundle.warn({
code: 'MISSING_FORMAT',
message: `No format option was supplied – defaulting to 'es'`,
url: `https://github.com/rollup/rollup/wiki/JavaScript-API#format`
});

options.format = 'es';
}

timeStart( '--GENERATE--' );

const rendered = bundle.render( options );
Expand Down
2 changes: 1 addition & 1 deletion test/cli/sourcemap-newline/_config.js
Expand Up @@ -2,7 +2,7 @@ const assert = require( 'assert' );

module.exports = {
description: 'adds a newline after the sourceMappingURL comment (#756)',
command: 'rollup -i main.js -m inline',
command: 'rollup -i main.js -f es -m inline',
result: code => {
assert.equal( code.slice( -1 ), '\n' );
}
Expand Down
19 changes: 19 additions & 0 deletions test/test.js
Expand Up @@ -133,6 +133,25 @@ describe( 'rollup', function () {
assert.ok( code[ code.length - 1 ] === '\n' );
});
});

it( 'warns on missing format option', () => {
const warnings = [];

return rollup.rollup({
entry: 'x',
plugins: [ loader({ x: `console.log( 42 );` }) ],
onwarn: warning => warnings.push( warning )
}).then( bundle => {
bundle.generate();
compareWarnings( warnings, [
{
code: 'MISSING_FORMAT',
message: `No format option was supplied – defaulting to 'es'`,
url: `https://github.com/rollup/rollup/wiki/JavaScript-API#format`
}
]);
});
});
});

describe( 'bundle.write()', () => {
Expand Down

0 comments on commit c597b91

Please sign in to comment.