Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(internal): Use Bun.stdin when using Bun to prevent process hanging #760

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions internal/runtime/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@
* @internal
* @param data Uint8Array to store the data.
*/
export function read(data: Uint8Array): Promise<number | null> {
export async function read(data: Uint8Array): Promise<number | null> {
// deno-lint-ignore no-explicit-any
const { Deno, process } = globalThis as any;
const { Deno, Bun, process } = globalThis as any;

if (Deno) {
return Deno.stdin.read(data);
return await Deno.stdin.read(data);
} else if (Bun) {
const reader = Bun.stdin.stream().getReader();
const { value: buffer } = await reader.read();
await reader.cancel();
for (let i = 0; i < buffer.length; i++) {
data[i] = buffer[i];
}
return buffer.length;
} else if (process) {
return new Promise((resolve, reject) => {
return await new Promise((resolve, reject) => {
process.stdin.once("readable", () => {
try {
const buffer = process.stdin.read();
Expand Down