oven-sh / bun

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

Bun run process exits early for CLI scripts with more than 2 user input prompts #6052

Open asibilia opened 1 year ago

asibilia commented 1 year ago

What version of Bun is running?

1.0.3

What platform is your computer?

Darwin 22.6.0 arm64 arm

What steps can reproduce the bug?

// Run `npm start` to start the demo
import {
  intro,
  outro,
  confirm,
  select,
  spinner,
  isCancel,
  cancel,
  text,
} from '@clack/prompts';
import { setTimeout as sleep } from 'node:timers/promises';
import color from 'picocolors';

async function main() {
  console.log();
  intro(color.inverse(' create-my-app '));

  const name = await text({
    message: 'What is your name?',
    placeholder: 'Anonymous',
  });

  if (isCancel(name)) {
    cancel('Operation cancelled');
    return process.exit(0);
  }

  const shouldContinue = await confirm({
    message: 'Do you want to continue?',
  });

  if (isCancel(shouldContinue)) {
    cancel('Operation cancelled');
    return process.exit(0);
  }

  const projectType = await select({
    message: 'Pick a project type.',
    options: [
      { value: 'ts', label: 'TypeScript' },
      { value: 'js', label: 'JavaScript' },
      { value: 'coffee', label: 'CoffeeScript', hint: 'oh no' },
    ],
  });

  if (isCancel(projectType)) {
    cancel('Operation cancelled');
    return process.exit(0);
  }

  const s = spinner();
  s.start('Installing via npm');

  await sleep(3000);

  s.stop('Installed via npm');

  outro("You're all set!");

  await sleep(1000);
}

main().catch(console.error);

What is the expected behavior?

When running a file that prompts a user via the command line, Bun should allow the user to input more than one response consecutively.

What do you see instead?

Bun always exits after the first input.

Additional information

I've set up a simple example repo here: https://github.com/asibilia/cli-tool

colinhacks commented 1 year ago

I've replicated this

rampall commented 1 year ago

I've had the same issue!

asibilia commented 1 year ago

This comment seems to work for me, though obviously not ideal.

Adding await void(0); between prompts

await text({
    ...
});

await void(0);

await text({
    ...
});
qhariN commented 10 months ago

Looks like 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.