-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Update CLI to show static warning for old architecture in run-windows and interactive prompt for init-windows #15038
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
dfeffaf
8b30d54
076d5dd
088f489
eef0011
e81d4bc
c7c9ddf
507d9dc
5414f0c
914d633
a2049c4
38ba951
8570475
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "prerelease", | ||
"comment": "Update CLI to show static warning for old architecture in run-windows and interactive prompt for init-windows (#15029)", | ||
"packageName": "@react-native-windows/cli", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
anupriya13 marked this conversation as resolved.
Show resolved
Hide resolved
anupriya13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* 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<typeof prompts>; | ||
|
||
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); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,67 @@ | ||||||
/** | ||||||
* Copyright (c) Microsoft Corporation. | ||||||
* Licensed under the MIT License. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The copyright notice is inconsistent with other test files. It should be 'Copyright (c) Microsoft Corporation. All rights reserved.' to match the pattern used in the test file.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Disregard this review comment. The correct copyright that we use in all files is:
|
||||||
* @format | ||||||
*/ | ||||||
|
||||||
import prompts from 'prompts'; | ||||||
import chalk from 'chalk'; | ||||||
export interface ArchitecturePromptResult { | ||||||
shouldContinueWithOldArch: boolean; | ||||||
userCancelled: boolean; | ||||||
} | ||||||
|
||||||
export async function promptForArchitectureChoice(): Promise<ArchitecturePromptResult> { | ||||||
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."; | ||||||
anupriya13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
}, | ||||||
}, | ||||||
{ | ||||||
onCancel: () => { | ||||||
throw new Error('User cancelled'); | ||||||
}, | ||||||
}, | ||||||
); | ||||||
|
||||||
if (!response.choice) { | ||||||
anupriya13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
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}; | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. | ||
* Licensed under the MIT License. | ||
* @format | ||
*/ | ||
|
||
import chalk from 'chalk'; | ||
|
||
/** | ||
* Displays a warning message about the Old Architecture template. | ||
*/ | ||
export function showOldArchitectureWarning(): void { | ||
console.log( | ||
chalk.yellow( | ||
`⚠️ This project is using the React Native (for Windows) Old Architecture. The old architecture will begin to be removed starting with react-native-windows version 0.82.`, | ||
anupriya13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
), | ||
); | ||
console.log(); | ||
console.log( | ||
chalk.cyan( | ||
'💡 It is strongly recommended to move to the new architecture as soon as possible to take advantage of improved performance, long-term support, and modern capabilities.', | ||
), | ||
); | ||
console.log(); | ||
console.log( | ||
chalk.blue( | ||
'🔗 Learn more: https://microsoft.github.io/react-native-windows/docs/new-architecture', | ||
), | ||
); | ||
console.log(); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.