Skip to content

Commit 77163db

Browse files
committed
Migrate to use @inquirer/confirm
Prompts have been removed from `inquirer` since 10.0.0, so we need to migrate our use of `inquirer.prompt` to the standalone `confirm` prompt offered by `@inquirer/prompt`. It does simplify the code a little as the prompt call now returns the users answers, without having to give each prompt a name and picking the value in an `answers` object. The replacement has happened like for like, leaving the check for whether being [run in a "text terminal"](https://nodejs.org/api/tty.html#tty) when asking for the usage data, but not if changing port. It doesn't add any new test either.
1 parent 7debdfa commit 77163db

File tree

4 files changed

+20
-476
lines changed

4 files changed

+20
-476
lines changed

lib/usage-data.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const os = require('os')
44
const path = require('path')
55

66
// npm dependencies
7-
const inquirer = require('inquirer')
7+
const {default: confirm} = require('@inquirer/confirm')
88
const universalAnalytics = require('universal-analytics')
99
const { v4: uuidv4 } = require('uuid')
1010
const ansiColors = require('ansi-colors')
@@ -50,14 +50,13 @@ function setUsageDataConfig (usageDataConfig) {
5050

5151
// Ask for permission to track data
5252
// returns a Promise with the user's answer
53-
function askForUsageDataPermission () {
54-
return inquirer.prompt([{
55-
name: 'usageData',
56-
message: USAGE_DATA_PROMPT,
57-
type: 'confirm',
58-
when: () => process.stdout.isTTY,
59-
default: false
60-
}]).then(answers => answers.usageData)
53+
async function askForUsageDataPermission () {
54+
if (process.stdout.isTTY) {
55+
return confirm({
56+
message: USAGE_DATA_PROMPT,
57+
default: false
58+
})
59+
}
6160
}
6261

6362
function startTracking (usageDataConfig) {

lib/utils/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const semver = require('semver')
77
const { existsSync } = require('fs')
88

99
// npm dependencies
10-
const inquirer = require('inquirer')
10+
const {default: confirm} = require('@inquirer/confirm')
1111
const portScanner = require('portscanner')
1212
const { marked } = require('marked')
1313

@@ -108,12 +108,10 @@ function findAvailablePort (callback) {
108108
console.error('ERROR: Port ' + port + ' in use - you may have another prototype running.\n')
109109

110110
// Ask user if they want to change port
111-
inquirer.prompt([{
112-
name: 'changePort',
111+
confirm({
113112
message: 'Change to an available port?',
114-
type: 'confirm'
115-
}]).then(answers => {
116-
if (answers.changePort) {
113+
}).then(changePort => {
114+
if (changePort) {
117115
// User answers yes
118116
port = availablePort
119117

0 commit comments

Comments
 (0)