Skip to content

Commit

Permalink
fix: honor options.stream everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
Pooya Parsa committed Mar 31, 2018
1 parent 4af75bc commit 34733b7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
parseRequst,
formatRequest,
renderBar,
printStats,
formatStats,
colorize,
} from './utils';

Expand Down Expand Up @@ -41,7 +41,9 @@ export default class WebpackBarPlugin extends webpack.ProgressPlugin {

this._render = _.throttle(this.render, 25);

this.logUpdate = this.options.logUpdate || logUpdate;
this.logUpdate =
this.options.logUpdate ||
(this.options.stream === process.stderr ? logUpdate.stderr : logUpdate);

if (!this.state) {
sharedState[this.options.name] = {
Expand All @@ -59,7 +61,8 @@ export default class WebpackBarPlugin extends webpack.ProgressPlugin {
done() {
if (this.options.profile) {
const stats = this.state.profile.getStats();
printStats(stats);
const statsStr = formatStats(stats);
this.options.stream.write(`\n${statsStr}\n`);
}

if (typeof this.options.done === 'function') {
Expand Down
10 changes: 7 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ export const formatRequest = (request) => {
return format(`${loaders}${NEXT}${request.file}`);
};

export const printStats = (allStats) => {
export const formatStats = (allStats) => {
const lines = [];

Object.keys(allStats).forEach((category) => {
const stats = allStats[category];

process.stderr.write(`\nStats by ${chalk.bold(_.startCase(category))}\n`);
lines.push(`Stats by ${chalk.bold(_.startCase(category))}`);

let totalRequests = 0;
const totalTime = [0, 0];
Expand Down Expand Up @@ -121,6 +123,8 @@ export const printStats = (allStats) => {

data.push(['Total', totalRequests, prettyTime(totalTime), '', '']);

process.stderr.write(`\n${table(data)}\n`);
lines.push(table(data));
});

return lines.join('\n\n');
};

0 comments on commit 34733b7

Please sign in to comment.