Skip to content

Commit b513ff2

Browse files
authored
Add warnings and deprecations for react-native-windows-init (#13488)
## Description This PR adds version checking to `react-native-windows-init` to give a deprecation warning if the user tries to use it for RNW 0.75 and an error if they use it on a newer version. ### Type of Change - Bug fix (non-breaking change which fixes an issue) ### Why We will be deprecating `react-native-windows-init` in favor of newer methods for adding RNW projects. Resolves #13461 ### What See above. ## Screenshots N/A ## Testing Verified I could se the warning/error when using it with ## Changelog Should this change be included in the release notes: _yes_ Add warnings and deprecations for react-native-windows-init
1 parent 63734c6 commit b513ff2

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Add warnings and deprecations for react-native-windows-init",
4+
"packageName": "react-native-windows-init",
5+
"email": "jthysell@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

packages/react-native-windows-init/src/Cli.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,24 @@ function installReactNativeWindows(
298298
);
299299
}
300300

301+
const parsedVersion = semver.parse(version);
302+
if (parsedVersion) {
303+
const newSteps = "Please see https://microsoft.github.io/react-native-windows/docs/getting-started for the latest method for adding RNW to your project.";
304+
if (parsedVersion.minor > 75
305+
|| (parsedVersion.minor === 0
306+
&& parsedVersion.prerelease.length > 1
307+
&& parsedVersion.prerelease[0] === 'canary'
308+
&& typeof parsedVersion.prerelease[1] === 'number'
309+
&& parsedVersion.prerelease[1] > 843)
310+
) {
311+
// Full-stop, you can't use the command anymore.
312+
throw new CodedError('UnsupportedReactNativeVersion', `react-native-windows-init only supports react-native-windows <= 0.75. ${newSteps}`);
313+
} else if (parsedVersion.minor === 75) {
314+
// You can use the command for now, but it will be deprecated soon.
315+
console.warn(chalk.yellow(`Warning: react-native-windows-init will be deprecated for RNW > 0.75. ${newSteps}`));
316+
}
317+
}
318+
301319
console.log(
302320
`Installing ${chalk.green('react-native-windows')}@${chalk.cyan(
303321
version,

0 commit comments

Comments
 (0)