mirror of
https://github.com/denoland/deno
synced 2024-08-25 02:57:22 +00:00
refactor: remove ext/console/01_colors.js (#18927)
This commit is contained in:
parent
bb1f5e4262
commit
59825a95b4
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
};
|
|
@ -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,
|
||||
};
|
2
ext/console/internal.d.ts
vendored
2
ext/console/internal.d.ts
vendored
|
@ -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)[];
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue