Skip to content

Commit 40e03fc

Browse files
committed
Resolve copilot comments
1 parent d7187e4 commit 40e03fc

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

packages/@react-native-windows/cli/src/utils/architecturePrompt.ts

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,28 @@ export async function promptForArchitectureChoice(
4848
try {
4949
let timeoutId: NodeJS.Timeout | undefined;
5050

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);
6873
},
6974
);
7075

@@ -82,7 +87,8 @@ export async function promptForArchitectureChoice(
8287

8388
const response = await Promise.race([userInputPromise, timeoutPromise]);
8489

85-
if (timeoutId) clearTimeout(timeoutId); // prevent late logging after resolution
90+
// ensures timeout callback never runs after user input
91+
if (timeoutId) clearTimeout(timeoutId);
8692

8793
if (!response.choice) {
8894
// User cancelled or no input

0 commit comments

Comments
 (0)