Skip to content

Commit 655f4eb

Browse files
authored
Upgrade NativeModuleSample/cpp-lib to RNW 0.78 (#1022)
## Description This PR upgrades the `NativeModuleSample/cpp-lib` sample to RNW 0.78 and also improves our UpgradeSmokeTest script to be more resilient in what it upgrades. ### Why To keep all the samples up to date. ## Screenshots N/A ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/microsoft/react-native-windows-samples/pull/1022)
1 parent 2432411 commit 655f4eb

17 files changed

Lines changed: 755 additions & 600 deletions

File tree

.github/scripts/UpgradeSmokeTest.ps1

Lines changed: 64 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
param(
77
[string]$RnwVersion = "latest",
8+
[bool]$UpgradeCli = $False,
9+
[bool]$UpgradeRnOrg = $False,
810
[bool]$Force = $False
911
)
1012

@@ -40,6 +42,48 @@ Function Compare-SemVer([string]$Left, [string]$Right) {
4042
return $Result
4143
}
4244

45+
Function Upgrade-Package([string]$DependencyName, [string]$DependencyVersion) {
46+
$yarnUpgradeCmd = "upgrade"
47+
if (Test-Path ".yarn") {
48+
$yarnUpgradeCmd = "up"
49+
}
50+
51+
Write-Host -NoNewline "Upgrading to $DependencyName@$DependencyVersion..."
52+
yarn $yarnUpgradeCmd $DependencyName@$DependencyVersion | Out-Null
53+
54+
if ($LastExitCode -ne 0) {
55+
Write-Host " failed."
56+
Write-Error "Failed to upgrade to $DependencyName@$DependencyVersion"
57+
exit $LastExitCode
58+
}
59+
60+
Write-Host " success."
61+
}
62+
63+
Function Get-DependencyVersion([string]$PackageName, [string]$PackageVersion, [string]$DependencyName) {
64+
[string]$DependencyVersion = npm info $PackageName@$PackageVersion dependencies.$DependencyName
65+
Write-Host "Package $PackageName@$PackageVersion depends on $DependencyName@$DependencyVersion"
66+
return $DependencyVersion
67+
}
68+
69+
Function Get-DevDependencyVersion([string]$PackageName, [string]$PackageVersion, [string]$DependencyName) {
70+
[string]$DependencyVersion = npm info $PackageName@$PackageVersion devDependencies.$DependencyName
71+
Write-Host "Package $PackageName@$PackageVersion dev depends on $DependencyName@$DependencyVersion"
72+
return $DependencyVersion
73+
}
74+
75+
Function Upgrade-RnwDependency([string]$RnwVersion, [string]$DependencyName) {
76+
[string]$DependencyVersion = Get-DependencyVersion 'react-native-windows' $RnwVersion $DependencyName
77+
78+
Upgrade-Package $DependencyName $DependencyVersion
79+
}
80+
81+
Function Upgrade-RnwDevDependency([string]$RnwVersion, [string]$DependencyName) {
82+
[string]$DependencyVersion = Get-DevDependencyVersion 'react-native-windows' $RnwVersion $DependencyName
83+
84+
Upgrade-Package $DependencyName $DependencyVersion
85+
}
86+
4387
Write-Host "UpgradeSmokeTest -RnwVersion $RnwVersion"
4488

4589
[string]$LocalRnwVersion = $null
@@ -89,39 +133,29 @@ if ($Force) {
89133
Write-Host "Starting upgrade..."
90134
}
91135

92-
[string]$ReactVersion = npm info react-native-windows@$TargetRnwVersion devDependencies.react
93-
Write-Host "RNW $TargetRnwVersion depends on react@$ReactVersion"
94-
95-
[string]$ReactNativeVersion = npm info react-native-windows@$TargetRnwVersion devDependencies.react-native
96-
Write-Host "RNW $TargetRnwVersion depends on react-native@$ReactNativeVersion"
97-
98-
$yarnUpgradeCmd = "upgrade"
99-
if (Test-Path ".yarn") {
100-
$yarnUpgradeCmd = "up"
101-
}
102-
103-
Write-Host "Upgrading to react@$ReactVersion..."
104-
yarn $yarnUpgradeCmd react@$ReactVersion
105-
106-
if ($LastExitCode -ne 0) {
107-
Write-Error "Failed to upgrade to react @$ReactVersion"
108-
exit $LastExitCode
136+
# Upgrade based on RNW dev dependencies
137+
Upgrade-RnwDevDependency $TargetRnwVersion 'react'
138+
Upgrade-RnwDevDependency $TargetRnwVersion 'react-native'
139+
Upgrade-RnwDevDependency $TargetRnwVersion 'react'
140+
Upgrade-RnwDevDependency $TargetRnwVersion '@types/react'
141+
142+
# Upgrade based on RNW dependencies
143+
if ($UpgradeCli) {
144+
Upgrade-RnwDependency $TargetRnwVersion '@react-native-community/cli'
145+
Upgrade-RnwDependency $TargetRnwVersion '@react-native-community/cli-platform-android'
146+
Upgrade-RnwDependency $TargetRnwVersion '@react-native-community/cli-platform-ios'
109147
}
110148

111-
Write-Host "Upgrading to react-native@$ReactNativeVersion..."
112-
yarn $yarnUpgradeCmd react-native@$ReactNativeVersion
113-
114-
if ($LastExitCode -ne 0) {
115-
Write-Error "Failed to upgrade to react-native@$ReactNativeVersion"
116-
exit $LastExitCode
149+
# Upgrade @react-native/* dependencies based on react-native
150+
if ($UpgradeRnOrg) {
151+
[string]$RnVersion = Get-DevDependencyVersion 'react-native-windows' $RnwVersion 'react-native'
152+
Upgrade-Package '@react-native/metro-config' "^$($RnVersion.Substring(0, 4)).0"
153+
Upgrade-Package '@react-native/babel-preset' "^$($RnVersion.Substring(0, 4)).0"
154+
Upgrade-Package '@react-native/eslint-config' "^$($RnVersion.Substring(0, 4)).0"
155+
Upgrade-Package '@react-native/typescript-config' "^$($RnVersion.Substring(0, 4)).0"
117156
}
118157

119-
Write-Host "Upgrading to react-native-windows@$TargetRnwVersion..."
120-
yarn $yarnUpgradeCmd react-native-windows@$TargetRnwVersion
121-
122-
if ($LastExitCode -ne 0) {
123-
Write-Error "Failed to upgrade to react-native-windows@$TargetRnwVersion"
124-
exit $LastExitCode
125-
}
158+
# Upgrade RNW itself
159+
Upgrade-Package 'react-native-windows' $TargetRnwVersion
126160

127161
exit 0

samples/NativeModuleSample/cpp-lib/README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,17 @@ yarn example-old windows
3131

3232
### Upgrade
3333

34-
**TODO**
34+
First run the **Setup** steps above. Then run the `UpgradeSmokeTest.ps1` script with the target RNW version (usually `latest`):
35+
36+
```ps1
37+
..\..\..\.github\scripts\UpgradeSmokeTest.ps1 latest $True $True $True
38+
```
39+
40+
Then call the following to update the JS and codegen with:
41+
42+
```cmd
43+
yarn prepare
44+
yarn codegen-windows
45+
```
46+
47+
Finally, build and verify *both* example apps as per the **Run** steps above. If both apps work without issue, then go ahead and submit the PR with your changes.

samples/NativeModuleSample/cpp-lib/example-old/package.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
"test:windows": "jest --config jest.config.windows.js"
99
},
1010
"dependencies": {
11-
"react": "18.3.1",
12-
"react-native": "0.76.0",
13-
"react-native-windows": "0.76.0"
11+
"react": "19.0.0",
12+
"react-native": "0.78.0",
13+
"react-native-windows": "0.78.2"
1414
},
1515
"devDependencies": {
1616
"@babel/core": "^7.25.2",
@@ -19,11 +19,10 @@
1919
"@react-native-community/cli": "15.0.0-alpha.2",
2020
"@react-native-community/cli-platform-android": "15.0.0-alpha.2",
2121
"@react-native-community/cli-platform-ios": "15.0.0-alpha.2",
22-
"@react-native/babel-preset": "0.76.0",
23-
"@react-native/metro-config": "0.76.0",
24-
"@react-native/typescript-config": "0.76.0",
25-
"@rnx-kit/jest-preset": "^0.1.17",
26-
"metro-config": "^0.81.0"
22+
"@react-native/babel-preset": "0.78.0",
23+
"@react-native/metro-config": "0.78.0",
24+
"@react-native/typescript-config": "0.78.0",
25+
"@rnx-kit/jest-preset": "^0.1.17"
2726
},
2827
"engines": {
2928
"node": ">=18"

samples/NativeModuleSample/cpp-lib/example-old/windows/NativeModuleSampleExampleOld/packages.lock.json

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
},
1111
"Microsoft.ReactNative": {
1212
"type": "Direct",
13-
"requested": "[0.76.0, )",
14-
"resolved": "0.76.0",
15-
"contentHash": "Ro7YU/18AD1SI4+W04EhGfPLnpc9k58Dy9i5xLoC0b/NlOBz/ahWzuOgXimOMQHG1tnoBoIasNBIovZQe4svaA=="
13+
"requested": "[0.78.2, )",
14+
"resolved": "0.78.2",
15+
"contentHash": "dC8qT8Y7PX8LmOfSE+Xh3Mt6a7r7EHx1wO6mI3ZGU9kTahqtf759fE0oatydEgvCvugYvZIu0BFarZpvVSOmhA=="
1616
},
1717
"Microsoft.ReactNative.Cxx": {
1818
"type": "Direct",
19-
"requested": "[0.76.0, )",
20-
"resolved": "0.76.0",
21-
"contentHash": "MYmg+K4RF/XOyKu4pPmE4IlLFR3oDwh2LmikAedyBqkCoLFGZVuxQ1apPVZKZXlLoABaXHl/Nc36ZHV2sNxI8w==",
19+
"requested": "[0.78.2, )",
20+
"resolved": "0.78.2",
21+
"contentHash": "b37+ruqhuA/HCi8TYVAcklgSdiBUhHyU3/0RJbcdWSyXrACVY10pTGR4tgzFjU8APwl5hAR+Q8zBj2ObMnkK1A==",
2222
"dependencies": {
23-
"Microsoft.ReactNative": "0.76.0"
23+
"Microsoft.ReactNative": "0.78.2"
2424
}
2525
},
2626
"Microsoft.UI.Xaml": {
@@ -46,18 +46,18 @@
4646
"nativemodulesample": {
4747
"type": "Project",
4848
"dependencies": {
49-
"Microsoft.ReactNative": "[0.76.0, )",
50-
"Microsoft.ReactNative.Cxx": "[0.76.0, )",
49+
"Microsoft.ReactNative": "[0.78.2, )",
50+
"Microsoft.ReactNative.Cxx": "[0.78.2, )",
5151
"Microsoft.UI.Xaml": "[2.8.0, )"
5252
}
5353
}
5454
},
5555
"native,Version=v0.0/win10-arm": {
5656
"Microsoft.ReactNative": {
5757
"type": "Direct",
58-
"requested": "[0.76.0, )",
59-
"resolved": "0.76.0",
60-
"contentHash": "Ro7YU/18AD1SI4+W04EhGfPLnpc9k58Dy9i5xLoC0b/NlOBz/ahWzuOgXimOMQHG1tnoBoIasNBIovZQe4svaA=="
58+
"requested": "[0.78.2, )",
59+
"resolved": "0.78.2",
60+
"contentHash": "dC8qT8Y7PX8LmOfSE+Xh3Mt6a7r7EHx1wO6mI3ZGU9kTahqtf759fE0oatydEgvCvugYvZIu0BFarZpvVSOmhA=="
6161
},
6262
"Microsoft.Web.WebView2": {
6363
"type": "Transitive",
@@ -68,9 +68,9 @@
6868
"native,Version=v0.0/win10-arm-aot": {
6969
"Microsoft.ReactNative": {
7070
"type": "Direct",
71-
"requested": "[0.76.0, )",
72-
"resolved": "0.76.0",
73-
"contentHash": "Ro7YU/18AD1SI4+W04EhGfPLnpc9k58Dy9i5xLoC0b/NlOBz/ahWzuOgXimOMQHG1tnoBoIasNBIovZQe4svaA=="
71+
"requested": "[0.78.2, )",
72+
"resolved": "0.78.2",
73+
"contentHash": "dC8qT8Y7PX8LmOfSE+Xh3Mt6a7r7EHx1wO6mI3ZGU9kTahqtf759fE0oatydEgvCvugYvZIu0BFarZpvVSOmhA=="
7474
},
7575
"Microsoft.Web.WebView2": {
7676
"type": "Transitive",
@@ -81,9 +81,9 @@
8181
"native,Version=v0.0/win10-arm64-aot": {
8282
"Microsoft.ReactNative": {
8383
"type": "Direct",
84-
"requested": "[0.76.0, )",
85-
"resolved": "0.76.0",
86-
"contentHash": "Ro7YU/18AD1SI4+W04EhGfPLnpc9k58Dy9i5xLoC0b/NlOBz/ahWzuOgXimOMQHG1tnoBoIasNBIovZQe4svaA=="
84+
"requested": "[0.78.2, )",
85+
"resolved": "0.78.2",
86+
"contentHash": "dC8qT8Y7PX8LmOfSE+Xh3Mt6a7r7EHx1wO6mI3ZGU9kTahqtf759fE0oatydEgvCvugYvZIu0BFarZpvVSOmhA=="
8787
},
8888
"Microsoft.Web.WebView2": {
8989
"type": "Transitive",
@@ -94,9 +94,9 @@
9494
"native,Version=v0.0/win10-x64": {
9595
"Microsoft.ReactNative": {
9696
"type": "Direct",
97-
"requested": "[0.76.0, )",
98-
"resolved": "0.76.0",
99-
"contentHash": "Ro7YU/18AD1SI4+W04EhGfPLnpc9k58Dy9i5xLoC0b/NlOBz/ahWzuOgXimOMQHG1tnoBoIasNBIovZQe4svaA=="
97+
"requested": "[0.78.2, )",
98+
"resolved": "0.78.2",
99+
"contentHash": "dC8qT8Y7PX8LmOfSE+Xh3Mt6a7r7EHx1wO6mI3ZGU9kTahqtf759fE0oatydEgvCvugYvZIu0BFarZpvVSOmhA=="
100100
},
101101
"Microsoft.Web.WebView2": {
102102
"type": "Transitive",
@@ -107,9 +107,9 @@
107107
"native,Version=v0.0/win10-x64-aot": {
108108
"Microsoft.ReactNative": {
109109
"type": "Direct",
110-
"requested": "[0.76.0, )",
111-
"resolved": "0.76.0",
112-
"contentHash": "Ro7YU/18AD1SI4+W04EhGfPLnpc9k58Dy9i5xLoC0b/NlOBz/ahWzuOgXimOMQHG1tnoBoIasNBIovZQe4svaA=="
110+
"requested": "[0.78.2, )",
111+
"resolved": "0.78.2",
112+
"contentHash": "dC8qT8Y7PX8LmOfSE+Xh3Mt6a7r7EHx1wO6mI3ZGU9kTahqtf759fE0oatydEgvCvugYvZIu0BFarZpvVSOmhA=="
113113
},
114114
"Microsoft.Web.WebView2": {
115115
"type": "Transitive",
@@ -120,9 +120,9 @@
120120
"native,Version=v0.0/win10-x86": {
121121
"Microsoft.ReactNative": {
122122
"type": "Direct",
123-
"requested": "[0.76.0, )",
124-
"resolved": "0.76.0",
125-
"contentHash": "Ro7YU/18AD1SI4+W04EhGfPLnpc9k58Dy9i5xLoC0b/NlOBz/ahWzuOgXimOMQHG1tnoBoIasNBIovZQe4svaA=="
123+
"requested": "[0.78.2, )",
124+
"resolved": "0.78.2",
125+
"contentHash": "dC8qT8Y7PX8LmOfSE+Xh3Mt6a7r7EHx1wO6mI3ZGU9kTahqtf759fE0oatydEgvCvugYvZIu0BFarZpvVSOmhA=="
126126
},
127127
"Microsoft.Web.WebView2": {
128128
"type": "Transitive",
@@ -133,9 +133,9 @@
133133
"native,Version=v0.0/win10-x86-aot": {
134134
"Microsoft.ReactNative": {
135135
"type": "Direct",
136-
"requested": "[0.76.0, )",
137-
"resolved": "0.76.0",
138-
"contentHash": "Ro7YU/18AD1SI4+W04EhGfPLnpc9k58Dy9i5xLoC0b/NlOBz/ahWzuOgXimOMQHG1tnoBoIasNBIovZQe4svaA=="
136+
"requested": "[0.78.2, )",
137+
"resolved": "0.78.2",
138+
"contentHash": "dC8qT8Y7PX8LmOfSE+Xh3Mt6a7r7EHx1wO6mI3ZGU9kTahqtf759fE0oatydEgvCvugYvZIu0BFarZpvVSOmhA=="
139139
},
140140
"Microsoft.Web.WebView2": {
141141
"type": "Transitive",

samples/NativeModuleSample/cpp-lib/example/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
"test:windows": "jest --config jest.config.windows.js"
99
},
1010
"dependencies": {
11-
"react": "18.3.1",
12-
"react-native": "0.76.0",
13-
"react-native-windows": "0.76.0"
11+
"react": "19.0.0",
12+
"react-native": "0.78.0",
13+
"react-native-windows": "0.78.2"
1414
},
1515
"devDependencies": {
1616
"@babel/core": "^7.25.2",
@@ -19,9 +19,9 @@
1919
"@react-native-community/cli": "15.0.0-alpha.2",
2020
"@react-native-community/cli-platform-android": "15.0.0-alpha.2",
2121
"@react-native-community/cli-platform-ios": "15.0.0-alpha.2",
22-
"@react-native/babel-preset": "0.76.0",
23-
"@react-native/metro-config": "0.76.0",
24-
"@react-native/typescript-config": "0.76.0",
22+
"@react-native/babel-preset": "0.78.0",
23+
"@react-native/metro-config": "0.78.0",
24+
"@react-native/typescript-config": "0.78.0",
2525
"@rnx-kit/jest-preset": "^0.1.17"
2626
},
2727
"engines": {

0 commit comments

Comments
 (0)