diff options
Diffstat (limited to 'ext')
-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 |
12 files changed, 24 insertions, 121 deletions
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"; |