-
Notifications
You must be signed in to change notification settings - Fork 70
[serverless] Migrate to @inquirer/prompts and remove inquirer-checkbox-plus-prompt
#2255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8b984e7
Migrate prompts to modern Inquirer and drop checkbox-plus
Drarig29 fe92e41
Ignore dynamic tooling dependencies in Knip
Drarig29 c331ab6
Add searchable Lambda checkbox prompt with Inquirer core
Drarig29 60a6ea6
Fix CI lint and license metadata for inquirer core
Drarig29 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| type PromptValidation<Value> = (value: Value) => boolean | string | Promise<boolean | string> | ||
|
|
||
| type Choice<Value> = | ||
| | Value | ||
| | { | ||
| checked?: boolean | ||
| description?: string | ||
| disabled?: boolean | string | ||
| name: string | ||
| short?: string | ||
| value: Value | ||
| } | ||
|
|
||
| export type CheckboxConfig<Value = string> = { | ||
| choices: readonly Choice<Value>[] | ||
| default?: readonly Value[] | ||
| message: string | ||
| pageSize?: number | ||
| validate?: PromptValidation<readonly Value[]> | ||
| } | ||
|
|
||
| export type ConfirmConfig = { | ||
| default?: boolean | ||
| message: string | ||
| } | ||
|
|
||
| export type InputConfig = { | ||
| default?: string | ||
| message: string | ||
| validate?: PromptValidation<string> | ||
| } | ||
|
|
||
| export type PasswordConfig = { | ||
| default?: string | ||
| mask?: boolean | string | ||
| message: string | ||
| validate?: PromptValidation<string> | ||
| } | ||
|
|
||
| export type SelectConfig<Value = string> = { | ||
| choices: readonly Choice<Value>[] | ||
| default?: Value | ||
| message: string | ||
| } | ||
|
|
||
| export type InquirerPrompts = { | ||
| checkbox: <Value = string>(config: CheckboxConfig<Value>) => Promise<Value[]> | ||
| confirm: (config: ConfirmConfig) => Promise<boolean> | ||
| input: (config: InputConfig) => Promise<string> | ||
| password: (config: PasswordConfig) => Promise<string> | ||
| select: <Value = string>(config: SelectConfig<Value>) => Promise<Value> | ||
| } | ||
|
|
||
| type InquirerPromptStatus = 'idle' | 'loading' | 'done' | ||
|
|
||
| type KeypressEvent = { | ||
| ctrl: boolean | ||
| name: string | ||
| shift: boolean | ||
| } | ||
|
|
||
| type Readline = { | ||
| clearLine: (dir: number) => void | ||
| line: string | ||
| write: (input: string) => void | ||
| } | ||
|
|
||
| type InquirerTheme = { | ||
| style: { | ||
| answer: (text: string) => string | ||
| error: (text: string) => string | ||
| highlight: (text: string) => string | ||
| message: (text: string, status: InquirerPromptStatus) => string | ||
| } | ||
| } | ||
|
|
||
| type PaginationConfig<Item> = { | ||
| active: number | ||
| items: readonly Item[] | ||
| loop?: boolean | ||
| pageSize: number | ||
| renderItem: (options: {index: number; isActive: boolean; item: Item}) => string | ||
| } | ||
|
|
||
| type PromptView<Value, Config> = (config: Config, done: (value: Value) => void) => string | [string, string | undefined] | ||
|
|
||
| type InquirerCore = { | ||
| createPrompt: <Value, Config>(view: PromptView<Value, Config>) => (config: Config) => Promise<Value> | ||
| isDownKey: (key: KeypressEvent) => boolean | ||
| isEnterKey: (key: KeypressEvent) => boolean | ||
| isSpaceKey: (key: KeypressEvent) => boolean | ||
| isUpKey: (key: KeypressEvent) => boolean | ||
| makeTheme: <Theme>(defaultTheme: Theme, customTheme?: unknown) => Theme & InquirerTheme | ||
| useEffect: (effect: (readline: Readline) => void | (() => void), dependencies?: readonly unknown[]) => void | ||
| useKeypress: (handler: (key: KeypressEvent, readline: Readline) => void | Promise<void>) => void | ||
| useMemo: <Value>(value: () => Value, dependencies: readonly unknown[]) => Value | ||
| usePagination: <Item>(config: PaginationConfig<Item>) => string | ||
| usePrefix: (options: {status: InquirerPromptStatus; theme?: unknown}) => string | ||
| useState: <Value>(value: Value) => [Value, (value: Value) => void] | ||
| } | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-implied-eval -- TypeScript rewrites plain `import()` to `require()` in our CommonJS emit. | ||
| const importInquirerModule = new Function('specifier', 'return import(specifier)') as ( | ||
| specifier: string | ||
| ) => Promise<unknown> | ||
|
|
||
| // Preserve a real runtime dynamic import so Node can load the ESM-only prompt package from CommonJS output. | ||
| export const loadPrompts = () => importInquirerModule('@inquirer/prompts') as Promise<InquirerPrompts> | ||
|
|
||
| export const loadCore = () => importInquirerModule('@inquirer/core') as Promise<InquirerCore> | ||
|
Comment on lines
+102
to
+110
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this needed because we emit commonjs and the new inquirer package is esm only? if so, I'd love to discuss with the guild what it would take to migrate our package from commonjs to esm since it seems like that's the future of the ecosystem |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any way we can avoid handwriting the types here? this feels like itll quickly become a problem to update in the future