In worker threads, supports-color is unable to automatically detect color support.
const { Worker, isMainThread } = require('worker_threads')
const supportsColor = require('supports-color')
if (isMainThread) {
console.log('mainThread, supportsColor.stdout', supportsColor.stdout)
console.log('mainThread, supportsColor.stderr', supportsColor.stderr)
new Worker(__filename)
} else {
console.log('workerThread, supportsColor.stdout', supportsColor.stdout)
console.log('workerThread, supportsColor.stderr', supportsColor.stderr)
}
$ node ./main.js
mainThread, supportsColor.stdout { level: 2, hasBasic: true, has256: true, has16m: false }
mainThread, supportsColor.stderr { level: 2, hasBasic: true, has256: true, has16m: false }
workerThread, supportsColor.stdout false
workerThread, supportsColor.stderr false
It looks like the stream type in worker threads is WritableWorkerStdio which returns isTTY false so the check at:
|
if (stream && !stream.isTTY && forceColor === undefined) { |
fails. If I skip that check (with
stream.constructor.name === 'WritableWorkerStdio') then supportsColor returns correct information and color output does work. I'm not sure if that's the best fix or whether it even
should be fixed.
In worker threads, supports-color is unable to automatically detect color support.
$ node ./main.js mainThread, supportsColor.stdout { level: 2, hasBasic: true, has256: true, has16m: false } mainThread, supportsColor.stderr { level: 2, hasBasic: true, has256: true, has16m: false } workerThread, supportsColor.stdout false workerThread, supportsColor.stderr falseIt looks like the stream type in worker threads is
WritableWorkerStdiowhich returnsisTTYfalse so the check at:supports-color/index.js
Line 57 in 14a0e6f
stream.constructor.name === 'WritableWorkerStdio') then supportsColor returns correct information and color output does work. I'm not sure if that's the best fix or whether it even should be fixed.