Skip to content

Commit 7f1c866

Browse files
authored
refactor: migrate all prompts from inquirer to @inquirer/prompts (#8551)
1 parent 511c37d commit 7f1c866

49 files changed

Lines changed: 664 additions & 1261 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎package-lock.json‎

Lines changed: 238 additions & 489 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
},
5454
"dependencies": {
5555
"@fastify/static": "^10.0.0",
56-
"@inquirer/search": "^4.3.3",
56+
"@inquirer/prompts": "^8.7.2",
5757
"@netlify/ai": "^1.0.1",
5858
"@netlify/api": "^15.1.2",
5959
"@netlify/blobs": "^11.1.3",
@@ -108,7 +108,6 @@
108108
"http-proxy": "^1.18.1",
109109
"http-proxy-middleware": "^3.0.5",
110110
"https-proxy-agent": "^8.0.0",
111-
"inquirer": "^8.2.7",
112111
"is-docker": "^4.0.0",
113112
"is-stream": "^4.0.1",
114113
"is-wsl": "^3.1.0",
@@ -167,7 +166,6 @@
167166
"@types/express": "^5.0.6",
168167
"@types/folder-walker": "^3.2.5",
169168
"@types/gitconfiglocal": "^2.0.3",
170-
"@types/inquirer": "^9.0.9",
171169
"@types/jsonwebtoken": "^9.0.10",
172170
"@types/lodash.shuffle": "^4.2.9",
173171
"@types/multiparty": "^4.2.1",

‎src/commands/agents/agents-create.ts‎

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { OptionValues } from 'commander'
2-
import inquirer from 'inquirer'
2+
import { input, select } from '@inquirer/prompts'
33

44
import { chalk, logAndThrowError, log, logJson } from '../../utils/command-helpers.js'
55
import { startSpinner, stopSpinner } from '../../lib/spinner.js'
@@ -30,17 +30,10 @@ export const agentsCreate = async (promptArg: string, options: AgentCreateOption
3030

3131
// Interactive prompt if not provided
3232
if (!prompt && !promptArg) {
33-
const { promptInput } = await inquirer.prompt<{
34-
promptInput: string
35-
}>([
36-
{
37-
type: 'input',
38-
name: 'promptInput',
39-
message: 'What would you like the agent to do?',
40-
validate: validatePrompt,
41-
},
42-
])
43-
finalPrompt = promptInput
33+
finalPrompt = await input({
34+
message: 'What would you like the agent to do?',
35+
validate: validatePrompt,
36+
})
4437
} else {
4538
finalPrompt = (promptArg || prompt) ?? ''
4639
}
@@ -52,18 +45,11 @@ export const agentsCreate = async (promptArg: string, options: AgentCreateOption
5245

5346
// Agent selection if not provided
5447
if (!agent) {
55-
const { agentInput } = await inquirer.prompt<{
56-
agentInput: string
57-
}>([
58-
{
59-
type: 'list',
60-
name: 'agentInput',
61-
message: 'Which agent would you like to use?',
62-
choices: AVAILABLE_AGENTS,
63-
default: 'claude',
64-
},
65-
])
66-
agent = agentInput
48+
agent = await select({
49+
message: 'Which agent would you like to use?',
50+
choices: AVAILABLE_AGENTS,
51+
default: 'claude',
52+
})
6753
} else {
6854
const agentIsValid = validateAgent(agent)
6955
if (agentIsValid !== true) {
@@ -75,22 +61,16 @@ export const agentsCreate = async (promptArg: string, options: AgentCreateOption
7561
if (!branch) {
7662
const defaultBranch = siteInfo.build_settings?.repo_branch
7763

78-
const { branchInput } = await inquirer.prompt<{
79-
branchInput: string
80-
}>([
81-
{
82-
type: 'input',
83-
name: 'branchInput',
84-
message: 'Which branch would you like to work on?',
85-
default: defaultBranch,
86-
validate: (input: string) => {
87-
if (!input || input.trim().length === 0) {
88-
return 'Branch name is required'
89-
}
90-
return true
91-
},
64+
const branchInput = await input({
65+
message: 'Which branch would you like to work on?',
66+
default: defaultBranch,
67+
validate: (value: string) => {
68+
if (!value || value.trim().length === 0) {
69+
return 'Branch name is required'
70+
}
71+
return true
9272
},
93-
])
73+
})
9474

9575
branch = branchInput.trim()
9676
}

‎src/commands/base-command.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { NodeFS, NoopLogger } from '@netlify/build-info/node'
99
import { resolveConfig } from '@netlify/config'
1010
import { getGlobalConfigStore, LocalState } from '@netlify/dev-utils'
1111
import { isCI } from 'ci-info'
12-
import search from '@inquirer/search'
12+
import { search } from '@inquirer/prompts'
1313
import { Command, CommanderError, Help, Option, type OptionValues } from 'commander'
1414
import debug from 'debug'
1515
import { findUp } from 'find-up'

‎src/commands/clone/clone.ts‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { resolve } from 'path'
22

33
import { LocalState } from '@netlify/dev-utils'
4-
import inquirer from 'inquirer'
4+
import { input } from '@inquirer/prompts'
55

66
import { normalizeRepoUrl } from '../../utils/normalize-repo-url.js'
77
import { chalk, logAndThrowError, log, getToken, netlifyCommand, type APIError } from '../../utils/command-helpers.js'
@@ -26,16 +26,10 @@ const isNetlifyGitServiceUrl = (repoUrl: string): boolean => {
2626
}
2727

2828
const getTargetDir = async (defaultDir: string): Promise<string> => {
29-
const { selectedDir } = await inquirer.prompt<{ selectedDir: string }>([
30-
{
31-
type: 'input',
32-
name: 'selectedDir',
33-
message: 'Where should we clone the repository?',
34-
default: defaultDir,
35-
},
36-
])
37-
38-
return selectedDir
29+
return await input({
30+
message: 'Where should we clone the repository?',
31+
default: defaultDir,
32+
})
3933
}
4034

4135
const cloneRepo = async (repoUrl: string, targetDir: string, debug: boolean): Promise<void> => {

‎src/commands/completion/completion.ts‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'fs'
22
import { homedir } from 'os'
33
import { dirname, join } from 'path'
44
import { fileURLToPath } from 'url'
5-
import inquirer from 'inquirer'
5+
import { confirm } from '@inquirer/prompts'
66

77
import type { OptionValues } from 'commander'
88
import { install, uninstall } from '@pnpm/tabtab'
@@ -56,14 +56,10 @@ export const completionGenerate = async (_options: OptionValues, command: BaseCo
5656
) {
5757
log(`To enable Tabtab autocompletion with zsh, the following line may need to be added to your ~/.zshrc:`)
5858
log(chalk.bold.cyan(`\n${AUTOLOAD_COMPINIT}\n`))
59-
const { compinitAdded } = await inquirer.prompt([
60-
{
61-
type: 'confirm',
62-
name: 'compinitAdded',
63-
message: `Would you like to add it?`,
64-
default: true,
65-
},
66-
])
59+
const compinitAdded = await confirm({
60+
message: `Would you like to add it?`,
61+
default: true,
62+
})
6763
if (compinitAdded) {
6864
fs.readFile(zshConfigFilepath, 'utf8', (_err, data) => {
6965
const updatedZshFile = AUTOLOAD_COMPINIT + '\n' + data

‎src/commands/create/create-action.ts‎

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import { pipeline } from 'stream/promises'
88
import { promisify } from 'util'
99

1010
import type { OptionValues } from 'commander'
11-
import inquirer from 'inquirer'
1211
import fetch from 'node-fetch'
1312

13+
import { select } from '@inquirer/prompts'
1414
import type { NetlifyAPI } from '@netlify/api'
1515
import { LocalState } from '@netlify/dev-utils'
1616

@@ -155,16 +155,10 @@ const selectRepoOwner = async (ghToken: string, repoOwnerFlag?: string): Promise
155155
...orgs.map((org) => ({ name: org.login, value: org.login })),
156156
]
157157

158-
const { owner } = await inquirer.prompt<{ owner: string }>([
159-
{
160-
type: 'list',
161-
name: 'owner',
162-
message: 'Where should the GitHub repo be created?',
163-
choices,
164-
},
165-
])
166-
167-
return owner
158+
return await select({
159+
message: 'Where should the GitHub repo be created?',
160+
choices,
161+
})
168162
}
169163

170164
// TODO: Replace with api client call once the site repo endpoint is added to @netlify/open-api
@@ -283,18 +277,13 @@ export const createAction = async (promptArg: string, options: CreateOptions, co
283277
if (accountSlugFlag) {
284278
accountSlug = accountSlugFlag
285279
} else if (accounts.length > 1) {
286-
const { accountSlug: selected } = await inquirer.prompt<{ accountSlug: string }>([
287-
{
288-
type: 'list',
289-
name: 'accountSlug',
290-
message: 'Team:',
291-
choices: accounts.map((account) => ({
292-
value: account.slug,
293-
name: account.name,
294-
})),
295-
},
296-
])
297-
accountSlug = selected
280+
accountSlug = await select({
281+
message: 'Team:',
282+
choices: accounts.map((account) => ({
283+
value: account.slug,
284+
name: account.name,
285+
})),
286+
})
298287
} else {
299288
accountSlug = accounts[0]?.slug
300289
}

‎src/commands/database/db-init.ts‎

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { mkdir, readdir, writeFile } from 'fs/promises'
33
import { join } from 'path'
44

55
import { applyMigrations } from '@netlify/dev'
6-
import inquirer from 'inquirer'
6+
import { confirm, select } from '@inquirer/prompts'
77

88
import { chalk, log, netlifyCommand } from '../../utils/command-helpers.js'
99
import { startSpinner, stopSpinner } from '../../lib/spinner.js'
@@ -54,17 +54,10 @@ const success = (text: string): void => {
5454

5555
const carefullyWriteFile = async (filePath: string, data: string, projectRoot: string) => {
5656
if (existsSync(filePath)) {
57-
type Answers = {
58-
overwrite: boolean
59-
}
60-
const answers = await inquirer.prompt<Answers>([
61-
{
62-
type: 'confirm',
63-
name: 'overwrite',
64-
message: `Overwrite existing file .${filePath.replace(projectRoot, '')}?`,
65-
},
66-
])
67-
if (answers.overwrite) {
57+
const overwrite = await confirm({
58+
message: `Overwrite existing file .${filePath.replace(projectRoot, '')}?`,
59+
})
60+
if (overwrite) {
6861
await writeFile(filePath, data)
6962
}
7063
} else {
@@ -87,20 +80,14 @@ const promptForQueryStyle = async (interactive: boolean): Promise<QueryStyle> =>
8780
}
8881

8982
log('')
90-
const { queryStyle } = await inquirer.prompt<{ queryStyle: QueryStyle }>([
91-
{
92-
type: 'list',
93-
name: 'queryStyle',
94-
message: 'What is your preferred style?',
95-
default: 'drizzle',
96-
choices: [
97-
{ name: 'Drizzle ORM (recommended)', value: 'drizzle' },
98-
{ name: 'Direct SQL', value: 'raw' },
99-
],
100-
},
101-
])
102-
103-
return queryStyle
83+
return await select<QueryStyle>({
84+
message: 'What is your preferred style?',
85+
default: 'drizzle',
86+
choices: [
87+
{ name: 'Drizzle ORM (recommended)', value: 'drizzle' },
88+
{ name: 'Direct SQL', value: 'raw' },
89+
],
90+
})
10491
}
10592

10693
const promptForStarter = async (interactive: boolean): Promise<boolean> => {
@@ -113,15 +100,10 @@ const promptForStarter = async (interactive: boolean): Promise<boolean> => {
113100
log('and then query it. Alternatively, you can do this yourself at any time.')
114101

115102
log('')
116-
const { answer } = await inquirer.prompt<{ answer: boolean }>([
117-
{
118-
type: 'confirm',
119-
name: 'answer',
120-
message: 'Do you want to create sample data?',
121-
default: true,
122-
},
123-
])
124-
return answer
103+
return await confirm({
104+
message: 'Do you want to create sample data?',
105+
default: true,
106+
})
125107
}
126108

127109
const installDependencies = async (

‎src/commands/database/db-migration-new.ts‎

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { readdir, mkdir, writeFile } from 'fs/promises'
22
import { join } from 'path'
33

4-
import inquirer from 'inquirer'
4+
import { input, select } from '@inquirer/prompts'
55

66
import { log, logJson } from '../../utils/command-helpers.js'
77
import BaseCommand from '../base-command.js'
@@ -91,15 +91,10 @@ export const migrationNew = async (options: MigrationNewOptions, command: BaseCo
9191

9292
if (!description) {
9393
if (isInteractive()) {
94-
const answers = await inquirer.prompt<{ description: string }>([
95-
{
96-
type: 'input',
97-
name: 'description',
98-
message: 'What is the purpose of this migration?',
99-
validate: (input: string) => (input.trim().length > 0 ? true : 'Description cannot be empty'),
100-
},
101-
])
102-
description = answers.description
94+
description = await input({
95+
message: 'What is the purpose of this migration?',
96+
validate: (value: string) => (value.trim().length > 0 ? true : 'Description cannot be empty'),
97+
})
10398
} else {
10499
throw new Error(
105100
`--description <description> argument is required when not running interactively. Provide a description of the migration (e.g. --description "add users table").`,
@@ -111,19 +106,14 @@ export const migrationNew = async (options: MigrationNewOptions, command: BaseCo
111106
const defaultScheme = detectedScheme ?? 'timestamp'
112107

113108
if (isInteractive()) {
114-
const answers = await inquirer.prompt<{ scheme: NumberingScheme }>([
115-
{
116-
type: 'list',
117-
name: 'scheme',
118-
message: 'Numbering scheme:',
119-
choices: [
120-
{ name: 'Timestamp (e.g. 20260312143000) [Recommended]', value: 'timestamp' },
121-
{ name: 'Sequential (e.g. 0001, 0002, ...)', value: 'sequential' },
122-
],
123-
default: defaultScheme,
124-
},
125-
])
126-
scheme = answers.scheme
109+
scheme = await select<NumberingScheme>({
110+
message: 'Numbering scheme:',
111+
choices: [
112+
{ name: 'Timestamp (e.g. 20260312143000) [Recommended]', value: 'timestamp' },
113+
{ name: 'Sequential (e.g. 0001, 0002, ...)', value: 'sequential' },
114+
],
115+
default: defaultScheme,
116+
})
127117
} else {
128118
scheme = defaultScheme
129119
}

0 commit comments

Comments
 (0)