Browse Source

use plugin names in CLI logs

gh-1187
Rich Harris 8 years ago
parent
commit
be7c90f0c7
  1. 41
      bin/src/logging.js
  2. 10
      src/Bundle.js
  3. 1
      src/utils/transform.js
  4. 2
      test/function/plugin-warn/_config.js

41
bin/src/logging.js

@ -8,40 +8,33 @@ const errorSymbol = process.stderr.isTTY ? `🚨 ` : `Error: `;
// log to stderr to keep `rollup main.js > bundle.js` from breaking
export const stderr = console.error.bind( console ); // eslint-disable-line no-console
export function handleWarning ( warning ) {
stderr( `${warnSymbol}${chalk.bold( warning.message )}` );
function log ( object, symbol ) {
const message = object.plugin ? `(${object.plugin} plugin) ${object.message}` : object.message;
stderr( `${symbol}${chalk.bold( message )}` );
if ( warning.url ) {
stderr( chalk.cyan( warning.url ) );
if ( object.url ) {
stderr( chalk.cyan( object.url ) );
}
if ( warning.loc ) {
stderr( `${relativeId( warning.loc.file )} (${warning.loc.line}:${warning.loc.column})` );
if ( object.loc ) {
stderr( `${relativeId( object.loc.file )} (${object.loc.line}:${object.loc.column})` );
} else if ( object.id ) {
stderr( relativeId( object.id ) );
}
if ( warning.frame ) {
stderr( chalk.dim( warning.frame ) );
if ( object.frame ) {
stderr( chalk.dim( object.frame ) );
}
stderr( '' );
}
export function handleError ( err, recover ) {
stderr( `${errorSymbol}${chalk.bold( err.message )}` );
if ( err.url ) {
stderr( chalk.cyan( err.url ) );
}
if ( err.loc ) {
stderr( `${relativeId( err.loc.file )} (${err.loc.line}:${err.loc.column})` );
}
if ( err.frame ) {
stderr( chalk.dim( err.frame ) );
}
stderr( '' );
export function handleWarning ( warning ) {
log( warning, warnSymbol );
}
export function handleError ( err, recover ) {
log( err, errorSymbol );
if ( !recover ) process.exit( 1 );
}

10
src/Bundle.js

@ -619,11 +619,13 @@ export default class Bundle {
warn ( warning ) {
warning.toString = () => {
if ( warning.loc ) {
return `${relativeId( warning.loc.file )} (${warning.loc.line}:${warning.loc.column}) ${warning.message}`;
}
let str = '';
if ( warning.plugin ) str += `(${warning.plugin} plugin) `;
if ( warning.loc ) str += `${relativeId( warning.loc.file )} (${warning.loc.line}:${warning.loc.column}) `;
str += warning.message;
return warning.message;
return str;
};
this.onwarn( warning );

1
src/utils/transform.js

@ -44,6 +44,7 @@ export default function transform ( bundle, source, id, plugins ) {
warn: ( warning, pos ) => {
warning = augment( warning, pos, 'PLUGIN_WARNING' );
warning.plugin = plugin.name;
warning.id = id;
bundle.warn( warning );
},

2
test/function/plugin-warn/_config.js

@ -15,11 +15,13 @@ module.exports = {
warnings: [
{
code: 'PLUGIN_WARNING',
id: path.resolve( __dirname, 'main.js' ),
plugin: 'test',
message: 'foo'
},
{
code: 'PLUGIN_WARNING',
id: path.resolve( __dirname, 'main.js' ),
plugin: 'test',
message: 'bar',
pos: 22,

Loading…
Cancel
Save