diff --git a/change/@react-native-windows-cli-a22acde5-14d3-4dcf-8667-7d50437d1c75.json b/change/@react-native-windows-cli-a22acde5-14d3-4dcf-8667-7d50437d1c75.json new file mode 100644 index 00000000000..26abea80de8 --- /dev/null +++ b/change/@react-native-windows-cli-a22acde5-14d3-4dcf-8667-7d50437d1c75.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Remove Prompt from CLI for switching to new arch.", + "packageName": "@react-native-windows/cli", + "email": "54227869+anupriya13@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/packages/@react-native-windows/cli/src/commands/initWindows/initWindows.ts b/packages/@react-native-windows/cli/src/commands/initWindows/initWindows.ts index 42790e5b63d..0fbd9d8994a 100644 --- a/packages/@react-native-windows/cli/src/commands/initWindows/initWindows.ts +++ b/packages/@react-native-windows/cli/src/commands/initWindows/initWindows.ts @@ -31,7 +31,6 @@ import { import {copyAndReplaceWithChangedCallback} from '../../generator-common'; import * as nameHelpers from '../../utils/nameHelpers'; import {showOldArchitectureWarning} from '../../utils/oldArchWarning'; -import {promptForArchitectureChoice} from '../../utils/architecturePrompt'; import type {InitOptions} from './initWindowsOptions'; import {initOptions} from './initWindowsOptions'; @@ -156,9 +155,6 @@ export class InitWindows { return; } - const userDidNotPassTemplate = !process.argv.some(arg => - arg.startsWith('--template'), - ); this.options.template ??= (this.rnwConfig?.['init-windows']?.template as string | undefined) ?? this.getDefaultTemplateName(); @@ -172,22 +168,9 @@ export class InitWindows { } const isOldArchTemplate = this.options.template.startsWith('old'); - const promptFlag = this.options.prompt; if (isOldArchTemplate) { showOldArchitectureWarning(); - - if (userDidNotPassTemplate && promptFlag) { - const promptResult = await promptForArchitectureChoice(); - - if ( - !promptResult.shouldContinueWithOldArch && - !promptResult.userCancelled - ) { - spinner.info('Switching to New Architecture template (cpp-app)...'); - this.options.template = 'cpp-app'; - } - } } const templateConfig = this.templates.get(this.options.template)!; @@ -321,7 +304,6 @@ function optionSanitizer(key: keyof InitOptions, value: any): any { case 'overwrite': case 'telemetry': case 'list': - case 'prompt': return value === undefined ? false : value; // Return value } } diff --git a/packages/@react-native-windows/cli/src/commands/initWindows/initWindowsOptions.ts b/packages/@react-native-windows/cli/src/commands/initWindows/initWindowsOptions.ts index 4b10906226a..0e54ea1b4f7 100644 --- a/packages/@react-native-windows/cli/src/commands/initWindows/initWindowsOptions.ts +++ b/packages/@react-native-windows/cli/src/commands/initWindows/initWindowsOptions.ts @@ -14,7 +14,6 @@ export interface InitOptions { overwrite?: boolean; telemetry?: boolean; list?: boolean; - prompt?: boolean; } export const initOptions: CommandOption[] = [ @@ -53,8 +52,4 @@ export const initOptions: CommandOption[] = [ description: 'Shows a list with all available templates with their descriptions.', }, - { - name: '--no-prompt', - description: 'Skip any interactive prompts and use default choices.', - }, ]; diff --git a/packages/@react-native-windows/cli/src/e2etest/architecturePrompt.test.ts b/packages/@react-native-windows/cli/src/e2etest/architecturePrompt.test.ts deleted file mode 100644 index 9b3fa02bedd..00000000000 --- a/packages/@react-native-windows/cli/src/e2etest/architecturePrompt.test.ts +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. - * Licensed under the MIT License. - * @format - */ - -import {promptForArchitectureChoice} from '../utils/architecturePrompt'; - -// Mock prompts module -jest.mock('prompts', () => { - return jest.fn(); -}); - -import prompts from 'prompts'; -const mockPrompts = prompts as jest.MockedFunction; - -describe('architecturePrompt', () => { - beforeEach(() => { - jest.clearAllMocks(); - }); - - test('returns true when user chooses Y', async () => { - mockPrompts.mockResolvedValue({choice: 'y'}); - - const result = await promptForArchitectureChoice(); - - expect(result.shouldContinueWithOldArch).toBe(true); - expect(result.userCancelled).toBe(false); - }); - - test('returns true when user chooses Y (uppercase)', async () => { - mockPrompts.mockResolvedValue({choice: 'Y'}); - - const result = await promptForArchitectureChoice(); - - expect(result.shouldContinueWithOldArch).toBe(true); - expect(result.userCancelled).toBe(false); - }); - - test('returns false when user chooses N', async () => { - mockPrompts.mockResolvedValue({choice: 'n'}); - - const result = await promptForArchitectureChoice(); - - expect(result.shouldContinueWithOldArch).toBe(false); - expect(result.userCancelled).toBe(false); - }); - - test('returns false when user chooses N (uppercase)', async () => { - mockPrompts.mockResolvedValue({choice: 'N'}); - - const result = await promptForArchitectureChoice(); - - expect(result.shouldContinueWithOldArch).toBe(false); - expect(result.userCancelled).toBe(false); - }); - - test('returns true with userCancelled when user cancels with no input', async () => { - mockPrompts.mockResolvedValue({}); - - const result = await promptForArchitectureChoice(); - - expect(result.shouldContinueWithOldArch).toBe(true); - expect(result.userCancelled).toBe(true); - }); - - test('returns true with userCancelled when prompts throws cancellation error', async () => { - mockPrompts.mockRejectedValue(new Error('User cancelled')); - - const result = await promptForArchitectureChoice(); - - expect(result.shouldContinueWithOldArch).toBe(true); - expect(result.userCancelled).toBe(true); - }); - - test('returns true and not cancelled on other errors', async () => { - mockPrompts.mockRejectedValue(new Error('Some other error')); - - const result = await promptForArchitectureChoice(); - - expect(result.shouldContinueWithOldArch).toBe(true); - expect(result.userCancelled).toBe(false); - }); -}); diff --git a/packages/@react-native-windows/cli/src/e2etest/initWindows.test.ts b/packages/@react-native-windows/cli/src/e2etest/initWindows.test.ts index a132ef3be1b..2c9a418f141 100644 --- a/packages/@react-native-windows/cli/src/e2etest/initWindows.test.ts +++ b/packages/@react-native-windows/cli/src/e2etest/initWindows.test.ts @@ -26,7 +26,6 @@ function validateOptionName( case 'overwrite': case 'telemetry': case 'list': - case 'prompt': return true; } throw new Error( @@ -56,7 +55,6 @@ test('initOptions - validate options', () => { // Validate all command options are present in InitOptions const optionName = commanderNameToOptionName(commandOption.name); - expect( validateOptionName(commandOption.name, optionName as keyof InitOptions), ).toBe(true); diff --git a/packages/@react-native-windows/cli/src/utils/architecturePrompt.ts b/packages/@react-native-windows/cli/src/utils/architecturePrompt.ts deleted file mode 100644 index 3b2ec30d7d6..00000000000 --- a/packages/@react-native-windows/cli/src/utils/architecturePrompt.ts +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. - * Licensed under the MIT License. - * @format - */ - -import prompts from 'prompts'; -import chalk from 'chalk'; -export interface ArchitecturePromptResult { - shouldContinueWithOldArch: boolean; - userCancelled: boolean; -} - -export async function promptForArchitectureChoice(): Promise { - try { - const response = await prompts( - { - type: 'text', - name: 'choice', - message: 'Would you like to continue using the Old Architecture? (Y/N)', - validate: (value: string) => { - const normalized = value.trim().toLowerCase(); - if (normalized === 'y' || normalized === 'n') { - return true; - } - return "Invalid input. Please enter 'Y' for Yes or 'N' for No."; - }, - }, - { - onCancel: () => { - throw new Error('User cancelled'); - }, - }, - ); - - if (!response.choice) { - return {shouldContinueWithOldArch: true, userCancelled: true}; - } - - const normalizedChoice = response.choice.trim().toLowerCase(); - if (normalizedChoice === 'y') { - console.log( - chalk.yellow( - 'Proceeding with Old Architecture. You can migrate later using our migration guide: https://microsoft.github.io/react-native-windows/docs/new-architecture', - ), - ); - return {shouldContinueWithOldArch: true, userCancelled: false}; - } else { - console.log( - chalk.green( - 'Great choice! Setting up the project with New Architecture support.', - ), - ); - return {shouldContinueWithOldArch: false, userCancelled: false}; - } - } catch (error) { - if ((error as Error).message === 'User cancelled') { - return {shouldContinueWithOldArch: true, userCancelled: true}; - } - console.log( - chalk.yellow( - 'Proceeding with Old Architecture. You can migrate later using our migration guide: https://microsoft.github.io/react-native-windows/docs/new-architecture', - ), - ); - return {shouldContinueWithOldArch: true, userCancelled: false}; - } -} diff --git a/packages/@react-native-windows/cli/src/utils/oldArchWarning.ts b/packages/@react-native-windows/cli/src/utils/oldArchWarning.ts index c40d4042773..c055ca56c35 100644 --- a/packages/@react-native-windows/cli/src/utils/oldArchWarning.ts +++ b/packages/@react-native-windows/cli/src/utils/oldArchWarning.ts @@ -28,4 +28,16 @@ export function showOldArchitectureWarning(): void { ), ); console.log(); + console.log( + chalk.blue( + '🔗 View the list of properties not yet supported in Fabric: https://microsoft.github.io/react-native-windows/docs/new-arch-missingProps', + ), + ); + console.log(); + console.log( + chalk.blue( + '💬 If you encounter missing properties, please open an issue: https://github.com/microsoft/react-native-windows/issues', + ), + ); + console.log(); }