diff --git a/bin/src/logging.js b/bin/src/logging.js index 33b84af..16dd8b5 100644 --- a/bin/src/logging.js +++ b/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 ); } diff --git a/src/Bundle.js b/src/Bundle.js index 26e6229..6ce3024 100644 --- a/src/Bundle.js +++ b/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 ); diff --git a/src/utils/transform.js b/src/utils/transform.js index 8d0f9bb..6581882 100644 --- a/src/utils/transform.js +++ b/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 ); }, diff --git a/test/function/plugin-warn/_config.js b/test/function/plugin-warn/_config.js index 1fd2f8c..78ee253 100644 --- a/test/function/plugin-warn/_config.js +++ b/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,