Skip to content

Commit f04d038

Browse files
authored
Add warning to CLI commands about using the old architecture (#14757)
## Description This PR adds warnings to the `run-windows` and `init-windows` CLI commands to warn about using old architecture projects. ### Type of Change - New feature (non-breaking change which adds functionality) ### Why To warn users that their project is using the old architecture and that they should upgrade to the new architecture, as the old architecture will be deprecated. Resolves #13936 ### What See above. ## Screenshots N/A ## Testing Verified commands show the warning ## Changelog Should this change be included in the release notes: _yes_ Add warning to CLI commands about using the old architecture
1 parent 1e3346e commit f04d038

File tree

6 files changed

+88
-13
lines changed

6 files changed

+88
-13
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Add warning to CLI commands about using the old architecture",
4+
"packageName": "@react-native-windows/cli",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/@react-native-windows/cli/src/commands/config/configUtils.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,11 +540,25 @@ export function getRnwConfig(
540540

541541
const config: Record<string, any> = pkgJson['react-native-windows'] ?? {};
542542

543+
const info = getRawTemplateInfo(projectFile);
544+
545+
// inject raw templateInfo for later command use
546+
if (info.projectArch) {
547+
config.projectArch = info.projectArch;
548+
}
549+
550+
if (info.projectLang) {
551+
config.projectLang = info.projectLang;
552+
}
553+
554+
if (info.projectType) {
555+
config.projectType = info.projectType;
556+
}
557+
543558
// if init-windows is missing (most existing projects), try to auto-calculate it
544-
config['init-windows'] ??= {};
545-
if (!config['init-windows'].template) {
546-
const info = getRawTemplateInfo(projectFile);
559+
if (!config['init-windows']?.template) {
547560
if (info.projectArch && info.projectLang && info.projectType) {
561+
config['init-windows'] ??= {};
548562
config['init-windows'].template = `${
549563
info.projectArch === 'old' ? 'old/uwp-' : ''
550564
}${info.projectLang}-${info.projectType}`;

packages/@react-native-windows/cli/src/commands/initWindows/initWindows.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ export class InitWindows {
165165
`Unable to find template '${this.options.template}'.`,
166166
);
167167
}
168+
169+
if (this.options.template.startsWith('old')) {
170+
spinner.warn(
171+
`The legacy '${this.options.template}' template targets the React Native Old Architecture, which will eventually be deprecated. See https://microsoft.github.io/react-native-windows/docs/new-architecture for details on switching to the New Architecture.`,
172+
);
173+
}
174+
168175
const templateConfig = this.templates.get(this.options.template)!;
169176

170177
// Check if there's a passed-in project name and if it's valid

packages/@react-native-windows/cli/src/commands/runWindows/runWindows.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* @format
55
*/
66

7+
/* eslint-disable complexity */
8+
79
import fs from '@react-native-windows/fs';
810
import path from 'path';
911

@@ -38,7 +40,6 @@ import type {AutoLinkOptions} from '../autolinkWindows/autolinkWindowsOptions';
3840
* @param value The unsanitized value of the option.
3941
* @returns The sanitized value of the option.
4042
*/
41-
// eslint-disable-next-line complexity
4243
function optionSanitizer(key: keyof RunWindowsOptions, value: any): any {
4344
// Do not add a default case here.
4445
// Strings risking PII should just return true if present, false otherwise.
@@ -205,6 +206,13 @@ async function runWindowsInternal(
205206
newInfo('Verbose: ON');
206207
}
207208

209+
// Warn about old architecture projects
210+
if (config.project.windows?.rnwConfig?.projectArch === 'old') {
211+
newWarn(
212+
'This project is using the React Native (for Windows) Old Architecture, which will eventually be deprecated. See https://microsoft.github.io/react-native-windows/docs/new-architecture for details on switching to the New Architecture.',
213+
);
214+
}
215+
208216
// Get the solution file
209217
let slnFile: string | null;
210218
runWindowsPhase = 'FindSolution';

packages/@react-native-windows/cli/src/e2etest/__snapshots__/dependencyConfig.test.ts.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ exports[`dependencyConfig - SimpleCSharpLib (Ignore react-native.config.js) 1`]
8181
"init-windows": {
8282
"template": "old/uwp-cs-lib",
8383
},
84+
"projectArch": "old",
85+
"projectLang": "cs",
86+
"projectType": "lib",
8487
},
8588
"solutionFile": "SimpleCSharpLib.sln",
8689
"sourceDir": "windows",
@@ -116,6 +119,9 @@ exports[`dependencyConfig - SimpleCSharpLib (Use react-native.config.js) 1`] = `
116119
"init-windows": {
117120
"template": "old/uwp-cs-lib",
118121
},
122+
"projectArch": "old",
123+
"projectLang": "cs",
124+
"projectType": "lib",
119125
},
120126
"solutionFile": "SimpleCSharpLib.sln",
121127
"sourceDir": "windows",
@@ -179,6 +185,9 @@ exports[`dependencyConfig - SimpleCppLib (Ignore react-native.config.js) 1`] = `
179185
"init-windows": {
180186
"template": "old/uwp-cpp-lib",
181187
},
188+
"projectArch": "old",
189+
"projectLang": "cpp",
190+
"projectType": "lib",
182191
},
183192
"solutionFile": "SimpleCppLib.sln",
184193
"sourceDir": "windows",
@@ -214,6 +223,9 @@ exports[`dependencyConfig - SimpleCppLib (Use react-native.config.js) 1`] = `
214223
"init-windows": {
215224
"template": "old/uwp-cpp-lib",
216225
},
226+
"projectArch": "old",
227+
"projectLang": "cpp",
228+
"projectType": "lib",
217229
},
218230
"solutionFile": "SimpleCppLib.sln",
219231
"sourceDir": "windows",

packages/@react-native-windows/cli/src/e2etest/__snapshots__/projectConfig.test.ts.snap

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ exports[`projectConfig - MissingProjectFilesApp (Ignore react-native.config.js)
1010
"project": {
1111
"projectFile": "Error: No app project file found, please specify in react-native.config.",
1212
},
13-
"rnwConfig": {
14-
"init-windows": {},
15-
},
13+
"rnwConfig": {},
1614
"solutionFile": "Error: No app solution file found, please specify in react-native.config.",
1715
"sourceDir": "windows",
1816
}
@@ -24,9 +22,7 @@ exports[`projectConfig - MissingProjectFilesApp (Use react-native.config.js) 1`]
2422
"project": {
2523
"projectFile": "Error: Project is required but not specified in react-native.config.",
2624
},
27-
"rnwConfig": {
28-
"init-windows": {},
29-
},
25+
"rnwConfig": {},
3026
"solutionFile": "Error: Solution file is required but not specified in react-native.config.",
3127
"sourceDir": "windows",
3228
}
@@ -50,6 +46,9 @@ exports[`projectConfig - SimpleCSharpApp (Ignore react-native.config.js) 1`] = `
5046
"init-windows": {
5147
"template": "old/uwp-cs-app",
5248
},
49+
"projectArch": "old",
50+
"projectLang": "cs",
51+
"projectType": "app",
5352
},
5453
"solutionFile": "SimpleCSharpApp.sln",
5554
"sourceDir": "windows",
@@ -74,6 +73,9 @@ exports[`projectConfig - SimpleCSharpApp (Use react-native.config.js) 1`] = `
7473
"init-windows": {
7574
"template": "old/uwp-cs-app",
7675
},
76+
"projectArch": "old",
77+
"projectLang": "cs",
78+
"projectType": "app",
7779
},
7880
"solutionFile": "SimpleCSharpApp.sln",
7981
"sourceDir": "windows",
@@ -98,6 +100,9 @@ exports[`projectConfig - SimpleCppApp (Ignore react-native.config.js) 1`] = `
98100
"init-windows": {
99101
"template": "old/uwp-cpp-app",
100102
},
103+
"projectArch": "old",
104+
"projectLang": "cpp",
105+
"projectType": "app",
101106
},
102107
"solutionFile": "SimpleCppApp.sln",
103108
"sourceDir": "windows",
@@ -122,6 +127,9 @@ exports[`projectConfig - SimpleCppApp (Use react-native.config.js) 1`] = `
122127
"init-windows": {
123128
"template": "old/uwp-cpp-app",
124129
},
130+
"projectArch": "old",
131+
"projectLang": "cpp",
132+
"projectType": "app",
125133
},
126134
"solutionFile": "SimpleCppApp.sln",
127135
"sourceDir": "windows",
@@ -146,6 +154,9 @@ exports[`projectConfig - WithExperimentalNuget (Ignore react-native.config.js) 1
146154
"init-windows": {
147155
"template": "old/uwp-cpp-app",
148156
},
157+
"projectArch": "old",
158+
"projectLang": "cpp",
159+
"projectType": "app",
149160
},
150161
"solutionFile": "WithExperimentalNuGet.sln",
151162
"sourceDir": "windows",
@@ -170,6 +181,9 @@ exports[`projectConfig - WithExperimentalNuget (Use react-native.config.js) 1`]
170181
"init-windows": {
171182
"template": "old/uwp-cpp-app",
172183
},
184+
"projectArch": "old",
185+
"projectLang": "cpp",
186+
"projectType": "app",
173187
},
174188
"solutionFile": "WithExperimentalNuGet.sln",
175189
"sourceDir": "windows",
@@ -194,6 +208,9 @@ exports[`projectConfig - WithHermes (Ignore react-native.config.js) 1`] = `
194208
"init-windows": {
195209
"template": "old/uwp-cpp-app",
196210
},
211+
"projectArch": "old",
212+
"projectLang": "cpp",
213+
"projectType": "app",
197214
},
198215
"solutionFile": "WithHermes.sln",
199216
"sourceDir": "windows",
@@ -218,6 +235,9 @@ exports[`projectConfig - WithHermes (Use react-native.config.js) 1`] = `
218235
"init-windows": {
219236
"template": "old/uwp-cpp-app",
220237
},
238+
"projectArch": "old",
239+
"projectLang": "cpp",
240+
"projectType": "app",
221241
},
222242
"solutionFile": "WithHermes.sln",
223243
"sourceDir": "windows",
@@ -235,9 +255,7 @@ exports[`projectConfig - WithIndirectDependency (Ignore react-native.config.js)
235255
"project": {
236256
"projectFile": "Error: Too many app project files found, please specify in react-native.config.",
237257
},
238-
"rnwConfig": {
239-
"init-windows": {},
240-
},
258+
"rnwConfig": {},
241259
"solutionFile": "WithIndirectDependency.sln",
242260
"sourceDir": "windows",
243261
}
@@ -261,6 +279,9 @@ exports[`projectConfig - WithIndirectDependency (Use react-native.config.js) 1`]
261279
"init-windows": {
262280
"template": "old/uwp-cpp-app",
263281
},
282+
"projectArch": "old",
283+
"projectLang": "cpp",
284+
"projectType": "app",
264285
},
265286
"solutionFile": "WithIndirectDependency.sln",
266287
"sourceDir": "windows",
@@ -286,6 +307,9 @@ exports[`projectConfig - WithWinUI3 (Ignore react-native.config.js) 1`] = `
286307
"init-windows": {
287308
"template": "old/uwp-cpp-app",
288309
},
310+
"projectArch": "old",
311+
"projectLang": "cpp",
312+
"projectType": "app",
289313
},
290314
"solutionFile": "WithWinUI3.sln",
291315
"sourceDir": "windows",
@@ -310,6 +334,9 @@ exports[`projectConfig - WithWinUI3 (Use react-native.config.js) 1`] = `
310334
"init-windows": {
311335
"template": "old/uwp-cpp-app",
312336
},
337+
"projectArch": "old",
338+
"projectLang": "cpp",
339+
"projectType": "app",
313340
},
314341
"solutionFile": "WithWinUI3.sln",
315342
"sourceDir": "windows",

0 commit comments

Comments
 (0)