clessg/progress-bar-webpack-plugin

doesn't work in Webstorm run tool

urrri opened this issue · 8 comments

urrri commented

I'm not sure this problem is in the package, but it works fine in terminal window and show nothing in "Run" window of Webstorm (I even didn't receive final callback).

same to me

This is because the plugin is disabled if the output is not a TTY, like WebStorm's Run window.

Here's the upstream discussion in node-progress.

Another library with the same issue (supports-color) fixed this by adding a FORCE_COLOR option.

The same issue is seen when running an application with forever, which redirects the output to a non-TTY stream.

This workaround helps in that case:

  var stream = options.stream;

  if (!stream) {
    stream = process.stderr;

    if (!stream.isTTY) {
      var tty = require('tty').WriteStream.prototype;

      Object.keys(tty).forEach(function (key) {
        process.stderr[key] = tty[key];
      })

      process.stderr.columns = 80;
    }
  }

Unfortunately WebStorm's Run window doesn't support clearing the line, so keeps drawing new progress bars.

I made it work perfectly in Webstorm's run console (on Windows 10) by adding this TTY-mock before using the progress bar:

if (!process.stdout.isTTY) {
    process.stdout.isTTY = true;
    process.stdout.columns = 80;
    process.stdout.cursorTo = () => { process.stdout.write('\r') };
    process.stdout.clearLine = () => {};
}

And creating the ProgressBar with the option "stream: process.stdout"

The mocked cursorTo()-function enables overwriting the same line so that multiple lines are not rendered (at least on Windows, this must done before writing the actual line, so that's why process.stdout.write('\r') is put in cursorTo() and not in clearLine()))

+1