terkelg / prompts

❯ Lightweight, beautiful and user-friendly interactive prompts
MIT License
8.86k stars 304 forks source link

Bun support #403

Closed olafur-palsson closed 10 months ago

olafur-palsson commented 1 year ago

Is your feature request related to a problem?

This is something odd I noticed. It looks like in general prompts works except when you run two question sequentially.

// index.js
const prompts = require('prompts')
// Works just fine
const response1 = await prompts({
  type: 'text',
  name: 'msg',
  message: 'Question'
})

// Not possible to use inputs anymore
const response2 = await prompts({
  type: 'text',
  name: 'msg',
  message: 'Question'
})

Describe the solution you'd like

It works when running with bun like when running with node.

Describe alternatives you've considered

Using node lol.

Additional context

None

ericklarsen commented 1 year ago

it happened on my side too.

sonyarianto commented 1 year ago

true true just run bun run example.js on this repo and on second question my WSL is hang :)

sonyarianto commented 1 year ago

refer to this https://github.com/oven-sh/bun/issues/4664

olafur-palsson commented 1 year ago

I took a look around and a lot of interactive cli stuff is having issues. https://github.com/oven-sh/bun/issues/4787 https://github.com/oven-sh/bun/issues/5267 https://github.com/oven-sh/bun/issues/5240 https://github.com/oven-sh/bun/issues/3255 https://github.com/oven-sh/bun/issues/2333

But here's one that says it's fixed in the upcoming bun release which was 1.0 at the time (@clack/prompts on npm) but I've been running it on Bun 1.0 and still have the same bug. https://github.com/natemoo-re/clack/issues/159

sonyarianto commented 1 year ago

@olafur-palsson Hi, for me Bun with @clack/prompts is no problem, but with terkelg/prompts has the issue CMIIW.

In @clack/prompts to test is easy, just clone that repo, and run bun --bun run examples/basic/index.ts it run smooth :)

olafur-palsson commented 1 year ago

@sonyarianto They have issue with these. There's some weird behavior when closing the readline interface in Bun I think.

Try running this one:

import * as p from '@clack/prompts';

await p.text({
  message: 'Where should we create your project?',
  placeholder: './lol',
})

await p.text({
  message: 'Where should we create your project?',
  placeholder: './lol',
})

I didn't read @clack/prompts but I know that terkelg/prompts creates readline interfaces and closes them for each question. Maybe @clack/prompts keeps it open longer?

sonyarianto commented 1 year ago

Hmmm with Bun 1.0.2 above script also still not working properly.

sonyarianto commented 1 year ago

@olafur-palsson butttt if you modify the code like this, inside the async then it will work smoothly.

index.js

import * as p from '@clack/prompts';

async function main() {
  const response1 = await p.text({
    message: 'Where should we create your project?',
    placeholder: './lol',
  });

  const response2 = await p.text({
    message: 'Where should we create your project?',
    placeholder: './lol',
  });
}

await main();

bun --bun run index.js

qhariN commented 10 months ago

This issue has already been addressed in the latest release of Bun, v1.0.18. You can find more details about the fix in the release notes: Bun v1.0.18 Release Notes.

michaelhays commented 10 months ago

Confirmed that this is no longer an issue with Bun v1.0.18, so this issue can probably be closed.

davidgomes commented 3 months ago

This can still happen on Bun, even after their v1.0.18 version.

Here's a repro/bug on Bun's issue tracker: https://github.com/oven-sh/bun/issues/9855#issuecomment-2224861121