






















@@ -1,105 +1,2 @@
1-const warningFilterKey = Symbol.for("openclaw.warning-filter");
2-3-export type ProcessWarning = {
4-code?: string;
5-name?: string;
6-message?: string;
7-};
8-9-type ProcessWarningInstallState = {
10-installed: boolean;
11-};
12-13-function resolveWarningFilterState(): ProcessWarningInstallState {
14-const globalStore = globalThis as Record<PropertyKey, unknown>;
15-if (Object.prototype.hasOwnProperty.call(globalStore, warningFilterKey)) {
16-return globalStore[warningFilterKey] as ProcessWarningInstallState;
17-}
18-const state = { installed: false };
19-globalStore[warningFilterKey] = state;
20-return state;
21-}
22-23-export function shouldIgnoreWarning(warning: ProcessWarning): boolean {
24-if (warning.code === "DEP0040" && warning.message?.includes("punycode")) {
25-return true;
26-}
27-if (warning.code === "DEP0060" && warning.message?.includes("util._extend")) {
28-return true;
29-}
30-if (
31-warning.name === "ExperimentalWarning" &&
32-warning.message?.includes("SQLite is an experimental feature")
33-) {
34-return true;
35-}
36-return false;
37-}
38-39-function normalizeWarningArgs(args: unknown[]): ProcessWarning {
40-const warningArg = args[0];
41-const secondArg = args[1];
42-const thirdArg = args[2];
43-let name: string | undefined;
44-let code: string | undefined;
45-let message: string | undefined;
46-47-if (warningArg instanceof Error) {
48-name = warningArg.name;
49-message = warningArg.message;
50-code = (warningArg as Error & { code?: string }).code;
51-} else if (typeof warningArg === "string") {
52-message = warningArg;
53-}
54-55-if (secondArg && typeof secondArg === "object" && !Array.isArray(secondArg)) {
56-const options = secondArg as { type?: unknown; code?: unknown };
57-if (typeof options.type === "string") {
58-name = options.type;
59-}
60-if (typeof options.code === "string") {
61-code = options.code;
62-}
63-} else {
64-if (typeof secondArg === "string") {
65-name = secondArg;
66-}
67-if (typeof thirdArg === "string") {
68-code = thirdArg;
69-}
70-}
71-72-return { name, code, message };
73-}
74-75-export function installProcessWarningFilter(): void {
76-const state = resolveWarningFilterState();
77-if (state.installed) {
78-return;
79-}
80-81-const originalEmitWarning = process.emitWarning.bind(process);
82-const wrappedEmitWarning: typeof process.emitWarning = ((...args: unknown[]) => {
83-if (shouldIgnoreWarning(normalizeWarningArgs(args))) {
84-return;
85-}
86-if (
87-args[0] instanceof Error &&
88-args[1] &&
89-typeof args[1] === "object" &&
90-!Array.isArray(args[1])
91-) {
92-const warning = args[0];
93-const emitted = Object.assign(new Error(warning.message), {
94-name: warning.name,
95-code: (warning as Error & { code?: string }).code,
96-});
97-process.emit("warning", emitted);
98-return;
99-}
100-Reflect.apply(originalEmitWarning, process, args);
101-}) as typeof process.emitWarning;
102-103-process.emitWarning = wrappedEmitWarning;
104-state.installed = true;
105-}
1+export { installProcessWarningFilter, shouldIgnoreWarning } from "./openclaw-runtime-io.js";
2+export type { ProcessWarning } from "./openclaw-runtime-io.js";
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。