Browse Source

richer warnings in CLI

gh-786
Rich-Harris 8 years ago
parent
commit
f695e628d6
  1. 29
      bin/src/runRollup.js
  2. 4
      rollup.config.cli.js
  3. 2
      src/Bundle.js

29
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;

4
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

2
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;

Loading…
Cancel
Save