-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
escape codes and emojis when redirecting stderr to file #1201
Comments
Ha, whoops – didn't anticipate that scenario. Is this just a case of doing something like this? const stderr = process.stderr.isTTY ?
console.error.bind( console ) :
str => console.error( stripControlCodesSomehow( str ) ); If so, any idea what |
I think it's better to not emit these codes rather than strip them after the fact. Only a single emoji was introduced as far as I can tell: Line 157 in 11a2830
rather than strip it, that need not be emitted if stderr I never used |
Although I think a passthrough chalk wrapper is the correct way to go, this regexp purports to remove terminal escape codes: |
This patch fixes the redirected stderr issue. However, it uses diff --git a/bin/src/handleError.js b/bin/src/handleError.js
index aff6cea..0d5dd10 100644
--- a/bin/src/handleError.js
+++ b/bin/src/handleError.js
@@ -1,4 +1,6 @@
-import * as chalk from 'chalk';
+const chalk = require( "chalk" );
+
+if ( !process.stderr.isTTY ) chalk.enabled = false;
function stderr ( msg ) {
console.error( msg ); // eslint-disable-line no-console
diff --git a/bin/src/runRollup.js b/bin/src/runRollup.js
index f511de1..549157c 100644
--- a/bin/src/runRollup.js
+++ b/bin/src/runRollup.js
@@ -1,7 +1,7 @@
import { realpathSync } from 'fs';
import * as rollup from 'rollup';
import relative from 'require-relative';
-import * as chalk from 'chalk';
+const chalk = require( "chalk" );
import handleError from './handleError';
import relativeId from '../../src/utils/relativeId.js';
import SOURCEMAPPING_URL from './sourceMappingUrl.js';
@@ -154,7 +154,8 @@ function execute ( options, command ) {
if ( seen.has( str ) ) return;
seen.add( str );
- stderr( `⚠️ ${chalk.bold( warning.message )}` );
+ const warnSymbol = process.stderr.isTTY ? `⚠️ ` : `Warning: `;
+ stderr( `${warnSymbol}${chalk.bold( warning.message )}` );
if ( warning.url ) {
stderr( chalk.cyan( warning.url ) ); Amusing side note: I thought there was an escape code issue with emitting the dash in the warning (bytes 0xe2 0x80 0x93) until I learned that some rollup warnings use the Unicode Character 'EN DASH' (U+2013) instead of the typical 'HYPHEN-MINUS' (U+002D). Was not expecting that. |
Thanks, have turned into a PR (#1206). The import chalk from 'chalk'; ...instead of... import * as chalk from 'chalk'; ...the end result is the same, except that Rollup doesn't think you're reassigning stuff illegally.
Ha, that's what happens when you work in publishing I suppose — you obsess over the correct punctuation. Though I thought I'd been typing an EM DASH all these years, not an EN DASH (which isn't the correct mark). Oops! Will have to retrain my fingers. |
Thanks. So |
apply kzc patch to prevent escape codes and emojis appearing in non-TTY stderr
@kzc Try this:
|
@braytak It's been a while since I looked at this but the problem was not only a color issue. I didn't want emojis in the output (interfering with analysis) if it was not a TTY, hence the need for an explicit check. I don't know the state of Rollup output now. It's probably changed and they may have reintroduced emojis unconditionally. |
@kzc I'm interested to learn more about your environment, given that utf-8 support is pretty widespread. Could you share some more with us? |
@shellscape I am an old school programmer and loathe emojis. They interfere with analysis. There ought to be a way to disable them. You were looking for input in #2393, so I brought this up. |
Just to follow up, an option to disable emojis is not uncommon in other projects: |
Ah, I see. In that case, you should be able to use bash to accomplish that and still pipe to your desired destination: sed 's/[^[:alnum:][:punct:][:space:]]//g' input You might also be able wrap https://www.npmjs.com/package/emoji-strip in a CLI. I'm not sure that asking a library or app to filter certain unicode characters is reasonable solely based on personal preference, especially when a number of workarounds exist. And I'd question yarn's decision to add that option if I had any skin in the game. Emoji were added in the Unicode Standard in version 6.0 that was released in 2010. I'd bet you're going to be progressively fighting an uphill battle as their use becomes more widespread. I'm just one maintainer though, and others may have different opinions. |
Would it be possible to automatically disable
chalk
escape codes and emojis if stderris ais not a tty? (correction)rollup version 0.39.0
The text was updated successfully, but these errors were encountered: