mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 04:39:10 +00:00

Some checks are pending
ci / bench release linux-x86_64 (push) Blocked by required conditions
ci / lint debug linux-x86_64 (push) Blocked by required conditions
ci / test release macos-x86_64 (push) Blocked by required conditions
ci / test debug windows-x86_64 (push) Blocked by required conditions
ci / test release windows-x86_64 (push) Blocked by required conditions
ci / pre-build (push) Waiting to run
ci / test debug linux-aarch64 (push) Blocked by required conditions
ci / test release linux-aarch64 (push) Blocked by required conditions
ci / test debug macos-aarch64 (push) Blocked by required conditions
ci / test release macos-aarch64 (push) Blocked by required conditions
ci / lint debug macos-x86_64 (push) Blocked by required conditions
ci / lint debug windows-x86_64 (push) Blocked by required conditions
ci / test debug linux-x86_64 (push) Blocked by required conditions
ci / test release linux-x86_64 (push) Blocked by required conditions
ci / test debug macos-x86_64 (push) Blocked by required conditions
ci / build wasm32 (push) Blocked by required conditions
ci / publish canary (push) Blocked by required conditions
52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
// deno-lint-ignore-file no-process-global
|
|
import { primordials } from "ext:core/mod.js";
|
|
import { getOptionValue } from "ext:deno_node/internal/options.ts";
|
|
|
|
const {
|
|
ErrorPrototype,
|
|
ErrorPrototypeToString,
|
|
ObjectPrototypeIsPrototypeOf,
|
|
SafeSet,
|
|
} = primordials;
|
|
|
|
let disableWarningSet;
|
|
|
|
export function onWarning(
|
|
warning: Error & { code?: string; name?: string; detail?: string },
|
|
) {
|
|
if (!disableWarningSet) {
|
|
disableWarningSet = new SafeSet();
|
|
const disableWarningValues = getOptionValue("--disable-warning");
|
|
for (let i = 0; i < disableWarningValues?.length; i++) {
|
|
disableWarningSet.add(disableWarningValues[i]);
|
|
}
|
|
}
|
|
if (
|
|
(warning?.code && disableWarningSet.has(warning.code)) ||
|
|
(warning?.name && disableWarningSet.has(warning.name))
|
|
) return;
|
|
|
|
if (!ObjectPrototypeIsPrototypeOf(ErrorPrototype, warning)) return;
|
|
|
|
const isDeprecation = warning.name === "DeprecationWarning";
|
|
if (isDeprecation && process.noDeprecation) return;
|
|
const trace = process.traceProcessWarnings ||
|
|
(isDeprecation && process.traceDeprecation);
|
|
let msg = `(${process.release.name}:${process.pid}) `;
|
|
if (warning.code) {
|
|
msg += `[${warning.code}] `;
|
|
}
|
|
if (trace && warning.stack) {
|
|
msg += `${warning.stack}`;
|
|
} else {
|
|
msg += typeof warning.toString === "function"
|
|
// deno-lint-ignore prefer-primordials
|
|
? `${warning.toString()}`
|
|
: ErrorPrototypeToString(warning);
|
|
}
|
|
if (typeof warning.detail === "string") {
|
|
msg += `\n${warning.detail}`;
|
|
}
|
|
process.stderr.write(msg + "\n");
|
|
}
|