Skip to content

Refactor Inquirer to new package structure #5510

@martinlingstuyl

Description

@martinlingstuyl

Inquirer has been completely rewritten in recent times. What we have been installing is the old version, which is still maintained.

This is what the maintainer said about it:

Inquirer recently underwent a rewrite from the ground up to reduce the package size and improve performance. The previous version of the package is still maintained (though not actively developed), and offered hundreds of community contributed prompts that might not have been migrated to the latest API. If this is what you're looking for, the previous package is over here.

Source

I've been refactoring it and it turned out to be quite some work, which also led to a couple of questions, because some features have been dropped in the new packages.

This issue is for discussing the implementation.

Implementation

do check out my associated PR #5511 which has exactly what I suggest below here.

Packages
We swap the packages inquirer and @types/inquirer with @inquirer/input, @inquirer/confirm and @inquirer/select.

Prompt util
We create a prompt util in utils/prompt.ts to wrap interactions with inquirer, because inquirer is ESM and cannot be stubbed. We create three separate prompt functions in there: prompt.forConfirmation, prompt.forInput and prompt.forSelection. These functions have a single parameter for passing prompt configuration. (typed the same as what inquirer expects)

We import the correct inquire package (@inquirer/input, @inquirer/confirm, @inquirer/select) when it is needed and pass the prompt config parameter into the inquire prompt call.

Cli runtime
We create two static prompt functions in the CLI runtime class, which can be used to toggle the spinner and run the prompts. Cli.promptForSelection and Cli.promptForConfirmation, just like currently with Cli.prompt. Cli.promptForInput is currently not necessary as there is no occasion in the code base where this would be used.

...and of course: replace all instances of where inquirer is used with the new prompt util and all instances where Cli.prompt was used with the new static functions.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions