1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-27 17:49:08 -05:00

fix(node): don't close stdio streams (#19256)

Closes https://github.com/denoland/deno/issues/19255

---------

Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
This commit is contained in:
Bartek Iwańczuk 2023-06-02 07:36:51 +02:00
parent fb0068bc43
commit 544f48c23c
No known key found for this signature in database
GPG key ID: 0C6BCDDC3B3AD750
2 changed files with 19 additions and 0 deletions

View file

@ -2,6 +2,8 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import process, { argv, env } from "node:process";
import { Readable } from "node:stream";
import { once } from "node:events";
import {
assert,
assertEquals,
@ -746,3 +748,19 @@ Deno.test({
assertEquals(stripColor(decoder.decode(stdout).trim()), "really exited");
},
});
Deno.test({
name: "process.stdout isn't closed when source stream ended",
async fn() {
const source = Readable.from(["foo", "bar"]);
source.pipe(process.stdout);
await once(source, "end");
// Wait a bit to ensure that streaming is completely finished.
await delay(10);
// This checks if the rid 1 is still valid.
assert(typeof process.stdout.isTTY === "boolean");
},
});

View file

@ -16,6 +16,7 @@ import * as io from "ext:deno_io/12_io.js";
// https://github.com/nodejs/node/blob/00738314828074243c9a52a228ab4c68b04259ef/lib/internal/bootstrap/switches/is_main_thread.js#L41
export function createWritableStdioStream(writer, name) {
const stream = new Writable({
emitClose: false,
write(buf, enc, cb) {
if (!writer) {
this.destroy(