From bc666e42a89f2f6ab104e5f1c1298ec590a99ce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 17 Jan 2022 23:23:49 +0100 Subject: fix(ext/console): don't depend on globalThis present (#13387) --- ext/console/01_colors.js | 14 +++++++++++++- ext/console/02_console.js | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'ext') diff --git a/ext/console/01_colors.js b/ext/console/01_colors.js index 138eaa6d9..42551963c 100644 --- a/ext/console/01_colors.js +++ b/ext/console/01_colors.js @@ -11,6 +11,16 @@ ArrayPrototypeJoin, } = window.__bootstrap.primordials; + let noColor = false; + + function setNoColor(value) { + noColor = value; + } + + function getNoColor() { + return noColor; + } + function code(open, close) { return { open: `\x1b[${open}m`, @@ -79,7 +89,7 @@ } function maybeColor(fn) { - return !(globalThis.Deno?.noColor ?? false) ? fn : (s) => s; + return !noColor ? fn : (s) => s; } window.__bootstrap.colors = { @@ -95,5 +105,7 @@ magenta, stripColor, maybeColor, + setNoColor, + getNoColor, }; })(this); diff --git a/ext/console/02_console.js b/ext/console/02_console.js index 435c95187..0ebf5a4d9 100644 --- a/ext/console/02_console.js +++ b/ext/console/02_console.js @@ -1650,7 +1650,7 @@ } function inspectArgs(args, inspectOptions = {}) { - const noColor = globalThis.Deno?.noColor ?? true; + const noColor = colors.getNoColor(); const rInspectOptions = { ...DEFAULT_INSPECT_OPTIONS, ...inspectOptions }; const first = args[0]; let a = 0; @@ -1759,7 +1759,7 @@ function getConsoleInspectOptions() { return { ...DEFAULT_INSPECT_OPTIONS, - colors: !(globalThis.Deno?.noColor ?? false), + colors: !colors.getNoColor(), }; } -- cgit v1.2.3