Skip to content

Commit cecfdcb

Browse files
committed
ref(inquirer): Replace inquirer with prompts
Inspired by facebook/create-react-app#10083. `prompts` is a modern and lighter alternative to `inquirer` and it is almost a drop-in replacement. This change shaves off 0.7MB from our minified builds.
1 parent ca4165a commit cecfdcb

File tree

4 files changed

+29
-238
lines changed

4 files changed

+29
-238
lines changed

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"@types/async": "^3.0.1",
3232
"@types/cli-table": "^0.3.0",
3333
"@types/form-data": "^2.2.1",
34-
"@types/inquirer": "^0.0.41",
3534
"@types/jest": "^26.0.14",
3635
"@types/js-yaml": "^3.11.1",
3736
"@types/mkdirp": "^1.0.0",
@@ -57,7 +56,7 @@
5756
"esbuild": "^0.11.6",
5857
"eslint": "^7.2.0",
5958
"eslint-config-prettier": "^6.11.0",
60-
"inquirer": "6.2.1",
59+
"prompts": "2.4.1",
6160
"jest": "^26.5.3",
6261
"js-yaml": "3.12.0",
6362
"json-schema-to-typescript": "5.7.0",

src/commands/publish.ts

+10-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as Github from '@octokit/rest';
2-
import * as inquirer from 'inquirer';
2+
import prompts from 'prompts';
33
import { Arguments, Argv, CommandBuilder } from 'yargs';
44
import chalk from 'chalk';
55
import {
@@ -215,19 +215,15 @@ async function promptConfirmation(targetList: BaseTarget[]): Promise<void> {
215215
logger.info(' ');
216216

217217
if (hasInput()) {
218-
const questions = [
219-
{
220-
message: 'Is everything OK? Type "yes" to proceed:',
221-
name: 'readyToPublish',
222-
type: 'input',
223-
// Force the user to type something that is not empty or one letter such
224-
// as y/n to make sure this is a concious choice.
225-
validate: (input: string) =>
226-
input.length >= 2 || 'Please type "yes" to proceed',
227-
},
228-
];
229-
const answers = (await inquirer.prompt(questions)) as any;
230-
const readyToPublish = coerceType<string>(answers.readyToPublish, 'string');
218+
const { readyToPublish } = await prompts({
219+
message: 'Is everything OK? Type "yes" to proceed:',
220+
name: 'readyToPublish',
221+
type: 'text',
222+
// Force the user to type something that is not empty or one letter such
223+
// as y/n to make sure this is a concious choice.
224+
validate: (input: string) =>
225+
input.length >= 2 || 'Please type "yes" to proceed',
226+
});
231227
if (readyToPublish.toLowerCase() !== 'yes') {
232228
logger.error('Oh, okay. Aborting.');
233229
process.exit(1);

src/targets/npm.ts

+9-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { SpawnOptions, spawnSync } from 'child_process';
2-
import * as inquirer from 'inquirer';
2+
import prompts from 'prompts';
33

44
import { logger as loggerRaw } from '../logger';
55
import { TargetConfig } from '../schemas/project_config';
@@ -114,17 +114,14 @@ export class NpmTarget extends BaseTarget {
114114
* Ask the user for the OTP value
115115
*/
116116
protected async requestOtp(): Promise<string> {
117-
const questions = [
118-
{
119-
message: 'Looks like your NPM account uses 2FA. Enter OTP:',
120-
name: 'otp',
121-
type: 'input',
122-
validate: (input: string) =>
123-
(input.length > 3 && input.length < 10) || 'Valid OTP, please',
124-
},
125-
];
126-
const answers = (await inquirer.prompt(questions)) as any;
127-
return answers.otp;
117+
const { otp } = await prompts({
118+
message: 'Looks like your NPM account uses 2FA. Enter OTP:',
119+
name: 'otp',
120+
type: 'text',
121+
validate: (input: string) =>
122+
(input.length > 3 && input.length < 10) || 'Valid OTP, please',
123+
});
124+
return otp;
128125
}
129126

130127
/**

0 commit comments

Comments
 (0)