Browse Source

Merge pull request #1200 from rollup/gh-1197

warn on missing format
gh-786
Rich Harris 8 years ago
committed by GitHub
parent
commit
c597b91368
  1. 6
      src/Bundle.js
  2. 12
      src/rollup.js
  3. 2
      test/cli/sourcemap-newline/_config.js
  4. 19
      test/test.js

6
src/Bundle.js

@ -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 );
@ -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 );
@ -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' );

12
src/rollup.js

@ -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 );

2
test/cli/sourcemap-newline/_config.js

@ -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' );
}

19
test/test.js

@ -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()', () => {

Loading…
Cancel
Save