oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
72.08k stars 2.58k forks source link

readline node not working with async iterator syntax #2535

Open babymum7 opened 1 year ago

babymum7 commented 1 year ago

What version of Bun is running?

0.5.8

What platform is your computer?

Darwin 22.4.0 x86_64 i386

What steps can reproduce the bug?

readline node not working with async iterator syntax while createReadStream dose

What is the expected behavior?

Should work just like with Node

What do you see instead?

1 | import fs from 'node:fs';
2 | import readline from 'node:readline';
3 |
4 | for await (const line of readline.createInterface({
                     ^
TypeError: undefined is not an object (evaluating 'line of readline.createInterface({
  input: fs.createReadStream("./2023-04-01.csv")
})')

Additional information

minimal snippet

import fs from 'node:fs';
import readline from 'node:readline';

for await (const line of readline.createInterface({
  input: fs.createReadStream('./2023-04-01.csv'),
})) {
  console.log(line);
}
ThatOneBro commented 1 year ago

I'm actually just about done fixing this, the problem was our node:events.on was out of spec and didn't return an async iterator, which readline's async iterator uses internally. Once I finish testing that, this issue should be resolved too

Related: #2187

eL1x00r commented 6 months ago

when fix

zavan commented 5 months ago

This works on bun 1.0.25:

import { createReadStream } from "node:fs";
import { createInterface } from "node:readline/promises";

const stream = createReadStream('file.csv');
const rl = createInterface({ input: stream });

for await (const line of rl) {
  console.log(line);
}

Edit: Nope. Only reads 3 lines.

Electroid commented 5 months ago

It now appears to only read the first line.

mvdkwast commented 5 months ago

It now appears to only read the first line.

Confirmed in 1.0.26