Skip to content

Commit

Permalink
* Improve deprecation warnings for some options
Browse files Browse the repository at this point in the history
* Update CLI list
  • Loading branch information
lukastaegert committed Nov 29, 2017
1 parent 24231ce commit 030eef7
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 38 deletions.
2 changes: 2 additions & 0 deletions bin/src/help.md
Expand Up @@ -18,12 +18,14 @@ Basic options:
Any module IDs defined here are added to external
-n, --name Name for UMD export
-m, --sourcemap Generate sourcemap (`-m inline` for inline map)
-l, --legacy Support IE8
--amd.id ID for AMD module (default is anonymous)
--amd.define Function to use in place of `define`
--no-strict Don't emit a `"use strict";` in the generated modules.
--no-indent Don't indent result
--environment <values> Settings passed to config file (see example)
--no-conflict Generate a noConflict method for UMD globals
--no-treeshake Disable tree-shaking
--silent Don't print warnings
--intro Content to insert at top of bundle (inside wrapper)
--outro Content to insert at end of bundle (inside wrapper)
Expand Down
1 change: 0 additions & 1 deletion bin/src/index.js
Expand Up @@ -20,7 +20,6 @@ const command = minimist( process.argv.slice( 2 ), {
m: 'sourcemap',
n: 'name',
o: 'output.file',
u: 'id',
v: 'version',
w: 'watch'
}
Expand Down
2 changes: 1 addition & 1 deletion bin/src/run/batchWarnings.js
Expand Up @@ -281,4 +281,4 @@ function showTruncatedWarnings(warnings) {
if ( nestedByModule.length > sliced.length ) {
stderr( `\n...and ${nestedByModule.length - sliced.length} other files` );
}
}
}
2 changes: 1 addition & 1 deletion bin/src/run/build.js
Expand Up @@ -42,4 +42,4 @@ export default function build ( inputOptions, outputOptions, warnings, silent )
if ( !silent ) stderr( chalk.green( `created ${chalk.bold( files.join( ', ' ) )} in ${chalk.bold(ms( Date.now() - start))}` ) );
})
.catch( handleError );
}
}
20 changes: 10 additions & 10 deletions bin/src/run/deprecateOptions.js
Expand Up @@ -2,52 +2,52 @@ export default function deprecateOptions ( options ) {
const deprecations = [];

if ( options.entry ) {
deprecations.push( { old: 'options.entry', new: 'options.input' } );
deprecations.push( { old: 'entry', new: 'input' } );
options.input = options.entry; // don't delete, as plugins sometimes depend on this...
}

if ( options.moduleName ) {
deprecations.push( { old: 'options.moduleName', new: 'options.name' } );
deprecations.push( { old: 'moduleName', new: 'output.name' } );
options.name = options.moduleName;
delete options.moduleName;
}

if ( options.sourceMap ) {
deprecations.push( { old: 'options.sourceMap', new: 'options.sourcemap' } );
deprecations.push( { old: 'sourceMap', new: 'output.sourcemap' } );
options.sourcemap = options.sourceMap;
delete options.sourceMap;
}

if ( options.sourceMapFile ) {
deprecations.push( { old: 'options.sourceMapFile', new: 'options.sourcemapFile' } );
deprecations.push( { old: 'sourceMapFile', new: 'output.sourcemapFile' } );
options.sourcemapFile = options.sourceMapFile;
delete options.sourceMapFile;
}

if ( options.useStrict ) {
deprecations.push( { old: 'options.useStrict', new: 'options.strict' } );
deprecations.push( { old: 'useStrict', new: 'output.strict' } );
options.strict = options.useStrict;
delete options.useStrict;
}

if ( options.targets ) {
deprecations.push( { old: 'options.targets', new: 'options.output' } );
deprecations.push( { old: 'targets', new: 'output' } );
options.output = options.targets;
delete options.targets;

let deprecatedDest = false;
options.output.forEach( output => {
if ( output.dest ) {
if ( !deprecatedDest ) {
deprecations.push( { old: 'output.dest', new: 'output.file' } );
deprecations.push( { old: 'targets.dest', new: 'output.file' } );
deprecatedDest = true;
}
output.file = output.dest;
delete output.dest;
}
} );
} else if ( options.dest ) {
deprecations.push( { old: 'options.dest', new: 'options.output.file' } );
deprecations.push( { old: 'dest', new: 'output.file' } );
options.output = {
file: options.dest,
format: options.format
Expand All @@ -57,12 +57,12 @@ export default function deprecateOptions ( options ) {

if ( options.format ) {
if ( !options.output ) options.output = { format: options.format };
deprecations.push( { old: 'options.format', new: 'options.output.format' } );
deprecations.push( { old: 'format', new: 'output.format' } );
delete options.format;
}

if ( options.pureExternalModules ) {
deprecations.push( { old: 'options.pureExternalModules', new: 'options.treeshake.pureExternalModules' } );
deprecations.push( { old: 'pureExternalModules', new: 'treeshake.pureExternalModules' } );
if ( options.treeshake === undefined ) {
options.treeshake = {};
}
Expand Down
46 changes: 23 additions & 23 deletions src/rollup/index.js
Expand Up @@ -94,7 +94,7 @@ function checkInputOptions ( options, warn ) {
if ( err ) throw err;
}

const deprecated = {
const deprecatedOutputOptions = {
dest: 'file',
moduleName: 'name',
sourceMap: 'sourcemap',
Expand Down Expand Up @@ -129,10 +129,10 @@ function checkOutputOptions ( options, warn ) {
}

const deprecations = [];
Object.keys( deprecated ).forEach( old => {
Object.keys( deprecatedOutputOptions ).forEach( old => {
if ( old in options ) {
deprecations.push( { old, new: deprecated[ old ] } );
options[ deprecated[ old ] ] = options[ old ];
deprecations.push( { old, new: deprecatedOutputOptions[ old ] } );
options[ deprecatedOutputOptions[ old ] ] = options[ old ];
delete options[ old ];
}
} );
Expand All @@ -154,41 +154,41 @@ const throwAsyncGenerateError = {
}
};

export default function rollup ( options ) {
export default function rollup ( inputOptions ) {
try {
if ( !options ) {
if ( !inputOptions ) {
throw new Error( 'You must supply an options object to rollup' );
}

const warn = options.onwarn || (warning => console.warn( warning.message )); // eslint-disable-line no-console
const warn = inputOptions.onwarn || (warning => console.warn( warning.message )); // eslint-disable-line no-console

checkInputOptions( options, warn );
const bundle = new Bundle( options );
checkInputOptions( inputOptions, warn );
const bundle = new Bundle( inputOptions );

timeStart( '--BUILD--' );

return bundle.build().then( () => {
timeEnd( '--BUILD--' );

function generate ( options ) {
if ( !options ) {
function generate ( outputOptions ) {
if ( !outputOptions ) {
throw new Error( 'You must supply an options object' );
}
checkOutputOptions( options, warn );
checkAmd( options );
checkOutputOptions( outputOptions, warn );
checkAmd( outputOptions );

timeStart( '--GENERATE--' );

const promise = Promise.resolve()
.then( () => bundle.render( options ) )
.then( () => bundle.render( outputOptions ) )
.then( rendered => {
timeEnd( '--GENERATE--' );

bundle.plugins.forEach( plugin => {
if ( plugin.ongenerate ) {
plugin.ongenerate( assign( {
bundle: result
}, options ), rendered );
}, outputOptions ), rendered );
}
} );

Expand All @@ -209,24 +209,24 @@ export default function rollup ( options ) {
modules: bundle.orderedModules.map( module => module.toJSON() ),

generate,
write: options => {
if ( !options || (!options.file && !options.dest) ) {
write: outputOptions => {
if ( !outputOptions || (!outputOptions.file && !outputOptions.dest) ) {
error( {
code: 'MISSING_OPTION',
message: 'You must specify options.file'
message: 'You must specify output.file'
} );
}

return generate( options ).then( result => {
const file = options.file;
return generate( outputOptions ).then( result => {
const file = outputOptions.file;
let { code, map } = result;

const promises = [];

if ( options.sourcemap ) {
if ( outputOptions.sourcemap ) {
let url;

if ( options.sourcemap === 'inline' ) {
if ( outputOptions.sourcemap === 'inline' ) {
url = map.toUrl();
} else {
url = `${basename( file )}.map`;
Expand All @@ -241,7 +241,7 @@ export default function rollup ( options ) {
return mapSequence( bundle.plugins.filter( plugin => plugin.onwrite ), plugin => {
return Promise.resolve( plugin.onwrite( assign( {
bundle: result
}, options ), result ) );
}, outputOptions ), result ) );
} );
} );
} );
Expand Down
4 changes: 2 additions & 2 deletions test/misc/index.js
Expand Up @@ -169,11 +169,11 @@ describe('bundle.write()', () => {
.then(bundle => {
assert.throws(() => {
bundle.write();
}, /You must specify options\.file/);
}, /You must specify output\.file/);

assert.throws(() => {
bundle.write({});
}, /You must specify options\.file/);
}, /You must specify output\.file/);
});
});

Expand Down

0 comments on commit 030eef7

Please sign in to comment.