rsms / estrella

Lightweight and versatile build tool based on the esbuild compiler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't run scripts with prompts

opened this issue · comments

I have the following build script:

build.mjs

import estrella from 'estrella'

estrella.build({
  entry: 'example/src/cli.ts',
  bundle: true,
  platform: 'node',
  format: 'esm',
  splitting: true,
  outdir: 'lib/example-build',
  watch: true,
  run: 'node lib/example-build/cli'
})

example/src/cli.ts

import inquirer from 'inquirer'

const main = async () => {
  const { message } = await import('./message')
  message()
  inquirer
    .prompt([
      {
        type: 'input',
        name: 'username',
        default: 'World'
      }
    ])
    .then(async answers => {
      console.log(`Hello ${answers.username}!`)
    })
}

main()

example/src/message.ts

export const message = () => console.log('Hey there! What`s your name?')

When i run build.mjs, the build works fine, but the output script doesn't work properly due to it's inquirer prompt, looks like estrella doesn't wait for the prompt to be answered before exiting

Am i missing something that is on the docs, or maybe doing something that i'm not supposed to?

Thanks!

Short version: It is working as intended.

Reading from and controlling stdin is not supported with the run functionality in Estrella. You can implement it yourself though in your build script by using the Nodejs child_process module to run your script. That allows you to emulate user input (or even redirect stdin of your build script to your subprocess.)

I'm going to close this issue since it's not a bug. If you have an idea for a feature request, please either add to this issue and we can rename and reopen it, or start a new issue. Thanks!