Skip to content

Commit 06c0ef6

Browse files
committed
feat: add expo 50 support
1 parent a06737a commit 06c0ef6

7 files changed

Lines changed: 69 additions & 15 deletions

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
Config plugin to auto-configure [`react-native-code-push`][lib] when the native code is generated (`npx expo prebuild`).
44

55
### ⚠️ Remove Expo updates completely ⚠️
6+
67
Before installing this package, you need completely remove Expo updates from your project:
8+
79
- Expo updates configurations
810
- Expo updates execution code in your app
911
- Expo updates package `npm uninstall -s expo-updates` or `yarn remove expo-updates`
1012
- Any other thing you have done with Expo updates
1113

1214
### Add the package to your npm dependencies
1315

14-
> Tested against Expo SDK 49
16+
> Tested against Expo SDK 50
1517
1618
```
1719
yarn add react-native-code-push react-native-code-push-plugin

build/android/buildscriptDependency.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/android/buildscriptDependency.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/android/mainApplicationDependency.js

Lines changed: 22 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/android/mainApplicationDependency.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/android/buildscriptDependency.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ function applyImplementation(appBuildGradle: string) {
1212
return appBuildGradle;
1313
}
1414

15+
// The default on Expo 50
16+
const reactNative73Include = `apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim(), "../native_modules.gradle");`;
17+
if (appBuildGradle.includes(reactNative73Include)) {
18+
return addBelowAnchorIfNotFound(
19+
appBuildGradle,
20+
reactNative73Include,
21+
codePushImplementation
22+
);
23+
}
24+
1525
// Seems to be the default on Expo 49
1626
const reactNative71Include = `apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json')"].execute(null, rootDir).text.trim(), "../native_modules.gradle");`;
1727
if (appBuildGradle.includes(reactNative71Include)) {

src/android/mainApplicationDependency.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,26 @@ export const withAndroidMainApplicationDependency: ConfigPlugin<
1818
"import com.microsoft.codepush.react.CodePush;"
1919
);
2020

21+
// The default on Expo 50, which uses kotlin
22+
const kotlinAnchor = `override fun getJSMainModuleName(): String = ".expo/.virtual-metro-entry"`;
23+
if (mainApplicationProps.modResults.contents.includes(kotlinAnchor)) {
24+
/**
25+
* Override the getJSBundleFile method in order to let
26+
* the CodePush runtime determine where to get the JS
27+
* bundle location from on each app start
28+
*/
29+
const kotlinJSBundleFileOverride = `
30+
override fun getJSBundleFile(): String? {
31+
return CodePush.getJSBundleFile()
32+
}
33+
`;
34+
mainApplicationProps.modResults.contents = addBelowAnchorIfNotFound(
35+
mainApplicationProps.modResults.contents,
36+
kotlinAnchor,
37+
kotlinJSBundleFileOverride
38+
);
39+
}
40+
2141
/**
2242
* Override the getJSBundleFile method in order to let
2343
* the CodePush runtime determine where to get the JS
@@ -29,30 +49,30 @@ export const withAndroidMainApplicationDependency: ConfigPlugin<
2949
return CodePush.getJSBundleFile();
3050
}\n`;
3151

32-
// This seems to be the default on Expo 49
52+
// The default on Expo 49
53+
const defaultReactNativeAnchor = "new DefaultReactNativeHost(this) {";
3354
if (
3455
mainApplicationProps.modResults.contents.includes(
35-
"new DefaultReactNativeHost(this) {"
56+
defaultReactNativeAnchor
3657
)
3758
) {
3859
mainApplicationProps.modResults.contents = addBelowAnchorIfNotFound(
3960
mainApplicationProps.modResults.contents,
40-
`new DefaultReactNativeHost(this) {`,
61+
defaultReactNativeAnchor,
4162
getJSBundleFileOverride
4263
);
4364

4465
return mainApplicationProps;
4566
}
4667

4768
// This is for compatibility, as it follows the Codepush instructions up-to-spec.
69+
const reactNativeHostAnchor = "new ReactNativeHost(this) {";
4870
if (
49-
mainApplicationProps.modResults.contents.includes(
50-
"new ReactNativeHost(this) {"
51-
)
71+
mainApplicationProps.modResults.contents.includes(reactNativeHostAnchor)
5272
) {
5373
mainApplicationProps.modResults.contents = addBelowAnchorIfNotFound(
5474
mainApplicationProps.modResults.contents,
55-
`new ReactNativeHost(this) {`,
75+
reactNativeHostAnchor,
5676
getJSBundleFileOverride
5777
);
5878

0 commit comments

Comments
 (0)