diff --git a/lib/process.d.ts b/lib/process.d.ts new file mode 100644 index 0000000..b125989 --- /dev/null +++ b/lib/process.d.ts @@ -0,0 +1,11 @@ +declare module 'node:process' { + import { Socket } from 'node:net'; + + interface Process extends NodeJS.Process { + stdout: Socket | NodeJS.Process['stdout']; + } + + const process: Process; + + export = process; +} diff --git a/lib/remove.ts b/lib/remove.ts index c0f0e2b..5ab5d3a 100644 --- a/lib/remove.ts +++ b/lib/remove.ts @@ -6,12 +6,18 @@ import { Logger } from './util/Logger.js'; import { stdout } from 'node:process'; import { CliEditTracker } from './util/CliEditTracker.js'; -const createNodeJsLogger = (): Logger => ({ - write: stdout.write.bind(stdout), - clearLine: stdout.clearLine.bind(stdout), - cursorTo: stdout.cursorTo.bind(stdout), - isTTY: stdout.isTTY, -}); +const createNodeJsLogger = (): Logger => + 'isTTY' in stdout && stdout.isTTY + ? { + write: stdout.write.bind(stdout), + clearLine: stdout.clearLine.bind(stdout), + cursorTo: stdout.cursorTo.bind(stdout), + isTTY: true, + } + : { + write: stdout.write.bind(stdout), + isTTY: false, + }; export const remove = ({ configPath, diff --git a/lib/util/Logger.ts b/lib/util/Logger.ts index 8c20189..05fd559 100644 --- a/lib/util/Logger.ts +++ b/lib/util/Logger.ts @@ -1,6 +1,11 @@ -export interface Logger { - write(text: string): void; - clearLine(dir: -1 | 0 | 1): void; - cursorTo(x: number): void; - isTTY: boolean; -} +export type Logger = + | { + write(text: string): void; + clearLine(dir: -1 | 0 | 1): void; + cursorTo(x: number): void; + isTTY: true; + } + | { + write(text: string): void; + isTTY: false; + };