Skip to content

Commit d26464b

Browse files
johnfMikhailSuendukovDmitriyKirakosyan
authored
Support RN 0.71.0 (microsoft#2419)
* Fix contributing instructions Should refer to react-native. react-native-cli was deprecated years ago. * Support RN 0.71.0 (Closes microsoft#2418) React native now uses react-native-gradle-plugin, which works a bit differently. * bump react-native test app version to 0.71.3 * bump ruby version to 2.7.6 * Fix tests to work on case sensitive file system * Add initial Linux support to the tests * Fix inclusion of codepush.gradle in tests * Fix iOS template project for tests * Put entry-file back * Release 7.2.0 * add clean to build android function --------- Co-authored-by: Mikhail Suendukov <[email protected]> Co-authored-by: Dmitriy Kirakosyan <[email protected]>
1 parent a97df22 commit d26464b

File tree

13 files changed

+89
-80
lines changed

13 files changed

+89
-80
lines changed

.github/workflows/react-native-code-push-ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- name: Setup Ruby
3939
uses: ruby/setup-ruby@v1
4040
with:
41-
ruby-version: '2.7.4'
41+
ruby-version: '2.7.6'
4242
bundler-cache: true
4343
- name: Package Installation
4444
run: npm install
@@ -58,7 +58,7 @@ jobs:
5858
- name: Setup Ruby
5959
uses: ruby/setup-ruby@v1
6060
with:
61-
ruby-version: '2.7.4'
61+
ruby-version: '2.7.6'
6262
bundler-cache: true
6363
- name: Install dependencies
6464
run: npm install

CONTRIBUTING.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ Follow these steps to test your modifications to the plugin manually:
3737

3838
First, make sure you have installed the dependencies for the plugin by following the steps above.
3939

40-
Then, make sure you have installed `react-native-cli`.
40+
Then, make sure you have installed `react-native`.
4141

4242
```
43-
npm install -g react-native-cli
43+
npm install -g react-native
4444
```
4545

4646
To run Android tests, make sure you have `sdk\tools`, `sdk\emulator` and `sdk\platform-tools` in your PATH.
@@ -131,4 +131,4 @@ To run the core unit tests on Android and pull the plugin from NPM:
131131
NPM=true CORE=true npm run test:android
132132
```
133133

134-
...and so on!
134+
...and so on!

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ We try our best to maintain backwards compatibility of our plugin with previous
7575
| v0.59 | v5.6+ *(RN refactored js bundle loader code)* |
7676
| v0.60-v0.61 | v6.0+ *(RN migrated to Autolinking)* |
7777
| v0.62-v0.64 | v6.2+ *(RN removed LiveReload)* |
78-
| v0.65-v0.69 | v7.2+ *(RN updated iPhone-target-version)* |
78+
| v0.65-v0.70 | v7.0+ *(RN updated iPhone-target-version)* |
79+
| v0.71 | v7.2+ *(RN moved to react-native-gradle-plugin)* |
7980

8081
*NOTE: `react-native-code-push` versions lower than **[v5.7.0](https://github.com/microsoft/react-native-code-push/releases/tag/v5.7.0)** will stop working in the near future. You can find more information in our [documentation](https://github.com/microsoft/code-push/blob/master/migration-notice.md).*
8182

android/codepush.gradle

+25-19
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import java.nio.file.Paths;
44

5-
def config = project.hasProperty("react") ? project.react : [];
6-
def bundleAssetName = config.bundleAssetName ?: "index.android.bundle"
5+
def config = project.extensions.findByName("react") ?: []
6+
def bundleAssetName = config.bundleAssetName.get() ?: "index.android.bundle"
77

88
// because elvis operator
99
def elvisFile(thing) {
@@ -23,11 +23,18 @@ android.buildTypes.each { buildType ->
2323
buildType.resValue 'string', "CODE_PUSH_APK_BUILD_TIME", String.format("\"%d\"", System.currentTimeMillis())
2424
}
2525

26-
gradle.projectsEvaluated {
26+
gradle.projectsEvaluated {
27+
def debuggableVariants = config.debuggableVariants.get() ?: ['debug']
28+
2729
android.applicationVariants.all { variant ->
30+
// No code push for debuggable variants
31+
if (debuggableVariants.contains(variant.name)) {
32+
return;
33+
}
34+
2835
def nodeModulesPath;
2936
if (config.root) {
30-
nodeModulesPath = Paths.get(config.root, "/node_modules");
37+
nodeModulesPath = Paths.get(config.root.asFile.get().absolutePath, "/node_modules");
3138
} else if (project.hasProperty('nodeModulesPath')) {
3239
nodeModulesPath = project.nodeModulesPath
3340
} else {
@@ -42,40 +49,38 @@ gradle.projectsEvaluated {
4249
def jsBundleFile;
4350

4451
// Additional node commandline arguments
45-
def nodeExecutableAndArgs = config.nodeExecutableAndArgs ?: ["node"]
46-
def extraPackagerArgs = config.extraPackagerArgs ?: []
52+
def nodeExecutableAndArgs = config.nodeExecutableAndArgs.get() ?: ["node"]
53+
def extraPackagerArgs = config.extraPackagerArgs.get() ?: []
4754

4855
// Make this task run right after the bundle task
4956
def generateBundledResourcesHash;
5057

51-
if (variant.hasProperty("bundleJsAndAssets")) {
52-
def reactBundleTask = variant.bundleJsAndAssets
53-
jsBundleDir = reactBundleTask.generatedAssetsFolders[0].absolutePath
54-
resourcesDir = reactBundleTask.generatedResFolders[0].absolutePath
58+
def reactBundleTask = tasks.findByName("createBundle${targetName}JsAndAssets")
59+
if (reactBundleTask) {
60+
jsBundleDir = reactBundleTask.property('jsBundleDir').asFile.get()
61+
resourcesDir = reactBundleTask.property('resourcesDir').asFile.get()
5562
jsBundleFile = file("$jsBundleDir/$bundleAssetName")
5663

5764
generateBundledResourcesHash = tasks.create(
5865
name: "generateBundledResourcesHash${targetName}",
5966
type: Exec) {
6067
commandLine (*nodeExecutableAndArgs, "${nodeModulesPath}/react-native-code-push/scripts/generateBundledResourcesHash.js", resourcesDir, jsBundleFile, jsBundleDir)
6168

62-
enabled config."bundleIn${targetName}" ||
63-
config."bundleIn${variant.buildType.name.capitalize()}" ?:
64-
targetName.toLowerCase().contains("release")
69+
enabled !debuggableVariants.contains(variant.name) ?: targetName.toLowerCase().contains("release")
6570
}
66-
71+
6772
runBefore("merge${targetName}Resources", generateBundledResourcesHash)
68-
runBefore("merge${targetName}Assets", generateBundledResourcesHash)
73+
runBefore("merge${targetName}Assets", generateBundledResourcesHash)
6974
} else {
7075
def jsBundleDirConfigName = "jsBundleDir${targetName}"
71-
jsBundleDir = elvisFile(config."$jsBundleDirConfigName") ?:
76+
jsBundleDir = elvisFile(config."$jsBundleDirConfigName").get() ?:
7277
file("$buildDir/intermediates/assets/${targetPath}")
7378

7479
def resourcesDirConfigName = "resourcesDir${targetName}"
75-
resourcesDir = elvisFile(config."${resourcesDirConfigName}") ?:
80+
resourcesDir = elvisFile(config."${resourcesDirConfigName}").get() ?:
7681
file("$buildDir/intermediates/res/merged/${targetPath}")
7782

78-
// In case version of 'Android Plugin for Gradle'' is lower than 1.3.0
83+
// In case version of 'Android Plugin for Gradle'' is lower than 1.3.0
7984
// '$buildDir' has slightly different structure - 'merged' folder
8085
// does not exists so '${targetPath}' folder contains directly in 'res' folder.
8186
if (!resourcesDir.exists() && file("$buildDir/intermediates/res/${targetPath}").exists()) {
@@ -107,7 +112,8 @@ gradle.projectsEvaluated {
107112
generateBundledResourcesHash.dependsOn("recordFilesBeforeBundleCommand${targetName}")
108113
}
109114

110-
generateBundledResourcesHash.dependsOn("bundle${targetName}JsAndAssets")
115+
generateBundledResourcesHash.dependsOn("createBundle${targetName}JsAndAssets")
116+
111117
runBefore("processArmeabi-v7a${targetName}Resources", generateBundledResourcesHash)
112118
runBefore("processX86${targetName}Resources", generateBundledResourcesHash)
113119
runBefore("processUniversal${targetName}Resources", generateBundledResourcesHash)

code-push-plugin-testing-framework/script/testConfig.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// IMPORTS //
33
var os = require("os");
44
var path = require("path");
5-
var TestUtil_1 = require("./TestUtil");
5+
var TestUtil_1 = require("./testUtil");
66
//////////////////////////////////////////////////////////////////////////////////////////
77
// Configuration variables.
88
// What plugin to use, what project directories to use, etc.

docs/setup-android.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ In order to integrate CodePush into your Android project, please perform the fol
2727
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')
2828
```
2929
30-
2. In your `android/app/build.gradle` file, add the `codepush.gradle` file as an additional build task definition underneath `react.gradle`:
30+
2. In your `android/app/build.gradle` file, add the `codepush.gradle` file as an additional build task definition to the end of the file:
3131
3232
```gradle
3333
...
34-
apply from: "../../node_modules/react-native/react.gradle"
3534
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
3635
...
3736
```

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-code-push",
3-
"version": "7.1.0",
3+
"version": "7.2.0",
44
"description": "React Native plugin for the CodePush service",
55
"main": "CodePush.js",
66
"typings": "typings/react-native-code-push.d.ts",

test/template/index.android.js

-1
This file was deleted.

test/template/index.ios.js

-1
This file was deleted.

test/template/ios/TestCodePush/AppDelegate.m

-34
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#import "AppDelegate.h"
2+
3+
#import <CodePush/CodePush.h>
4+
5+
#import <React/RCTBundleURLProvider.h>
6+
#import <React/RCTBridge.h>
7+
#import <React/RCTRootView.h>
8+
9+
@implementation AppDelegate
10+
11+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
12+
{
13+
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
14+
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
15+
moduleName:@"CODE_PUSH_TEST_APP_NAME"
16+
initialProperties:nil];
17+
18+
self.moduleName = @"TestCodePush";
19+
// You can add your custom initial props in the dictionary below.
20+
// They will be passed down to the ViewController used by React Native.
21+
self.initialProps = @{};
22+
23+
return [super application:application didFinishLaunchingWithOptions:launchOptions];
24+
}
25+
26+
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
27+
{
28+
return [CodePush bundleURL];
29+
}
30+
31+
/// This method controls whether the `concurrentRoot`feature of React18 is turned on or off.
32+
///
33+
/// @see: https://reactjs.org/blog/2022/03/29/react-v18.html
34+
/// @note: This requires to be rendering on Fabric (i.e. on the New Architecture).
35+
/// @return: `true` if the `concurrentRoot` feature is enabled. Otherwise, it returns `false`.
36+
- (BOOL)concurrentRootEnabled
37+
{
38+
return true;
39+
}
40+
41+
@end

test/test.ts

+11-13
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ class RNAndroid extends Platform.Android implements RNPlatform {
8383
//// Set up gradle to build CodePush with the app
8484
// Add CodePush to android/app/build.gradle
8585
const buildGradle = path.join(innerprojectDirectory, "android", "app", "build.gradle");
86+
8687
TestUtil.replaceString(buildGradle,
87-
"apply from: \"../../node_modules/react-native/react.gradle\"",
88-
"apply from: \"../../node_modules/react-native/react.gradle\"\napply from: \"" + gradleContent + "\"");
88+
"apply from: file\\(\"../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle\"\\); applyNativeModulesAppBuildGradle\\(project\\)",
89+
"apply from: file(\"../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle\"); applyNativeModulesAppBuildGradle(project)\napply from: \"" + gradleContent + "\"");
8990

9091
// Add CodePush to android/settings.gradle
9192
const settingsGradle = path.join(innerprojectDirectory, "android", "settings.gradle");
@@ -122,13 +123,10 @@ class RNAndroid extends Platform.Android implements RNPlatform {
122123
* Build function of the test application, the command depends on the OS
123124
*/
124125
buildFunction(androidDirectory: string): Q.Promise<void> {
125-
if (process.platform === "darwin") {
126-
return TestUtil.getProcessOutput(`./gradlew assembleRelease --daemon`, { noLogStdOut: true, cwd: androidDirectory })
127-
.then(() => { return null; });
128-
} else {
129-
return TestUtil.getProcessOutput(`gradlew assembleRelease --daemon`, { noLogStdOut: true, cwd: androidDirectory })
126+
const gradlewCommand = process.platform === "darwin" || process.platform === "linux" ? "./gradlew" : "gradlew";
127+
return TestUtil.getProcessOutput(`${gradlewCommand} clean`, { noLogStdOut: true, cwd: androidDirectory })
128+
.then(() => TestUtil.getProcessOutput(`${gradlewCommand} assembleRelease --daemon`, { noLogStdOut: true, cwd: androidDirectory }))
130129
.then(() => { return null; });
131-
}
132130
}
133131

134132
/**
@@ -178,7 +176,7 @@ class RNIOS extends Platform.IOS implements RNPlatform {
178176
installPlatform(projectDirectory: string): Q.Promise<void> {
179177
const iOSProject: string = path.join(projectDirectory, TestConfig.TestAppName, "ios");
180178
const infoPlistPath: string = path.join(iOSProject, TestConfig.TestAppName, "Info.plist");
181-
const appDelegatePath: string = path.join(iOSProject, TestConfig.TestAppName, "AppDelegate.m");
179+
const appDelegatePath: string = path.join(iOSProject, TestConfig.TestAppName, "AppDelegate.mm");
182180

183181

184182
// Install the Podfile
@@ -195,9 +193,9 @@ class RNIOS extends Platform.IOS implements RNPlatform {
195193
// Add the correct bundle identifier
196194
.then(TestUtil.replaceString.bind(undefined, path.join(iOSProject, TestConfig.TestAppName + ".xcodeproj", "project.pbxproj"),
197195
"PRODUCT_BUNDLE_IDENTIFIER = [^;]*", "PRODUCT_BUNDLE_IDENTIFIER = \"" + TestConfig.TestNamespace + "\""))
198-
// Copy the AppDelegate.m to the project
196+
// Copy the AppDelegate.mm to the project
199197
.then(TestUtil.copyFile.bind(undefined,
200-
path.join(TestConfig.templatePath, "ios", TestConfig.TestAppName, "AppDelegate.m"),
198+
path.join(TestConfig.templatePath, "ios", TestConfig.TestAppName, "AppDelegate.mm"),
201199
appDelegatePath, true))
202200
.then<void>(TestUtil.replaceString.bind(undefined, appDelegatePath, TestUtil.CODE_PUSH_TEST_APP_NAME_PLACEHOLDER, TestConfig.TestAppName));
203201
}
@@ -307,7 +305,7 @@ class RNProjectManager extends ProjectManager {
307305
}
308306
mkdirp.sync(projectDirectory);
309307

310-
return TestUtil.getProcessOutput("npx react-native init " + appName + " --version 0.67.1", { cwd: projectDirectory, timeout: 30 * 60 * 1000 })
308+
return TestUtil.getProcessOutput("npx react-native init " + appName + " --version 0.71.3", { cwd: projectDirectory, timeout: 30 * 60 * 1000 })
311309
.then((e) => { console.log(`"npx react-native init ${appName}" success. cwd=${projectDirectory}`); return e; })
312310
.then(this.copyTemplate.bind(this, templatePath, projectDirectory))
313311
.then<void>(TestUtil.getProcessOutput.bind(undefined, TestConfig.thisPluginInstallString, { cwd: path.join(projectDirectory, TestConfig.TestAppName) }))
@@ -377,7 +375,7 @@ class RNProjectManager extends ProjectManager {
377375
deferred.resolve(undefined);
378376
});
379377
return deferred.promise
380-
.then(TestUtil.getProcessOutput.bind(undefined, "npx react-native bundle --platform " + targetPlatform.getName() + " --entry-file index." + targetPlatform.getName() + ".js --bundle-output " + bundlePath + " --assets-dest " + bundleFolder + " --dev false",
378+
.then(TestUtil.getProcessOutput.bind(undefined, "npx react-native bundle --entry-file index.js --platform " + targetPlatform.getName() + " --bundle-output " + bundlePath + " --assets-dest " + bundleFolder + " --dev false",
381379
{ cwd: path.join(projectDirectory, TestConfig.TestAppName) }))
382380
.then<string>(TestUtil.archiveFolder.bind(undefined, bundleFolder, "", path.join(projectDirectory, TestConfig.TestAppName, "update.zip"), isDiff));
383381
}

0 commit comments

Comments
 (0)