Skip to content

Commit 1294e90

Browse files
Copilotdmichon-msft
andcommitted
Replace inquirer with @inquirer/* packages
Agent-Logs-Url: https://github.com/microsoft/rushstack/sessions/489f4c8b-19ff-4dd2-9198-b68f948590c4 Co-authored-by: dmichon-msft <26827560+dmichon-msft@users.noreply.github.com>
1 parent dc158dd commit 1294e90

File tree

6 files changed

+145
-455
lines changed

6 files changed

+145
-455
lines changed

common/config/rush/nonbrowser-approved-packages.json

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,26 @@
2626
"name": "@eslint/eslintrc",
2727
"allowedCategories": [ "libraries" ]
2828
},
29+
{
30+
"name": "@inquirer/checkbox",
31+
"allowedCategories": [ "libraries" ]
32+
},
33+
{
34+
"name": "@inquirer/confirm",
35+
"allowedCategories": [ "libraries" ]
36+
},
37+
{
38+
"name": "@inquirer/input",
39+
"allowedCategories": [ "libraries" ]
40+
},
41+
{
42+
"name": "@inquirer/search",
43+
"allowedCategories": [ "libraries" ]
44+
},
45+
{
46+
"name": "@inquirer/select",
47+
"allowedCategories": [ "libraries" ]
48+
},
2949
{
3050
"name": "@jest/core",
3151
"allowedCategories": [ "libraries" ]
@@ -794,10 +814,6 @@
794814
"name": "import-lazy",
795815
"allowedCategories": [ "libraries" ]
796816
},
797-
{
798-
"name": "inquirer",
799-
"allowedCategories": [ "libraries" ]
800-
},
801817
{
802818
"name": "jest",
803819
"allowedCategories": [ "libraries", "tests" ]

libraries/rush-lib/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,15 @@
6262
"dependency-path": "~9.2.8",
6363
"dotenv": "~16.4.7",
6464
"fast-glob": "~3.3.1",
65-
"figures": "3.0.0",
6665
"git-repo-info": "~2.1.0",
6766
"glob-escape": "~0.0.2",
6867
"https-proxy-agent": "~5.0.0",
6968
"ignore": "~5.1.6",
70-
"inquirer": "~8.2.7",
69+
"@inquirer/checkbox": "~5.1.3",
70+
"@inquirer/confirm": "~6.0.11",
71+
"@inquirer/input": "~5.0.11",
72+
"@inquirer/search": "~4.1.7",
73+
"@inquirer/select": "~5.1.3",
7174
"js-yaml": "~4.1.0",
7275
"npm-package-arg": "~6.1.0",
7376
"object-hash": "3.0.0",
@@ -89,7 +92,6 @@
8992
"@rushstack/webpack-deep-imports-plugin": "workspace:*",
9093
"@rushstack/webpack-preserve-dynamic-require-plugin": "workspace:*",
9194
"@types/cli-table": "0.3.0",
92-
"@types/inquirer": "7.3.1",
9395
"@types/js-yaml": "4.0.9",
9496
"@types/npm-package-arg": "6.1.0",
9597
"@types/object-hash": "~3.0.6",

libraries/rush-lib/src/cli/actions/ChangeAction.ts

Lines changed: 32 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import * as path from 'node:path';
55
import * as child_process from 'node:child_process';
66

7-
import type * as InquirerType from 'inquirer';
87

98
import type {
109
CommandLineFlagParameter,
@@ -246,8 +245,6 @@ export class ChangeAction extends BaseRushAction {
246245

247246
await this._warnUnstagedChangesAsync();
248247

249-
const inquirer: typeof InquirerType = await import('inquirer');
250-
const promptModule: InquirerType.PromptModule = inquirer.createPromptModule();
251248
let changeFileData: Map<string, IChangeFile> = new Map<string, IChangeFile>();
252249
let interactiveMode: boolean = false;
253250
if (this._bulkChangeParameter.value) {
@@ -323,15 +320,14 @@ export class ChangeAction extends BaseRushAction {
323320
await this._getChangeFilesSinceBaseBranchAsync()
324321
);
325322
changeFileData = await this._promptForChangeFileDataAsync(
326-
promptModule,
327323
sortedProjectList,
328324
existingChangeComments
329325
);
330326

331327
if (this._isEmailRequired(changeFileData)) {
332328
const email: string = this._changeEmailParameter.value
333329
? this._changeEmailParameter.value
334-
: await this._detectOrAskForEmailAsync(promptModule);
330+
: await this._detectOrAskForEmailAsync();
335331
changeFileData.forEach((changeFile: IChangeFile) => {
336332
changeFile.email = this.rushConfiguration.getProjectByName(changeFile.packageName)?.versionPolicy
337333
?.includeEmailInChangeFile
@@ -343,7 +339,6 @@ export class ChangeAction extends BaseRushAction {
343339
let changefiles: string[];
344340
try {
345341
changefiles = await this._writeChangeFilesAsync(
346-
promptModule,
347342
changeFileData,
348343
this._overwriteFlagParameter.value,
349344
interactiveMode
@@ -528,15 +523,13 @@ export class ChangeAction extends BaseRushAction {
528523
* The main loop which prompts the user for information on changed projects.
529524
*/
530525
private async _promptForChangeFileDataAsync(
531-
promptModule: InquirerType.PromptModule,
532526
sortedProjectList: string[],
533527
existingChangeComments: Map<string, string[]>
534528
): Promise<Map<string, IChangeFile>> {
535529
const changedFileData: Map<string, IChangeFile> = new Map<string, IChangeFile>();
536530

537531
for (const projectName of sortedProjectList) {
538532
const changeInfo: IChangeInfo | undefined = await this._askQuestionsAsync(
539-
promptModule,
540533
projectName,
541534
existingChangeComments
542535
);
@@ -563,7 +556,6 @@ export class ChangeAction extends BaseRushAction {
563556
* Asks all questions which are needed to generate changelist for a project.
564557
*/
565558
private async _askQuestionsAsync(
566-
promptModule: InquirerType.PromptModule,
567559
packageName: string,
568560
existingChangeComments: Map<string, string[]>
569561
): Promise<IChangeInfo | undefined> {
@@ -574,11 +566,10 @@ export class ChangeAction extends BaseRushAction {
574566
comments.forEach((comment) => {
575567
this.terminal.writeLine(` > ${comment}`);
576568
});
577-
const { appendComment }: { appendComment: 'skip' | 'append' } = await promptModule({
578-
name: 'appendComment',
579-
type: 'list',
580-
default: 'skip',
569+
const { default: select } = await import('@inquirer/select');
570+
const appendComment: 'skip' | 'append' = await select<'skip' | 'append'>({
581571
message: 'Append to existing comments or skip?',
572+
default: 'skip',
582573
choices: [
583574
{
584575
name: 'Skip',
@@ -594,23 +585,19 @@ export class ChangeAction extends BaseRushAction {
594585
if (appendComment === 'skip') {
595586
return undefined;
596587
} else {
597-
return await this._promptForCommentsAsync(promptModule, packageName);
588+
return await this._promptForCommentsAsync(packageName);
598589
}
599590
} else {
600-
return await this._promptForCommentsAsync(promptModule, packageName);
591+
return await this._promptForCommentsAsync(packageName);
601592
}
602593
}
603594

604595
private async _promptForCommentsAsync(
605-
promptModule: InquirerType.PromptModule,
606596
packageName: string
607597
): Promise<IChangeInfo | undefined> {
608598
const bumpOptions: { [type: string]: string } = this._getBumpOptions(packageName);
609-
const { comment }: { comment: string } = await promptModule({
610-
name: 'comment',
611-
type: 'input',
612-
message: `Describe changes, or ENTER if no changes:`
613-
});
599+
const { default: input } = await import('@inquirer/input');
600+
const comment: string = await input({ message: `Describe changes, or ENTER if no changes:` });
614601

615602
if (Object.keys(bumpOptions).length === 0 || !comment) {
616603
return {
@@ -619,17 +606,16 @@ export class ChangeAction extends BaseRushAction {
619606
type: ChangeType[ChangeType.none]
620607
} as IChangeInfo;
621608
} else {
622-
const { bumpType }: { bumpType: string } = await promptModule({
609+
const { default: select } = await import('@inquirer/select');
610+
const bumpType: string = await select<string>({
623611
choices: Object.keys(bumpOptions).map((option) => {
624612
return {
625613
value: option,
626614
name: bumpOptions[option]
627615
};
628616
}),
629617
default: 'patch',
630-
message: 'Select the type of change:',
631-
name: 'bumpType',
632-
type: 'list'
618+
message: 'Select the type of change:'
633619
});
634620

635621
return {
@@ -693,10 +679,10 @@ export class ChangeAction extends BaseRushAction {
693679
* Will determine a user's email by first detecting it from their Git config,
694680
* or will ask for it if it is not found or the Git config is wrong.
695681
*/
696-
private async _detectOrAskForEmailAsync(promptModule: InquirerType.PromptModule): Promise<string> {
682+
private async _detectOrAskForEmailAsync(): Promise<string> {
697683
return (
698-
(await this._detectAndConfirmEmailAsync(promptModule)) ||
699-
(await this._promptForEmailAsync(promptModule))
684+
(await this._detectAndConfirmEmailAsync()) ||
685+
(await this._promptForEmailAsync())
700686
);
701687
}
702688

@@ -716,20 +702,15 @@ export class ChangeAction extends BaseRushAction {
716702
* Detects the user's email address from their Git configuration, prompts the user to approve the
717703
* detected email. It returns undefined if it cannot be detected.
718704
*/
719-
private async _detectAndConfirmEmailAsync(
720-
promptModule: InquirerType.PromptModule
721-
): Promise<string | undefined> {
705+
private async _detectAndConfirmEmailAsync(): Promise<string | undefined> {
722706
const email: string | undefined = this._detectEmail();
723707

724708
if (email) {
725-
const { isCorrectEmail }: { isCorrectEmail: boolean } = await promptModule([
726-
{
727-
type: 'confirm',
728-
name: 'isCorrectEmail',
729-
default: 'Y',
730-
message: `Is your email address ${email}?`
731-
}
732-
]);
709+
const { default: confirm } = await import('@inquirer/confirm');
710+
const isCorrectEmail: boolean = await confirm({
711+
message: `Is your email address ${email}?`,
712+
default: true
713+
});
733714
return isCorrectEmail ? email : undefined;
734715
} else {
735716
return undefined;
@@ -739,18 +720,14 @@ export class ChangeAction extends BaseRushAction {
739720
/**
740721
* Asks the user for their email address
741722
*/
742-
private async _promptForEmailAsync(promptModule: InquirerType.PromptModule): Promise<string> {
743-
const { email }: { email: string } = await promptModule([
744-
{
745-
type: 'input',
746-
name: 'email',
747-
message: 'What is your email address?',
748-
validate: (input: string) => {
749-
return true; // @todo should be an email
750-
}
723+
private async _promptForEmailAsync(): Promise<string> {
724+
const { default: input } = await import('@inquirer/input');
725+
return await input({
726+
message: 'What is your email address?',
727+
validate: (value: string) => {
728+
return true; // @todo should be an email
751729
}
752-
]);
753-
return email;
730+
});
754731
}
755732

756733
private async _warnUnstagedChangesAsync(): Promise<void> {
@@ -774,15 +751,13 @@ export class ChangeAction extends BaseRushAction {
774751
* Writes change files to the common/changes folder. Will prompt for overwrite if file already exists.
775752
*/
776753
private async _writeChangeFilesAsync(
777-
promptModule: InquirerType.PromptModule,
778754
changeFileData: Map<string, IChangeFile>,
779755
overwrite: boolean,
780756
interactiveMode: boolean
781757
): Promise<string[]> {
782758
const writtenFiles: string[] = [];
783759
await changeFileData.forEach(async (changeFile: IChangeFile) => {
784760
const writtenFile: string | undefined = await this._writeChangeFileAsync(
785-
promptModule,
786761
changeFile,
787762
overwrite,
788763
interactiveMode
@@ -795,7 +770,6 @@ export class ChangeAction extends BaseRushAction {
795770
}
796771

797772
private async _writeChangeFileAsync(
798-
promptModule: InquirerType.PromptModule,
799773
changeFileData: IChangeFile,
800774
overwrite: boolean,
801775
interactiveMode: boolean
@@ -808,7 +782,7 @@ export class ChangeAction extends BaseRushAction {
808782
const shouldWrite: boolean =
809783
!fileExists ||
810784
overwrite ||
811-
(interactiveMode ? await this._promptForOverwriteAsync(promptModule, filePath) : false);
785+
(interactiveMode ? await this._promptForOverwriteAsync(filePath) : false);
812786

813787
if (!interactiveMode && fileExists && !overwrite) {
814788
throw new Error(`Changefile ${filePath} already exists`);
@@ -821,16 +795,12 @@ export class ChangeAction extends BaseRushAction {
821795
}
822796

823797
private async _promptForOverwriteAsync(
824-
promptModule: InquirerType.PromptModule,
825798
filePath: string
826799
): Promise<boolean> {
827-
const overwrite: boolean = await promptModule([
828-
{
829-
name: 'overwrite',
830-
type: 'confirm',
831-
message: `Overwrite ${filePath}?`
832-
}
833-
]);
800+
const { default: confirm } = await import('@inquirer/confirm');
801+
const overwrite: boolean = await confirm({
802+
message: `Overwrite ${filePath}?`
803+
});
834804

835805
if (overwrite) {
836806
return true;

libraries/rush-lib/src/logic/InteractiveUpgrader.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import Prompt from 'inquirer/lib/ui/prompt';
5-
64
import { NpmCheck, type INpmCheckState, type INpmCheckPackageSummary } from '@rushstack/npm-check-fork';
75
import { Colorize } from '@rushstack/terminal';
86

97
import type { RushConfiguration } from '../api/RushConfiguration';
108
import { upgradeInteractive, type IDepsToUpgradeAnswers } from '../utilities/InteractiveUpgradeUI';
119
import type { RushConfigurationProject } from '../api/RushConfigurationProject';
12-
import { SearchListPrompt } from '../utilities/prompts/SearchListPrompt';
1310

1411
interface IUpgradeInteractiveDeps {
1512
projects: RushConfigurationProject[];
@@ -42,26 +39,27 @@ export class InteractiveUpgrader {
4239

4340
private async _getUserSelectedProjectForUpgradeAsync(): Promise<RushConfigurationProject> {
4441
const projects: RushConfigurationProject[] | undefined = this._rushConfiguration.projects;
45-
const ui: Prompt = new Prompt({
46-
list: SearchListPrompt
47-
});
4842

49-
const { selectProject } = await ui.run([
50-
{
51-
name: 'selectProject',
52-
message: 'Select a project you would like to upgrade',
53-
type: 'list',
54-
choices: projects.map((project) => {
55-
return {
43+
const { default: search } = await import('@inquirer/search');
44+
45+
return await search<RushConfigurationProject>({
46+
message: 'Select a project you would like to upgrade',
47+
source: (term) => {
48+
const choices: { name: string; short: string; value: RushConfigurationProject }[] = projects.map(
49+
(project) => ({
5650
name: Colorize.green(project.packageName),
51+
short: project.packageName,
5752
value: project
58-
};
59-
}),
60-
pageSize: 12
61-
}
62-
]);
63-
64-
return selectProject;
53+
})
54+
);
55+
if (!term) {
56+
return choices;
57+
}
58+
const filter: string = term.toUpperCase();
59+
return choices.filter((choice) => choice.short.toUpperCase().includes(filter));
60+
},
61+
pageSize: 12
62+
});
6563
}
6664

6765
private async _getPackageDependenciesStatusAsync(

0 commit comments

Comments
 (0)