@@ -48,23 +48,28 @@ export async function promptForArchitectureChoice(
48
48
try {
49
49
let timeoutId : NodeJS . Timeout | undefined ;
50
50
51
- const userInputPromise = prompts (
52
- {
53
- type : 'text' ,
54
- name : 'choice' ,
55
- message :
56
- 'Would you like to continue using the Old Architecture? (Y/N)' ,
57
- validate : ( value : string ) => {
58
- const normalized = value . trim ( ) . toLowerCase ( ) ;
59
- return normalized === 'y' || normalized === 'n'
60
- ? true
61
- : "Invalid input. Please enter 'Y' for Yes or 'N' for No." ;
62
- } ,
63
- } ,
64
- {
65
- onCancel : ( ) => {
66
- throw new Error ( 'User cancelled' ) ;
67
- } ,
51
+ // Wrap prompts in a cancelable promise
52
+ const userInputPromise = new Promise < { choice ?: string } > (
53
+ ( resolve , reject ) => {
54
+ prompts (
55
+ {
56
+ type : 'text' ,
57
+ name : 'choice' ,
58
+ message :
59
+ 'Would you like to continue using the Old Architecture? (Y/N)' ,
60
+ validate : ( value : string ) => {
61
+ const normalized = value . trim ( ) . toLowerCase ( ) ;
62
+ return normalized === 'y' || normalized === 'n'
63
+ ? true
64
+ : "Invalid input. Please enter 'Y' for Yes or 'N' for No." ;
65
+ } ,
66
+ } ,
67
+ {
68
+ onCancel : ( ) => reject ( new Error ( 'User cancelled' ) ) ,
69
+ } ,
70
+ )
71
+ . then ( resolve )
72
+ . catch ( reject ) ;
68
73
} ,
69
74
) ;
70
75
@@ -82,7 +87,8 @@ export async function promptForArchitectureChoice(
82
87
83
88
const response = await Promise . race ( [ userInputPromise , timeoutPromise ] ) ;
84
89
85
- if ( timeoutId ) clearTimeout ( timeoutId ) ; // prevent late logging after resolution
90
+ // ensures timeout callback never runs after user input
91
+ if ( timeoutId ) clearTimeout ( timeoutId ) ;
86
92
87
93
if ( ! response . choice ) {
88
94
// User cancelled or no input
0 commit comments