Skip to content

Commit

Permalink
Add warnings and deprecations for react-native-windows-init (#13488)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
jonthysell authored Jul 23, 2024
1 parent 63734c6 commit b513ff2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Add warnings and deprecations for react-native-windows-init",
"packageName": "react-native-windows-init",
"email": "jthysell@microsoft.com",
"dependentChangeType": "patch"
}
18 changes: 18 additions & 0 deletions packages/react-native-windows-init/src/Cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,24 @@ function installReactNativeWindows(
);
}

const parsedVersion = semver.parse(version);
if (parsedVersion) {
const newSteps = "Please see https://microsoft.github.io/react-native-windows/docs/getting-started for the latest method for adding RNW to your project.";
if (parsedVersion.minor > 75
|| (parsedVersion.minor === 0
&& parsedVersion.prerelease.length > 1
&& parsedVersion.prerelease[0] === 'canary'
&& typeof parsedVersion.prerelease[1] === 'number'
&& parsedVersion.prerelease[1] > 843)
) {
// Full-stop, you can't use the command anymore.
throw new CodedError('UnsupportedReactNativeVersion', `react-native-windows-init only supports react-native-windows <= 0.75. ${newSteps}`);
} else if (parsedVersion.minor === 75) {
// You can use the command for now, but it will be deprecated soon.
console.warn(chalk.yellow(`Warning: react-native-windows-init will be deprecated for RNW > 0.75. ${newSteps}`));
}
}

console.log(
`Installing ${chalk.green('react-native-windows')}@${chalk.cyan(
version,
Expand Down

0 comments on commit b513ff2

Please sign in to comment.