Skip to content

Commit

Permalink
suppress warnings with --silent (closes #1213)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Jan 7, 2017
1 parent 6384b6c commit bc0f791
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions bin/src/help.md
Expand Up @@ -23,6 +23,7 @@ Basic options:
--no-indent Don't indent result
--environment <values> Settings passed to config file (see example)
--no-conflict Generate a noConflict method for UMD globals
--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)
--banner Content to insert at top of bundle (outside wrapper)
Expand Down
4 changes: 4 additions & 0 deletions bin/src/runRollup.js
Expand Up @@ -151,6 +151,10 @@ function execute ( options, command ) {
external = ( optionsExternal || [] ).concat( commandExternal );
}

if ( command.silent ) {
options.onwarn = () => {};
}

if ( !options.onwarn ) {
const seen = new Set();

Expand Down
5 changes: 5 additions & 0 deletions test/cli/silent/_config.js
@@ -0,0 +1,5 @@
module.exports = {
description: 'does not print warnings with --silent',
command: 'rollup -i main.js -f cjs --silent',
stderr: ``
};
5 changes: 5 additions & 0 deletions test/cli/silent/_expected.js
@@ -0,0 +1,5 @@
'use strict';

var foo = 42;

assert.equal( foo, 42 );
1 change: 1 addition & 0 deletions test/cli/silent/foo.js
@@ -0,0 +1 @@
export var foo = 42;
3 changes: 3 additions & 0 deletions test/cli/silent/main.js
@@ -0,0 +1,3 @@
import { foo, bar } from './foo.js';

assert.equal( foo, 42 );
14 changes: 11 additions & 3 deletions test/test.js
Expand Up @@ -58,6 +58,10 @@ function loader ( modules ) {
};
}

function deindent ( str ) {
return str.slice( 1 ).replace( /^\t+/gm, '' ).replace( /\s+$/gm, '' ).trim();
}

function compareWarnings ( actual, expected ) {
assert.deepEqual(
actual.map( warning => {
Expand All @@ -72,7 +76,7 @@ function compareWarnings ( actual, expected ) {
}),
expected.map( warning => {
if ( warning.frame ) {
warning.frame = warning.frame.slice( 1 ).replace( /^\t+/gm, '' ).replace( /\s+$/gm, '' ).trim();
warning.frame = deindent( warning.frame );
}
return warning;
})
Expand All @@ -90,7 +94,7 @@ function compareError ( actual, expected ) {
}

if ( expected.frame ) {
expected.frame = expected.frame.slice( 1 ).replace( /^\t+/gm, '' ).replace( /\s+$/gm, '' ).trim();
expected.frame = deindent( expected.frame );
}

assert.deepEqual( actual, expected );
Expand Down Expand Up @@ -498,7 +502,11 @@ describe( 'rollup', function () {
}
}

if ( stderr ) console.error( stderr );
if ( 'stderr' in config ) {
assert.equal( deindent( config.stderr ), stderr.trim() );
} else if ( stderr ) {
console.error( stderr );
}

let unintendedError;

Expand Down

0 comments on commit bc0f791

Please sign in to comment.