diff options
author | Leo Kettmeir <crowlkats@toaxl.com> | 2023-04-30 11:11:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-30 09:11:37 +0000 |
commit | 59825a95b4d3952c955b8b43e174189999e35d15 (patch) | |
tree | b3ff4c24f5596cc70daac40b578805a61d565c2a | |
parent | bb1f5e4262940a966e6314f57a4267514911d262 (diff) |
refactor: remove ext/console/01_colors.js (#18927)
-rw-r--r-- | cli/js/40_testing.js | 2 | ||||
-rw-r--r-- | ext/console/01_colors.js | 108 | ||||
-rw-r--r-- | ext/console/01_console.js (renamed from ext/console/02_console.js) | 17 | ||||
-rw-r--r-- | ext/console/internal.d.ts | 2 | ||||
-rw-r--r-- | ext/console/lib.rs | 2 | ||||
-rw-r--r-- | ext/fetch/23_request.js | 2 | ||||
-rw-r--r-- | ext/fetch/23_response.js | 2 | ||||
-rw-r--r-- | ext/node/polyfills/internal/util/inspect.mjs | 2 | ||||
-rw-r--r-- | ext/web/01_dom_exception.js | 2 | ||||
-rw-r--r-- | ext/web/02_event.js | 2 | ||||
-rw-r--r-- | ext/web/06_streams.js | 2 | ||||
-rw-r--r-- | ext/web/09_file.js | 2 | ||||
-rw-r--r-- | ext/web/15_performance.js | 2 | ||||
-rw-r--r-- | runtime/fmt_errors.rs | 2 | ||||
-rw-r--r-- | runtime/js/90_deno_ns.js | 2 | ||||
-rw-r--r-- | runtime/js/98_global_scope.js | 2 | ||||
-rw-r--r-- | runtime/js/99_main.js | 11 |
17 files changed, 34 insertions, 130 deletions
diff --git a/cli/js/40_testing.js b/cli/js/40_testing.js index 555f5f1fe..8afcb74ee 100644 --- a/cli/js/40_testing.js +++ b/cli/js/40_testing.js @@ -3,7 +3,7 @@ const core = globalThis.Deno.core; const ops = core.ops; import { setExitHandler } from "ext:runtime/30_os.js"; -import { Console } from "ext:deno_console/02_console.js"; +import { Console } from "ext:deno_console/01_console.js"; import { serializePermissions } from "ext:runtime/10_permissions.js"; import { assert } from "ext:deno_web/00_infra.js"; const primordials = globalThis.__bootstrap.primordials; diff --git a/ext/console/01_colors.js b/ext/console/01_colors.js deleted file mode 100644 index a598db921..000000000 --- a/ext/console/01_colors.js +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. - -/// <reference path="../../core/internal.d.ts" /> - -const primordials = globalThis.__bootstrap.primordials; -const { - SafeRegExp, - StringPrototypeReplace, - ArrayPrototypeJoin, -} = primordials; - -let noColor = false; - -function setNoColor(value) { - noColor = value; -} - -function getNoColor() { - return noColor; -} - -function code(open, close) { - return { - open: `\x1b[${open}m`, - close: `\x1b[${close}m`, - regexp: new SafeRegExp(`\\x1b\\[${close}m`, "g"), - }; -} - -function run(str, code) { - return `${code.open}${ - StringPrototypeReplace(str, code.regexp, code.open) - }${code.close}`; -} - -function bold(str) { - return run(str, code(1, 22)); -} - -function italic(str) { - return run(str, code(3, 23)); -} - -function yellow(str) { - return run(str, code(33, 39)); -} - -function cyan(str) { - return run(str, code(36, 39)); -} - -function red(str) { - return run(str, code(31, 39)); -} - -function green(str) { - return run(str, code(32, 39)); -} - -function bgRed(str) { - return run(str, code(41, 49)); -} - -function white(str) { - return run(str, code(37, 39)); -} - -function gray(str) { - return run(str, code(90, 39)); -} - -function magenta(str) { - return run(str, code(35, 39)); -} - -// https://github.com/chalk/ansi-regex/blob/02fa893d619d3da85411acc8fd4e2eea0e95a9d9/index.js -const ANSI_PATTERN = new SafeRegExp( - ArrayPrototypeJoin([ - "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", - "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))", - ], "|"), - "g", -); - -function stripColor(string) { - return StringPrototypeReplace(string, ANSI_PATTERN, ""); -} - -function maybeColor(fn) { - return !noColor ? fn : (s) => s; -} - -export { - bgRed, - bold, - cyan, - getNoColor, - gray, - green, - italic, - magenta, - maybeColor, - red, - setNoColor, - stripColor, - white, - yellow, -}; diff --git a/ext/console/02_console.js b/ext/console/01_console.js index 51e827876..318cf9cb4 100644 --- a/ext/console/02_console.js +++ b/ext/console/01_console.js @@ -119,7 +119,16 @@ const { SafeMapIterator, ArrayBufferPrototype, } = primordials; -import * as colors_ from "ext:deno_console/01_colors.js"; + +let noColor = false; + +function setNoColor(value) { + noColor = value; +} + +function getNoColor() { + return noColor; +} // Don't use 'blue' not visible on cmd.exe const styles = { @@ -3031,7 +3040,7 @@ function inspectArgs(args, inspectOptions = {}) { if (ctx.maxArrayLength === null) ctx.maxArrayLength = Infinity; if (ctx.maxStringLength === null) ctx.maxStringLength = Infinity; - const noColor = colors_.getNoColor(); + const noColor = getNoColor(); const first = args[0]; let a = 0; let string = ""; @@ -3146,7 +3155,7 @@ const timerMap = new SafeMap(); const isConsoleInstance = Symbol("isConsoleInstance"); function getConsoleInspectOptions() { - const color = !colors_.getNoColor(); + const color = !getNoColor(); return { ...getDefaultInspectOptions(), colors: color, @@ -3597,9 +3606,11 @@ export { formatNumber, formatValue, getDefaultInspectOptions, + getNoColor, inspect, inspectArgs, quoteString, + setNoColor, styles, wrapConsole, }; diff --git a/ext/console/internal.d.ts b/ext/console/internal.d.ts index d344f3a77..1fbc89378 100644 --- a/ext/console/internal.d.ts +++ b/ext/console/internal.d.ts @@ -3,7 +3,7 @@ /// <reference no-default-lib="true" /> /// <reference lib="esnext" /> -declare module "ext:deno_console/02_console.js" { +declare module "ext:deno_console/01_console.js" { function createFilteredInspectProxy<TObject>(params: { object: TObject; keys: (keyof TObject)[]; diff --git a/ext/console/lib.rs b/ext/console/lib.rs index a45b856cd..a31470e08 100644 --- a/ext/console/lib.rs +++ b/ext/console/lib.rs @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. use std::path::PathBuf; -deno_core::extension!(deno_console, esm = ["01_colors.js", "02_console.js"],); +deno_core::extension!(deno_console, esm = ["01_console.js"],); pub fn get_declaration() -> PathBuf { PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("lib.deno_console.d.ts") diff --git a/ext/fetch/23_request.js b/ext/fetch/23_request.js index ae3edffd4..22c1f8354 100644 --- a/ext/fetch/23_request.js +++ b/ext/fetch/23_request.js @@ -10,7 +10,7 @@ /// <reference lib="esnext" /> import * as webidl from "ext:deno_webidl/00_webidl.js"; -import { createFilteredInspectProxy } from "ext:deno_console/02_console.js"; +import { createFilteredInspectProxy } from "ext:deno_console/01_console.js"; import { byteUpperCase, HTTP_TOKEN_CODE_POINT_RE, diff --git a/ext/fetch/23_response.js b/ext/fetch/23_response.js index ffbfe4936..86799252b 100644 --- a/ext/fetch/23_response.js +++ b/ext/fetch/23_response.js @@ -12,7 +12,7 @@ const core = globalThis.Deno.core; import * as webidl from "ext:deno_webidl/00_webidl.js"; -import { createFilteredInspectProxy } from "ext:deno_console/02_console.js"; +import { createFilteredInspectProxy } from "ext:deno_console/01_console.js"; import { byteLowerCase, HTTP_TAB_OR_SPACE, diff --git a/ext/node/polyfills/internal/util/inspect.mjs b/ext/node/polyfills/internal/util/inspect.mjs index cdaa3db81..671ab2acf 100644 --- a/ext/node/polyfills/internal/util/inspect.mjs +++ b/ext/node/polyfills/internal/util/inspect.mjs @@ -22,7 +22,7 @@ import { validateObject, validateString } from "ext:deno_node/internal/validators.mjs"; import { codes } from "ext:deno_node/internal/error_codes.ts"; -import { createStylizeWithColor, formatValue, formatNumber, formatBigInt, styles, colors } from "ext:deno_console/02_console.js"; +import { createStylizeWithColor, formatValue, formatNumber, formatBigInt, styles, colors } from "ext:deno_console/01_console.js"; diff --git a/ext/web/01_dom_exception.js b/ext/web/01_dom_exception.js index ae3dcfd2e..c465a06fd 100644 --- a/ext/web/01_dom_exception.js +++ b/ext/web/01_dom_exception.js @@ -21,7 +21,7 @@ const { SymbolFor, } = primordials; import * as webidl from "ext:deno_webidl/00_webidl.js"; -import { createFilteredInspectProxy } from "ext:deno_console/02_console.js"; +import { createFilteredInspectProxy } from "ext:deno_console/01_console.js"; const _name = Symbol("name"); const _message = Symbol("message"); diff --git a/ext/web/02_event.js b/ext/web/02_event.js index 34b3502a7..e45347420 100644 --- a/ext/web/02_event.js +++ b/ext/web/02_event.js @@ -9,7 +9,7 @@ const core = globalThis.Deno.core; const ops = core.ops; import * as webidl from "ext:deno_webidl/00_webidl.js"; import DOMException from "ext:deno_web/01_dom_exception.js"; -import { createFilteredInspectProxy } from "ext:deno_console/02_console.js"; +import { createFilteredInspectProxy } from "ext:deno_console/01_console.js"; const primordials = globalThis.__bootstrap.primordials; const { ArrayPrototypeFilter, diff --git a/ext/web/06_streams.js b/ext/web/06_streams.js index ac626a209..c8a7b9c47 100644 --- a/ext/web/06_streams.js +++ b/ext/web/06_streams.js @@ -78,7 +78,7 @@ const { WeakMapPrototypeHas, WeakMapPrototypeSet, } = primordials; -import { createFilteredInspectProxy } from "ext:deno_console/02_console.js"; +import { createFilteredInspectProxy } from "ext:deno_console/01_console.js"; import { assert, AssertionError } from "ext:deno_web/00_infra.js"; /** @template T */ diff --git a/ext/web/09_file.js b/ext/web/09_file.js index dccb20611..8f0072e05 100644 --- a/ext/web/09_file.js +++ b/ext/web/09_file.js @@ -48,7 +48,7 @@ const { TypeError, Uint8Array, } = primordials; -import { createFilteredInspectProxy } from "ext:deno_console/02_console.js"; +import { createFilteredInspectProxy } from "ext:deno_console/01_console.js"; // TODO(lucacasonato): this needs to not be hardcoded and instead depend on // host os. diff --git a/ext/web/15_performance.js b/ext/web/15_performance.js index 85990c954..d494a5328 100644 --- a/ext/web/15_performance.js +++ b/ext/web/15_performance.js @@ -16,7 +16,7 @@ const { } = primordials; import * as webidl from "ext:deno_webidl/00_webidl.js"; import { structuredClone } from "ext:deno_web/02_structured_clone.js"; -import { createFilteredInspectProxy } from "ext:deno_console/02_console.js"; +import { createFilteredInspectProxy } from "ext:deno_console/01_console.js"; import { EventTarget } from "ext:deno_web/02_event.js"; import { opNow } from "ext:deno_web/02_timers.js"; import DOMException from "ext:deno_web/01_dom_exception.js"; diff --git a/runtime/fmt_errors.rs b/runtime/fmt_errors.rs index 6852cbcd1..5dcb96ec7 100644 --- a/runtime/fmt_errors.rs +++ b/runtime/fmt_errors.rs @@ -12,7 +12,7 @@ use std::fmt::Write as _; /// Compares all properties of JsError, except for JsError::cause. /// This function is used to detect that 2 JsError objects in a JsError::cause /// chain are identical, ie. there is a recursive cause. -/// 02_console.js, which also detects recursive causes, can use JS object +/// 01_console.js, which also detects recursive causes, can use JS object /// comparisons to compare errors. We don't have access to JS object identity in /// format_js_error(). fn errors_are_equal_without_cause(a: &JsError, b: &JsError) -> bool { diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js index bb6ba3b08..3507a98a3 100644 --- a/runtime/js/90_deno_ns.js +++ b/runtime/js/90_deno_ns.js @@ -4,7 +4,7 @@ const core = globalThis.Deno.core; const ops = core.ops; import * as timers from "ext:deno_web/02_timers.js"; import * as httpClient from "ext:deno_fetch/22_http_client.js"; -import * as console from "ext:deno_console/02_console.js"; +import * as console from "ext:deno_console/01_console.js"; import * as ffi from "ext:deno_ffi/00_ffi.js"; import * as net from "ext:deno_net/01_net.js"; import * as tls from "ext:deno_net/02_tls.js"; diff --git a/runtime/js/98_global_scope.js b/runtime/js/98_global_scope.js index 911db65cb..1084f5c24 100644 --- a/runtime/js/98_global_scope.js +++ b/runtime/js/98_global_scope.js @@ -13,7 +13,7 @@ import * as event from "ext:deno_web/02_event.js"; import * as timers from "ext:deno_web/02_timers.js"; import * as base64 from "ext:deno_web/05_base64.js"; import * as encoding from "ext:deno_web/08_text_encoding.js"; -import * as console from "ext:deno_console/02_console.js"; +import * as console from "ext:deno_console/01_console.js"; import * as caches from "ext:deno_cache/01_cache.js"; import * as compression from "ext:deno_web/14_compression.js"; import * as worker from "ext:runtime/11_workers.js"; diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index b6dab121c..0ed692f3c 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -44,13 +44,14 @@ import * as location from "ext:deno_web/12_location.js"; import * as version from "ext:runtime/01_version.ts"; import * as os from "ext:runtime/30_os.js"; import * as timers from "ext:deno_web/02_timers.js"; -import * as colors from "ext:deno_console/01_colors.js"; import { getDefaultInspectOptions, + getNoColor, inspectArgs, quoteString, + setNoColor, wrapConsole, -} from "ext:deno_console/02_console.js"; +} from "ext:deno_console/01_console.js"; import * as performance from "ext:deno_web/15_performance.js"; import * as url from "ext:deno_url/00_url.js"; import * as fetch from "ext:deno_fetch/26_fetch.js"; @@ -220,11 +221,11 @@ function formatException(error) { } else if (typeof error == "string") { return `Uncaught ${ inspectArgs([quoteString(error, getDefaultInspectOptions())], { - colors: !colors.getNoColor(), + colors: !getNoColor(), }) }`; } else { - return `Uncaught ${inspectArgs([error], { colors: !colors.getNoColor() })}`; + return `Uncaught ${inspectArgs([error], { colors: !getNoColor() })}`; } } @@ -313,7 +314,7 @@ function runtimeStart( ); core.setBuildInfo(target); util.setLogDebug(debugFlag, source); - colors.setNoColor(noColor || !isTty); + setNoColor(noColor || !isTty); // deno-lint-ignore prefer-primordials Error.prepareStackTrace = core.prepareStackTrace; } |