Skip to content

Commit

Permalink
Workaround for #9041
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Mar 23, 2024
1 parent 940448d commit 240ea8a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/js/node/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -3388,9 +3388,21 @@ var require_readable = __commonJS({
};

Readable.fromWeb = function (readableStream, options) {
// We cache .stream() calls for file descriptors
// This won't create a new ReadableStream each time.
let bunStdinStream = Bun.stdin.stream();
if (readableStream === bunStdinStream) {
return bunStdinStream;
}

return webStreamsAdapters.newStreamReadableFromReadableStream(readableStream, options);
};
Readable.toWeb = function (streamReadable, options) {
// Workaround for https://github.com/oven-sh/bun/issues/9041
if (streamReadable === process.stdin) {
return Bun.stdin.stream();
}

return webStreamsAdapters.newReadableStreamFromStreamReadable(streamReadable, options);
};
Readable.wrap = function (src, options) {
Expand Down
26 changes: 26 additions & 0 deletions test/regression/issue/09041.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { test, expect } from "bun:test";
import { bunEnv, bunExe, tempDirWithFiles } from "harness";
import { join } from "path";
import { $ } from "bun";
import { cp, rm } from "fs/promises";
test("09041", async () => {
const out = tempDirWithFiles("09041", {
"09041-fixture.mjs": await Bun.file(join(import.meta.dir, "09041", "09041-fixture.mjs")).text(),
"09041-fixture.test.js": await Bun.file(join(import.meta.dir, "09041", "09041-fixture-test.txt")).text(),
"package.json": `{}`,
});

let { exited, stderr, stdout } = Bun.spawn({
cmd: [bunExe(), "test"],
cwd: out,
env: bunEnv,
stdio: ["ignore", "pipe", "inherit"],
});

expect(await exited).toBe(0);
const err = await new Response(stderr).text();
expect(err).toContain("1 pass");
expect(err).toContain("0 fail");

await rm(out, { force: true, recursive: true });
}, 10000);
18 changes: 18 additions & 0 deletions test/regression/issue/09041/09041-fixture-test.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions test/regression/issue/09041/09041-fixture.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 240ea8a

Please sign in to comment.