Permalink
Browse files

suppress warnings with --silent (closes #1213)

  • Loading branch information...
1 parent 6384b6c commit bc0f791195770066de09a6a644d898fd4758b211 @Rich-Harris Rich-Harris committed Jan 7, 2017
Showing with 30 additions and 3 deletions.
  1. +1 −0 bin/src/help.md
  2. +4 −0 bin/src/runRollup.js
  3. +5 −0 test/cli/silent/_config.js
  4. +5 −0 test/cli/silent/_expected.js
  5. +1 −0 test/cli/silent/foo.js
  6. +3 −0 test/cli/silent/main.js
  7. +11 −3 test/test.js
View
@@ -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)
@@ -151,6 +151,10 @@ function execute ( options, command ) {
external = ( optionsExternal || [] ).concat( commandExternal );
}
+ if ( command.silent ) {
+ options.onwarn = () => {};
+ }
+
if ( !options.onwarn ) {
const seen = new Set();
@@ -0,0 +1,5 @@
+module.exports = {
+ description: 'does not print warnings with --silent',
+ command: 'rollup -i main.js -f cjs --silent',
+ stderr: ``
+};
@@ -0,0 +1,5 @@
+'use strict';
+
+var foo = 42;
+
+assert.equal( foo, 42 );
@@ -0,0 +1 @@
+export var foo = 42;
@@ -0,0 +1,3 @@
+import { foo, bar } from './foo.js';
+
+assert.equal( foo, 42 );
View
@@ -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 => {
@@ -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;
})
@@ -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 );
@@ -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;

0 comments on commit bc0f791

Please sign in to comment.