Skip to content

Commit 2bf4c60

Browse files
committed
fix: patch console.log and console.error in utility.ts for Deno compatibility
1 parent 540efcb commit 2bf4c60

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

ddss/utility.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { format } from "node:util";
12
import type { Interface } from "node:readline";
23
import { stdout } from "node:process";
34

@@ -11,6 +12,8 @@ export function strRuleGetStrIdea(data: string): string | null {
1112

1213
export function patchStdout(rl: Interface) {
1314
const originalWrite = stdout.write;
15+
const originalLog = console.log;
16+
const originalError = console.error;
1417
let isReprompting = false;
1518

1619
// @ts-ignore
@@ -43,8 +46,17 @@ export function patchStdout(rl: Interface) {
4346
return originalWrite.call(stdout, chunk, encoding, callback);
4447
};
4548

49+
console.log = (...args: any[]) => {
50+
stdout.write(format(...args) + "\n");
51+
};
52+
console.error = (...args: any[]) => {
53+
stdout.write(format(...args) + "\n");
54+
};
55+
4656
return () => {
4757
// @ts-ignore
4858
stdout.write = originalWrite;
59+
console.log = originalLog;
60+
console.error = originalError;
4961
};
5062
}

0 commit comments

Comments
 (0)