Skip to content
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

Add flag to force Node colors #713

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -168,6 +168,7 @@ change the behavior of the debug logging:
| `DEBUG` | Enables/disables specific debugging namespaces. |
| `DEBUG_HIDE_DATE` | Hide date from debug output (non-TTY). |
| `DEBUG_COLORS`| Whether or not to use colors in the debug output. |
| `DEBUG_COLORS_NODE` | Assume runtime is Node, even if it looks like a browser (e.g. Electron). |
| `DEBUG_DEPTH` | Object inspection depth. |
| `DEBUG_SHOW_HIDDEN` | Shows hidden properties on inspected objects. |

Expand Down
7 changes: 2 additions & 5 deletions src/browser.js
Expand Up @@ -169,14 +169,11 @@ function formatArgs(args) {
}

/**
* Invokes `console.debug()` when available.
* No-op when `console.debug` is not a "function".
* If `console.debug` is not available, falls back
* to `console.log`.
* Invokes `console.log` if available or no-op
*
* @api public
*/
exports.log = console.debug || console.log || (() => {});
exports.log = console.log || (() => {});

/**
* Save `namespaces`.
Expand Down
5 changes: 4 additions & 1 deletion src/index.js
Expand Up @@ -3,7 +3,10 @@
* treat as a browser.
*/

if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) {
const isBrowserNode = process.type === 'renderer' || process.browser === true || process.__nwjs;
const isBrowser = typeof process === 'undefined';

if (isBrowser || (isBrowserNode && !process.env.DEBUG_COLORS_NODE)) {
module.exports = require('./browser.js');
} else {
module.exports = require('./node.js');
Expand Down
5 changes: 5 additions & 0 deletions src/node.js
Expand Up @@ -128,6 +128,11 @@ exports.inspectOpts = Object.keys(process.env).filter(key => {
return k.toUpperCase();
});

if (prop === 'colorsNode') {
obj.colors = true;
return obj;
}

// Coerce string value into JS value
let val = process.env[key];
if (/^(yes|on|true|enabled)$/i.test(val)) {
Expand Down