mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
feat: Add deprecation warning for Deno.customInspect
(#22027)
This change sets the removal version of `Deno.customInspect` for Deno v2. Towards #22021 --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
parent
ee0cfd3fd5
commit
5aa25f08be
3 changed files with 42 additions and 17 deletions
4
cli/tsc/dts/lib.deno.ns.d.ts
vendored
4
cli/tsc/dts/lib.deno.ns.d.ts
vendored
|
@ -5034,8 +5034,8 @@ declare namespace Deno {
|
||||||
* called when `Deno.inspect()` is called, or when the object is logged to
|
* called when `Deno.inspect()` is called, or when the object is logged to
|
||||||
* the console.
|
* the console.
|
||||||
*
|
*
|
||||||
* @deprecated This symbol is deprecated since 1.9. Use
|
* @deprecated Use `Symbol.for("Deno.customInspect")` instead. This symbol
|
||||||
* `Symbol.for("Deno.customInspect")` instead.
|
* will be removed in Deno 2.0.
|
||||||
*
|
*
|
||||||
* @category Console and Debugging
|
* @category Console and Debugging
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -83,9 +83,6 @@ const denoNs = {
|
||||||
futime: fs.futime,
|
futime: fs.futime,
|
||||||
futimeSync: fs.futimeSync,
|
futimeSync: fs.futimeSync,
|
||||||
errors: errors.errors,
|
errors: errors.errors,
|
||||||
// TODO(kt3k): Remove this export at v2
|
|
||||||
// See https://github.com/denoland/deno/issues/9294
|
|
||||||
customInspect: console.customInspect,
|
|
||||||
inspect: console.inspect,
|
inspect: console.inspect,
|
||||||
env: os.env,
|
env: os.env,
|
||||||
exit: os.exit,
|
exit: os.exit,
|
||||||
|
|
|
@ -43,6 +43,7 @@ import * as version from "ext:runtime/01_version.ts";
|
||||||
import * as os from "ext:runtime/30_os.js";
|
import * as os from "ext:runtime/30_os.js";
|
||||||
import * as timers from "ext:deno_web/02_timers.js";
|
import * as timers from "ext:deno_web/02_timers.js";
|
||||||
import {
|
import {
|
||||||
|
customInspect,
|
||||||
getDefaultInspectOptions,
|
getDefaultInspectOptions,
|
||||||
getNoColor,
|
getNoColor,
|
||||||
inspectArgs,
|
inspectArgs,
|
||||||
|
@ -111,12 +112,13 @@ function warnOnDeprecatedApi(apiName, stack, suggestion) {
|
||||||
// to make it more useful.
|
// to make it more useful.
|
||||||
const stackLines = StringPrototypeSplit(stack, "\n");
|
const stackLines = StringPrototypeSplit(stack, "\n");
|
||||||
ArrayPrototypeShift(stackLines);
|
ArrayPrototypeShift(stackLines);
|
||||||
while (true) {
|
while (stackLines.length > 0) {
|
||||||
// Filter out internal frames at the top of the stack - they are not useful
|
// Filter out internal frames at the top of the stack - they are not useful
|
||||||
// to the user.
|
// to the user.
|
||||||
if (
|
if (
|
||||||
StringPrototypeIncludes(stackLines[0], "(ext:") ||
|
StringPrototypeIncludes(stackLines[0], "(ext:") ||
|
||||||
StringPrototypeIncludes(stackLines[0], "(node:")
|
StringPrototypeIncludes(stackLines[0], "(node:") ||
|
||||||
|
StringPrototypeIncludes(stackLines[0], "<anonymous>")
|
||||||
) {
|
) {
|
||||||
ArrayPrototypeShift(stackLines);
|
ArrayPrototypeShift(stackLines);
|
||||||
} else {
|
} else {
|
||||||
|
@ -127,6 +129,7 @@ function warnOnDeprecatedApi(apiName, stack, suggestion) {
|
||||||
// event loop tick or promise handler calling a user function - again not
|
// event loop tick or promise handler calling a user function - again not
|
||||||
// useful to the user.
|
// useful to the user.
|
||||||
if (
|
if (
|
||||||
|
stackLines.length > 0 &&
|
||||||
StringPrototypeIncludes(stackLines[stackLines.length - 1], "(ext:core/")
|
StringPrototypeIncludes(stackLines[stackLines.length - 1], "(ext:core/")
|
||||||
) {
|
) {
|
||||||
ArrayPrototypePop(stackLines);
|
ArrayPrototypePop(stackLines);
|
||||||
|
@ -168,16 +171,17 @@ function warnOnDeprecatedApi(apiName, stack, suggestion) {
|
||||||
"color: yellow;",
|
"color: yellow;",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (stackLines.length > 0) {
|
||||||
console.error("%c\u2502", "color: yellow;");
|
console.error("%c\u2502", "color: yellow;");
|
||||||
console.error("%c\u2514 Stack trace:", "color: yellow;");
|
console.error("%c\u2514 Stack trace:", "color: yellow;");
|
||||||
for (let i = 0; i < stackLines.length; i++) {
|
for (let i = 0; i < stackLines.length; i++) {
|
||||||
console.error(
|
console.error(
|
||||||
`%c ${i == stackLines.length - 1 ? "\u2514" : "\u251c"}\u2500 ${
|
`%c ${i == stackLines.length - 1 ? "\u2514" : "\u251c"}\u2500 ${
|
||||||
StringPrototypeTrim(stackLines[i])
|
StringPrototypeTrim(stackLines[i])
|
||||||
}`,
|
}`,
|
||||||
"color: yellow;",
|
"color: yellow;",
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
console.error();
|
console.error();
|
||||||
}
|
}
|
||||||
|
@ -626,6 +630,18 @@ function bootstrapMainRuntime(runtimeOptions) {
|
||||||
noColor: util.getterOnly(() => ops.op_bootstrap_no_color()),
|
noColor: util.getterOnly(() => ops.op_bootstrap_no_color()),
|
||||||
args: util.getterOnly(opArgs),
|
args: util.getterOnly(opArgs),
|
||||||
mainModule: util.getterOnly(opMainModule),
|
mainModule: util.getterOnly(opMainModule),
|
||||||
|
// TODO(kt3k): Remove this export at v2
|
||||||
|
// See https://github.com/denoland/deno/issues/9294
|
||||||
|
customInspect: {
|
||||||
|
get() {
|
||||||
|
warnOnDeprecatedApi(
|
||||||
|
"Deno.customInspect",
|
||||||
|
new Error().stack,
|
||||||
|
'Use `Symbol.for("Deno.customInspect")` instead.',
|
||||||
|
);
|
||||||
|
return customInspect;
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO(bartlomieju): deprecate --unstable
|
// TODO(bartlomieju): deprecate --unstable
|
||||||
|
@ -769,6 +785,18 @@ function bootstrapWorkerRuntime(
|
||||||
pid: util.getterOnly(opPid),
|
pid: util.getterOnly(opPid),
|
||||||
noColor: util.getterOnly(() => ops.op_bootstrap_no_color()),
|
noColor: util.getterOnly(() => ops.op_bootstrap_no_color()),
|
||||||
args: util.getterOnly(opArgs),
|
args: util.getterOnly(opArgs),
|
||||||
|
// TODO(kt3k): Remove this export at v2
|
||||||
|
// See https://github.com/denoland/deno/issues/9294
|
||||||
|
customInspect: {
|
||||||
|
get() {
|
||||||
|
warnOnDeprecatedApi(
|
||||||
|
"Deno.customInspect",
|
||||||
|
new Error().stack,
|
||||||
|
'Use `Symbol.for("Deno.customInspect")` instead.',
|
||||||
|
);
|
||||||
|
return customInspect;
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
// Setup `Deno` global - we're actually overriding already
|
// Setup `Deno` global - we're actually overriding already
|
||||||
// existing global `Deno` with `Deno` namespace from "./deno.ts".
|
// existing global `Deno` with `Deno` namespace from "./deno.ts".
|
||||||
|
|
Loading…
Add table
Reference in a new issue