diff options
author | Marvin Hagemeister <marvin@deno.com> | 2024-10-11 19:14:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-11 19:14:10 +0200 |
commit | 9117a9a43cba86d3112f86b10c5ea77baa2c6007 (patch) | |
tree | 21cce1fb7525ae8dc4863d7feb24d3e8688c7f60 | |
parent | 94b588ce6624ae2f2ed648c7b1a479a10513542f (diff) |
fix(node): make `process.stdout.isTTY` writable (#26130)
Fixes https://github.com/denoland/deno/issues/26123
-rw-r--r-- | ext/node/polyfills/_process/streams.mjs | 10 | ||||
-rw-r--r-- | tests/unit_node/process_test.ts | 10 |
2 files changed, 19 insertions, 1 deletions
diff --git a/ext/node/polyfills/_process/streams.mjs b/ext/node/polyfills/_process/streams.mjs index 19c1c9c18..7936e82aa 100644 --- a/ext/node/polyfills/_process/streams.mjs +++ b/ext/node/polyfills/_process/streams.mjs @@ -63,6 +63,10 @@ export function createWritableStdioStream(writer, name, warmup = false) { stream.destroySoon = stream.destroy; stream._isStdio = true; stream.once("close", () => writer?.close()); + + // We cannot call `writer?.isTerminal()` eagerly here + let getIsTTY = () => writer?.isTerminal(); + ObjectDefineProperties(stream, { columns: { __proto__: null, @@ -81,7 +85,11 @@ export function createWritableStdioStream(writer, name, warmup = false) { __proto__: null, enumerable: true, configurable: true, - get: () => writer?.isTerminal(), + // Allow users to overwrite it + get: () => getIsTTY(), + set: (value) => { + getIsTTY = () => value; + }, }, getWindowSize: { __proto__: null, diff --git a/tests/unit_node/process_test.ts b/tests/unit_node/process_test.ts index add9e1280..0e0f169d6 100644 --- a/tests/unit_node/process_test.ts +++ b/tests/unit_node/process_test.ts @@ -691,6 +691,16 @@ Deno.test({ assertStrictEquals(process.stdout.clearLine, undefined); assertStrictEquals(process.stdout.clearScreenDown, undefined); } + + // Allows overwriting `process.stdout.isTTY` + // https://github.com/denoland/deno/issues/26123 + const original = process.stdout.isTTY; + try { + process.stdout.isTTY = !isTTY; + assertEquals(process.stdout.isTTY, !isTTY); + } finally { + process.stdout.isTTY = original; + } }, }); |