diff --git a/bin/src/runRollup.js b/bin/src/runRollup.js index baf8753..9ef3b19 100644 --- a/bin/src/runRollup.js +++ b/bin/src/runRollup.js @@ -1,7 +1,9 @@ import { realpathSync } from 'fs'; import * as rollup from 'rollup'; import relative from 'require-relative'; +import * as chalk from 'chalk'; import handleError from './handleError'; +import relativeId from '../../src/utils/relativeId.js'; import SOURCEMAPPING_URL from './sourceMappingUrl.js'; import { install as installSourcemapSupport } from 'source-map-support'; @@ -143,7 +145,32 @@ function execute ( options, command ) { external = ( optionsExternal || [] ).concat( commandExternal ); } - options.onwarn = options.onwarn || ( warning => stderr( warning.toString() ) ); + if ( !options.onwarn ) { + const seen = new Set(); + + options.onwarn = warning => { + const str = warning.toString(); + + if ( seen.has( str ) ) return; + seen.add( str ); + + stderr( `⚠️ ${chalk.bold( warning.message )}` ); + + if ( warning.url ) { + stderr( chalk.cyan( warning.url ) ); + } + + if ( warning.loc ) { + stderr( `${relativeId( warning.loc.file )} (${warning.loc.line}:${warning.loc.column})` ); + } + + if ( warning.frame ) { + stderr( chalk.dim( warning.frame ) ); + } + + stderr( '' ); + }; + } options.external = external; diff --git a/rollup.config.cli.js b/rollup.config.cli.js index 982f6b0..5c0f673 100644 --- a/rollup.config.cli.js +++ b/rollup.config.cli.js @@ -15,7 +15,9 @@ export default { buble(), commonjs({ include: 'node_modules/**', - namedExports: { chalk: [ 'red', 'cyan', 'grey' ] } + namedExports: { + chalk: [ 'yellow', 'red', 'cyan', 'grey', 'dim', 'bold' ] + } }), nodeResolve({ main: true diff --git a/src/Bundle.js b/src/Bundle.js index 520fa45..79cd8d0 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -588,7 +588,7 @@ export default class Bundle { warn ( warning ) { warning.toString = () => { if ( warning.loc ) { - return `${warning.loc.file} (${warning.loc.line}:${warning.loc.column}) ${warning.message}`; + return `${relativeId( warning.loc.file )} (${warning.loc.line}:${warning.loc.column}) ${warning.message}`; } return warning.message;