44import * as path from 'node:path' ;
55import * as child_process from 'node:child_process' ;
66
7- import type * as InquirerType from 'inquirer' ;
87
98import 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 ;
0 commit comments