Skip to content

Commit 0eb4487

Browse files
shawwndevongovett
authored andcommitted
Switch emojis to log-symbols for terminal compatibility (#363)
* Don't show emoji on windows. * Use log-symbols * Emoji with fallback for windows
1 parent ec89fab commit 0eb4487

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

src/Bundler.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const Logger = require('./Logger');
1313
const PackagerRegistry = require('./packagers');
1414
const localRequire = require('./utils/localRequire');
1515
const config = require('./utils/config');
16+
const emoji = require('./utils/emoji');
1617

1718
/**
1819
* The Bundler is the main entry point. It resolves and loads assets,
@@ -122,7 +123,7 @@ class Bundler extends EventEmitter {
122123
this.errored = false;
123124

124125
this.logger.clear();
125-
this.logger.status('⏳', 'Building...');
126+
this.logger.status(emoji.progress, 'Building...');
126127

127128
try {
128129
// Start worker farm, watcher, etc. if needed
@@ -144,7 +145,7 @@ class Bundler extends EventEmitter {
144145
buildTime < 1000
145146
? `${buildTime}ms`
146147
: `${(buildTime / 1000).toFixed(2)}s`;
147-
this.logger.status('✨', `Built in ${time}.`, 'green');
148+
this.logger.status(emoji.success, `Built in ${time}.`, 'green');
148149

149150
return bundle;
150151
} catch (err) {
@@ -304,7 +305,7 @@ class Bundler extends EventEmitter {
304305
}
305306

306307
if (!this.errored) {
307-
this.logger.status('⏳', `Building ${asset.basename}...`);
308+
this.logger.status(emoji.progress, `Building ${asset.basename}...`);
308309
}
309310

310311
// Mark the asset processed so we don't load it twice
@@ -461,7 +462,7 @@ class Bundler extends EventEmitter {
461462
}
462463

463464
this.logger.clear();
464-
this.logger.status('⏳', `Building ${asset.basename}...`);
465+
this.logger.status(emoji.progress, `Building ${asset.basename}...`);
465466

466467
// Add the asset to the rebuild queue, and reset the timeout.
467468
this.buildQueue.add(asset);

src/Logger.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const chalk = require('chalk');
22
const readline = require('readline');
33
const prettyError = require('./utils/prettyError');
4+
const emoji = require('./utils/emoji');
45

56
class Logger {
67
constructor(options) {
@@ -51,7 +52,7 @@ class Logger {
5152

5253
let {message, stack} = prettyError(err, {color: this.color});
5354

54-
this.status('🚨', message, 'red');
55+
this.status(emoji.error, message, 'red');
5556
if (stack) {
5657
this.write(stack);
5758
}

src/utils/emoji.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const supportsEmoji = process.platform !== 'win32' || process.env.VSCODE_PID;
2+
3+
// Fallback symbols for Windows from https://en.wikipedia.org/wiki/Code_page_437
4+
exports.progress = supportsEmoji ? '⏳' : '∞';
5+
exports.success = supportsEmoji ? '✨' : '√';
6+
exports.error = supportsEmoji ? '🚨' : '×';

0 commit comments

Comments
 (0)