Skip to content

Commit

Permalink
Avoid triggering stdio streams creation (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
stroncium authored and sindresorhus committed Aug 21, 2019
1 parent a4140d7 commit 03ea72b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions index.js
@@ -1,5 +1,6 @@
'use strict';
const os = require('os');
const tty = require('tty');
const hasFlag = require('has-flag');

const {env} = process;
Expand Down Expand Up @@ -40,7 +41,7 @@ function translateLevel(level) {
};
}

function supportsColor(stream) {
function supportsColor(haveStream, streamIsTTY) {
if (forceColor === 0) {
return 0;
}
Expand All @@ -55,7 +56,7 @@ function supportsColor(stream) {
return 2;
}

if (stream && !stream.isTTY && forceColor === undefined) {
if (haveStream && !streamIsTTY && forceColor === undefined) {
return 0;
}

Expand Down Expand Up @@ -123,12 +124,12 @@ function supportsColor(stream) {
}

function getSupportLevel(stream) {
const level = supportsColor(stream);
const level = supportsColor(stream, stream && stream.isTTY);
return translateLevel(level);
}

module.exports = {
supportsColor: getSupportLevel,
stdout: getSupportLevel(process.stdout),
stderr: getSupportLevel(process.stderr)
stdout: translateLevel(supportsColor(true, tty.isatty(1))),
stderr: translateLevel(supportsColor(true, tty.isatty(2)))
};

0 comments on commit 03ea72b

Please sign in to comment.