From 06c0ef6a8d71976f27a7ee8f9658b90fa893640c Mon Sep 17 00:00:00 2001 From: Gabriel Taveira Date: Sat, 20 Jan 2024 11:21:28 -0300 Subject: [PATCH 1/6] feat: add expo 50 support --- README.md | 4 ++- build/android/buildscriptDependency.js | 5 +++ build/android/buildscriptDependency.js.map | 2 +- build/android/mainApplicationDependency.js | 27 ++++++++++++--- .../android/mainApplicationDependency.js.map | 2 +- src/android/buildscriptDependency.ts | 10 ++++++ src/android/mainApplicationDependency.ts | 34 +++++++++++++++---- 7 files changed, 69 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 268dfb9..795055c 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,9 @@ Config plugin to auto-configure [`react-native-code-push`][lib] when the native code is generated (`npx expo prebuild`). ### ⚠️ Remove Expo updates completely ⚠️ + Before installing this package, you need completely remove Expo updates from your project: + - Expo updates configurations - Expo updates execution code in your app - Expo updates package `npm uninstall -s expo-updates` or `yarn remove expo-updates` @@ -11,7 +13,7 @@ Before installing this package, you need completely remove Expo updates from you ### Add the package to your npm dependencies -> Tested against Expo SDK 49 +> Tested against Expo SDK 50 ``` yarn add react-native-code-push react-native-code-push-plugin diff --git a/build/android/buildscriptDependency.js b/build/android/buildscriptDependency.js index d85c45d..5274919 100644 --- a/build/android/buildscriptDependency.js +++ b/build/android/buildscriptDependency.js @@ -9,6 +9,11 @@ function applyImplementation(appBuildGradle) { if (appBuildGradle.includes(codePushImplementation)) { return appBuildGradle; } + // The default on Expo 50 + 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");`; + if (appBuildGradle.includes(reactNative73Include)) { + return (0, addBelowAnchorIfNotFound_1.addBelowAnchorIfNotFound)(appBuildGradle, reactNative73Include, codePushImplementation); + } // Seems to be the default on Expo 49 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");`; if (appBuildGradle.includes(reactNative71Include)) { diff --git a/build/android/buildscriptDependency.js.map b/build/android/buildscriptDependency.js.map index ab21db0..47744e8 100644 --- a/build/android/buildscriptDependency.js.map +++ b/build/android/buildscriptDependency.js.map @@ -1 +1 @@ -{"version":3,"file":"buildscriptDependency.js","sourceRoot":"","sources":["../../src/android/buildscriptDependency.ts"],"names":[],"mappings":";;;AAAA,wDAAuE;AAGvE,gFAA6E;AAE7E,SAAS,mBAAmB,CAAC,cAAsB;IACjD,MAAM,sBAAsB,GAC1B,iFAAiF,CAAC;IAEpF,6DAA6D;IAC7D,IAAI,cAAc,CAAC,QAAQ,CAAC,sBAAsB,CAAC,EAAE;QACnD,OAAO,cAAc,CAAC;KACvB;IAED,qCAAqC;IACrC,MAAM,oBAAoB,GAAG,2LAA2L,CAAC;IACzN,IAAI,cAAc,CAAC,QAAQ,CAAC,oBAAoB,CAAC,EAAE;QACjD,OAAO,IAAA,mDAAwB,EAC7B,cAAc,EACd,oBAAoB,EACpB,sBAAsB,CACvB,CAAC;KACH;IAED,oBAAoB;IACpB,MAAM,iCAAiC,GAAG,wDAAwD,CAAC;IACnG,IAAI,cAAc,CAAC,QAAQ,CAAC,iCAAiC,CAAC,EAAE;QAC9D,OAAO,IAAA,mDAAwB,EAC7B,cAAc,EACd,iCAAiC,EACjC,sBAAsB,CACvB,CAAC;KACH;IAED,oBAAoB;IACpB,MAAM,2BAA2B,GAAG,4DAA4D,CAAC;IACjG,IAAI,cAAc,CAAC,QAAQ,CAAC,2BAA2B,CAAC,EAAE;QACxD,OAAO,IAAA,mDAAwB,EAC7B,cAAc,EACd,2BAA2B,EAC3B,sBAAsB,CACvB,CAAC;KACH;IAED,MAAM,IAAI,KAAK,CACb,6EAA6E,CAC9E,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACI,MAAM,gCAAgC,GAEzC,CAAC,MAAM,EAAE,EAAE;IACb,OAAO,IAAA,mCAAkB,EAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,EAAE;QACrD,gBAAgB,CAAC,UAAU,CAAC,QAAQ,GAAG,mBAAmB,CACxD,gBAAgB,CAAC,UAAU,CAAC,QAAQ,CACrC,CAAC;QAEF,OAAO,gBAAgB,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAVW,QAAA,gCAAgC,oCAU3C"} \ No newline at end of file +{"version":3,"file":"buildscriptDependency.js","sourceRoot":"","sources":["../../src/android/buildscriptDependency.ts"],"names":[],"mappings":";;;AAAA,wDAAuE;AAGvE,gFAA6E;AAE7E,SAAS,mBAAmB,CAAC,cAAsB;IACjD,MAAM,sBAAsB,GAC1B,iFAAiF,CAAC;IAEpF,6DAA6D;IAC7D,IAAI,cAAc,CAAC,QAAQ,CAAC,sBAAsB,CAAC,EAAE;QACnD,OAAO,cAAc,CAAC;KACvB;IAED,yBAAyB;IACzB,MAAM,oBAAoB,GAAG,sPAAsP,CAAC;IACpR,IAAI,cAAc,CAAC,QAAQ,CAAC,oBAAoB,CAAC,EAAE;QACjD,OAAO,IAAA,mDAAwB,EAC7B,cAAc,EACd,oBAAoB,EACpB,sBAAsB,CACvB,CAAC;KACH;IAED,qCAAqC;IACrC,MAAM,oBAAoB,GAAG,2LAA2L,CAAC;IACzN,IAAI,cAAc,CAAC,QAAQ,CAAC,oBAAoB,CAAC,EAAE;QACjD,OAAO,IAAA,mDAAwB,EAC7B,cAAc,EACd,oBAAoB,EACpB,sBAAsB,CACvB,CAAC;KACH;IAED,oBAAoB;IACpB,MAAM,iCAAiC,GAAG,wDAAwD,CAAC;IACnG,IAAI,cAAc,CAAC,QAAQ,CAAC,iCAAiC,CAAC,EAAE;QAC9D,OAAO,IAAA,mDAAwB,EAC7B,cAAc,EACd,iCAAiC,EACjC,sBAAsB,CACvB,CAAC;KACH;IAED,oBAAoB;IACpB,MAAM,2BAA2B,GAAG,4DAA4D,CAAC;IACjG,IAAI,cAAc,CAAC,QAAQ,CAAC,2BAA2B,CAAC,EAAE;QACxD,OAAO,IAAA,mDAAwB,EAC7B,cAAc,EACd,2BAA2B,EAC3B,sBAAsB,CACvB,CAAC;KACH;IAED,MAAM,IAAI,KAAK,CACb,6EAA6E,CAC9E,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACI,MAAM,gCAAgC,GAEzC,CAAC,MAAM,EAAE,EAAE;IACb,OAAO,IAAA,mCAAkB,EAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,EAAE;QACrD,gBAAgB,CAAC,UAAU,CAAC,QAAQ,GAAG,mBAAmB,CACxD,gBAAgB,CAAC,UAAU,CAAC,QAAQ,CACrC,CAAC;QAEF,OAAO,gBAAgB,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAVW,QAAA,gCAAgC,oCAU3C"} \ No newline at end of file diff --git a/build/android/mainApplicationDependency.js b/build/android/mainApplicationDependency.js index d1f1867..cdd1686 100644 --- a/build/android/mainApplicationDependency.js +++ b/build/android/mainApplicationDependency.js @@ -11,6 +11,21 @@ const withAndroidMainApplicationDependency = (config) => { return (0, config_plugins_1.withMainApplication)(config, (mainApplicationProps) => { // Import the plugin class. mainApplicationProps.modResults.contents = (0, addBelowAnchorIfNotFound_1.addBelowAnchorIfNotFound)(mainApplicationProps.modResults.contents, "import expo.modules.ReactNativeHostWrapper;", "import com.microsoft.codepush.react.CodePush;"); + // The default on Expo 50, which uses kotlin + const kotlinAnchor = `override fun getJSMainModuleName(): String = ".expo/.virtual-metro-entry"`; + if (mainApplicationProps.modResults.contents.includes(kotlinAnchor)) { + /** + * Override the getJSBundleFile method in order to let + * the CodePush runtime determine where to get the JS + * bundle location from on each app start + */ + const kotlinJSBundleFileOverride = ` + override fun getJSBundleFile(): String? { + return CodePush.getJSBundleFile() + } + `; + mainApplicationProps.modResults.contents = (0, addBelowAnchorIfNotFound_1.addBelowAnchorIfNotFound)(mainApplicationProps.modResults.contents, kotlinAnchor, kotlinJSBundleFileOverride); + } /** * Override the getJSBundleFile method in order to let * the CodePush runtime determine where to get the JS @@ -21,14 +36,16 @@ const withAndroidMainApplicationDependency = (config) => { protected String getJSBundleFile() { return CodePush.getJSBundleFile(); }\n`; - // This seems to be the default on Expo 49 - if (mainApplicationProps.modResults.contents.includes("new DefaultReactNativeHost(this) {")) { - mainApplicationProps.modResults.contents = (0, addBelowAnchorIfNotFound_1.addBelowAnchorIfNotFound)(mainApplicationProps.modResults.contents, `new DefaultReactNativeHost(this) {`, getJSBundleFileOverride); + // The default on Expo 49 + const defaultReactNativeAnchor = "new DefaultReactNativeHost(this) {"; + if (mainApplicationProps.modResults.contents.includes(defaultReactNativeAnchor)) { + mainApplicationProps.modResults.contents = (0, addBelowAnchorIfNotFound_1.addBelowAnchorIfNotFound)(mainApplicationProps.modResults.contents, defaultReactNativeAnchor, getJSBundleFileOverride); return mainApplicationProps; } // This is for compatibility, as it follows the Codepush instructions up-to-spec. - if (mainApplicationProps.modResults.contents.includes("new ReactNativeHost(this) {")) { - mainApplicationProps.modResults.contents = (0, addBelowAnchorIfNotFound_1.addBelowAnchorIfNotFound)(mainApplicationProps.modResults.contents, `new ReactNativeHost(this) {`, getJSBundleFileOverride); + const reactNativeHostAnchor = "new ReactNativeHost(this) {"; + if (mainApplicationProps.modResults.contents.includes(reactNativeHostAnchor)) { + mainApplicationProps.modResults.contents = (0, addBelowAnchorIfNotFound_1.addBelowAnchorIfNotFound)(mainApplicationProps.modResults.contents, reactNativeHostAnchor, getJSBundleFileOverride); return mainApplicationProps; } throw new Error("Cannot find a suitable place to insert the CodePush getJSBundleFile code."); diff --git a/build/android/mainApplicationDependency.js.map b/build/android/mainApplicationDependency.js.map index b1b124c..0e2d7d1 100644 --- a/build/android/mainApplicationDependency.js.map +++ b/build/android/mainApplicationDependency.js.map @@ -1 +1 @@ -{"version":3,"file":"mainApplicationDependency.js","sourceRoot":"","sources":["../../src/android/mainApplicationDependency.ts"],"names":[],"mappings":";;;AAAA,wDAAwE;AAGxE,gFAA6E;AAE7E;;;GAGG;AACI,MAAM,oCAAoC,GAE7C,CAAC,MAAM,EAAE,EAAE;IACb,OAAO,IAAA,oCAAmB,EAAC,MAAM,EAAE,CAAC,oBAAoB,EAAE,EAAE;QAC1D,2BAA2B;QAC3B,oBAAoB,CAAC,UAAU,CAAC,QAAQ,GAAG,IAAA,mDAAwB,EACjE,oBAAoB,CAAC,UAAU,CAAC,QAAQ,EACxC,6CAA6C,EAC7C,+CAA+C,CAChD,CAAC;QAEF;;;;WAIG;QACH,MAAM,uBAAuB,GAAG;;;;UAI1B,CAAC;QAEP,0CAA0C;QAC1C,IACE,oBAAoB,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAC/C,oCAAoC,CACrC,EACD;YACA,oBAAoB,CAAC,UAAU,CAAC,QAAQ,GAAG,IAAA,mDAAwB,EACjE,oBAAoB,CAAC,UAAU,CAAC,QAAQ,EACxC,oCAAoC,EACpC,uBAAuB,CACxB,CAAC;YAEF,OAAO,oBAAoB,CAAC;SAC7B;QAED,iFAAiF;QACjF,IACE,oBAAoB,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAC/C,6BAA6B,CAC9B,EACD;YACA,oBAAoB,CAAC,UAAU,CAAC,QAAQ,GAAG,IAAA,mDAAwB,EACjE,oBAAoB,CAAC,UAAU,CAAC,QAAQ,EACxC,6BAA6B,EAC7B,uBAAuB,CACxB,CAAC;YAEF,OAAO,oBAAoB,CAAC;SAC7B;QAED,MAAM,IAAI,KAAK,CACb,2EAA2E,CAC5E,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAxDW,QAAA,oCAAoC,wCAwD/C"} \ No newline at end of file +{"version":3,"file":"mainApplicationDependency.js","sourceRoot":"","sources":["../../src/android/mainApplicationDependency.ts"],"names":[],"mappings":";;;AAAA,wDAAwE;AAGxE,gFAA6E;AAE7E;;;GAGG;AACI,MAAM,oCAAoC,GAE7C,CAAC,MAAM,EAAE,EAAE;IACb,OAAO,IAAA,oCA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,MAAM,IAAI,KAAK,CACb,2EAA2E,CAC5E,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AA5EW,QAAA,oCAAoC,wCA4E/C"} \ No newline at end of file diff --git a/src/android/buildscriptDependency.ts b/src/android/buildscriptDependency.ts index 20e7a1b..7903edb 100644 --- a/src/android/buildscriptDependency.ts +++ b/src/android/buildscriptDependency.ts @@ -12,6 +12,16 @@ function applyImplementation(appBuildGradle: string) { return appBuildGradle; } + // The default on Expo 50 + 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");`; + if (appBuildGradle.includes(reactNative73Include)) { + return addBelowAnchorIfNotFound( + appBuildGradle, + reactNative73Include, + codePushImplementation + ); + } + // Seems to be the default on Expo 49 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");`; if (appBuildGradle.includes(reactNative71Include)) { diff --git a/src/android/mainApplicationDependency.ts b/src/android/mainApplicationDependency.ts index 7594ced..c73c53f 100644 --- a/src/android/mainApplicationDependency.ts +++ b/src/android/mainApplicationDependency.ts @@ -18,6 +18,26 @@ export const withAndroidMainApplicationDependency: ConfigPlugin< "import com.microsoft.codepush.react.CodePush;" ); + // The default on Expo 50, which uses kotlin + const kotlinAnchor = `override fun getJSMainModuleName(): String = ".expo/.virtual-metro-entry"`; + if (mainApplicationProps.modResults.contents.includes(kotlinAnchor)) { + /** + * Override the getJSBundleFile method in order to let + * the CodePush runtime determine where to get the JS + * bundle location from on each app start + */ + const kotlinJSBundleFileOverride = ` + override fun getJSBundleFile(): String? { + return CodePush.getJSBundleFile() + } + `; + mainApplicationProps.modResults.contents = addBelowAnchorIfNotFound( + mainApplicationProps.modResults.contents, + kotlinAnchor, + kotlinJSBundleFileOverride + ); + } + /** * Override the getJSBundleFile method in order to let * the CodePush runtime determine where to get the JS @@ -29,15 +49,16 @@ export const withAndroidMainApplicationDependency: ConfigPlugin< return CodePush.getJSBundleFile(); }\n`; - // This seems to be the default on Expo 49 + // The default on Expo 49 + const defaultReactNativeAnchor = "new DefaultReactNativeHost(this) {"; if ( mainApplicationProps.modResults.contents.includes( - "new DefaultReactNativeHost(this) {" + defaultReactNativeAnchor ) ) { mainApplicationProps.modResults.contents = addBelowAnchorIfNotFound( mainApplicationProps.modResults.contents, - `new DefaultReactNativeHost(this) {`, + defaultReactNativeAnchor, getJSBundleFileOverride ); @@ -45,14 +66,13 @@ export const withAndroidMainApplicationDependency: ConfigPlugin< } // This is for compatibility, as it follows the Codepush instructions up-to-spec. + const reactNativeHostAnchor = "new ReactNativeHost(this) {"; if ( - mainApplicationProps.modResults.contents.includes( - "new ReactNativeHost(this) {" - ) + mainApplicationProps.modResults.contents.includes(reactNativeHostAnchor) ) { mainApplicationProps.modResults.contents = addBelowAnchorIfNotFound( mainApplicationProps.modResults.contents, - `new ReactNativeHost(this) {`, + reactNativeHostAnchor, getJSBundleFileOverride ); From f5e28ace8a9858fd612c00cfcbd94e4e6bbaf8cd Mon Sep 17 00:00:00 2001 From: Gabriel Taveira Date: Sat, 20 Jan 2024 11:25:40 -0300 Subject: [PATCH 2/6] chore: version bump --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2857e3..4a47aa6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,3 +5,7 @@ ### @config-plugins/react-native-codepush 1.0.2 - Update interim README + +### @config-plugins/react-native-codepush 1.0.4 + +- Expo SDK 50 support diff --git a/package.json b/package.json index 8d1404f..9a4a834 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-code-push-plugin", - "version": "1.0.3", + "version": "1.0.4", "description": "Config plugin to auto configure react-native-code-push on prebuild", "main": "build/index.js", "types": "build/index.d.ts", From 7513d160fbfab5c8e07ee180091e27370b62ad7c Mon Sep 17 00:00:00 2001 From: Gabriel Taveira Date: Sat, 20 Jan 2024 11:35:47 -0300 Subject: [PATCH 3/6] fix: kotlin support --- build/android/mainApplicationDependency.js | 33 ++++++------ .../android/mainApplicationDependency.js.map | 2 +- build/utils/addBelowAnchorIfNotFound.js | 3 ++ build/utils/addBelowAnchorIfNotFound.js.map | 2 +- src/android/mainApplicationDependency.ts | 50 ++++++++++++------- src/utils/addBelowAnchorIfNotFound.ts | 6 +++ 6 files changed, 62 insertions(+), 34 deletions(-) diff --git a/build/android/mainApplicationDependency.js b/build/android/mainApplicationDependency.js index cdd1686..b65941c 100644 --- a/build/android/mainApplicationDependency.js +++ b/build/android/mainApplicationDependency.js @@ -10,28 +10,33 @@ const addBelowAnchorIfNotFound_1 = require("../utils/addBelowAnchorIfNotFound"); const withAndroidMainApplicationDependency = (config) => { return (0, config_plugins_1.withMainApplication)(config, (mainApplicationProps) => { // Import the plugin class. - mainApplicationProps.modResults.contents = (0, addBelowAnchorIfNotFound_1.addBelowAnchorIfNotFound)(mainApplicationProps.modResults.contents, "import expo.modules.ReactNativeHostWrapper;", "import com.microsoft.codepush.react.CodePush;"); + const hostWrapperClass = "import expo.modules.ReactNativeHostWrapper"; + const codePushClass = "import com.microsoft.codepush.react.CodePush"; + // Expo 50 uses Kotlin and does not require the ; + if (mainApplicationProps.modResults.contents.includes(hostWrapperClass)) { + mainApplicationProps.modResults.contents = (0, addBelowAnchorIfNotFound_1.addBelowAnchorIfNotFound)(mainApplicationProps.modResults.contents, hostWrapperClass, codePushClass); + } + // Expo 49 uses Java and requires the ; + if (mainApplicationProps.modResults.contents.includes(`${hostWrapperClass};`)) { + mainApplicationProps.modResults.contents = (0, addBelowAnchorIfNotFound_1.addBelowAnchorIfNotFound)(mainApplicationProps.modResults.contents, `${hostWrapperClass};`, `${codePushClass};`); + } + /** + * Override the getJSBundleFile method in order to let + * the CodePush runtime determine where to get the JS + * bundle location from on each app start + */ // The default on Expo 50, which uses kotlin const kotlinAnchor = `override fun getJSMainModuleName(): String = ".expo/.virtual-metro-entry"`; if (mainApplicationProps.modResults.contents.includes(kotlinAnchor)) { - /** - * Override the getJSBundleFile method in order to let - * the CodePush runtime determine where to get the JS - * bundle location from on each app start - */ const kotlinJSBundleFileOverride = ` override fun getJSBundleFile(): String? { return CodePush.getJSBundleFile() } `; mainApplicationProps.modResults.contents = (0, addBelowAnchorIfNotFound_1.addBelowAnchorIfNotFound)(mainApplicationProps.modResults.contents, kotlinAnchor, kotlinJSBundleFileOverride); + return mainApplicationProps; } - /** - * Override the getJSBundleFile method in order to let - * the CodePush runtime determine where to get the JS - * bundle location from on each app start - */ - const getJSBundleFileOverride = ` + const javaJSBundleFileOverride = ` @Override protected String getJSBundleFile() { return CodePush.getJSBundleFile(); @@ -39,13 +44,13 @@ const withAndroidMainApplicationDependency = (config) => { // The default on Expo 49 const defaultReactNativeAnchor = "new DefaultReactNativeHost(this) {"; if (mainApplicationProps.modResults.contents.includes(defaultReactNativeAnchor)) { - mainApplicationProps.modResults.contents = (0, addBelowAnchorIfNotFound_1.addBelowAnchorIfNotFound)(mainApplicationProps.modResults.contents, defaultReactNativeAnchor, getJSBundleFileOverride); + mainApplicationProps.modResults.contents = (0, addBelowAnchorIfNotFound_1.addBelowAnchorIfNotFound)(mainApplicationProps.modResults.contents, defaultReactNativeAnchor, javaJSBundleFileOverride); return mainApplicationProps; } // This is for compatibility, as it follows the Codepush instructions up-to-spec. const reactNativeHostAnchor = "new ReactNativeHost(this) {"; if (mainApplicationProps.modResults.contents.includes(reactNativeHostAnchor)) { - mainApplicationProps.modResults.contents = (0, addBelowAnchorIfNotFound_1.addBelowAnchorIfNotFound)(mainApplicationProps.modResults.contents, reactNativeHostAnchor, getJSBundleFileOverride); + mainApplicationProps.modResults.contents = (0, addBelowAnchorIfNotFound_1.addBelowAnchorIfNotFound)(mainApplicationProps.modResults.contents, reactNativeHostAnchor, javaJSBundleFileOverride); return mainApplicationProps; } throw new Error("Cannot find a suitable place to insert the CodePush getJSBundleFile code."); diff --git a/build/android/mainApplicationDependency.js.map b/build/android/mainApplicationDependency.js.map index 0e2d7d1..ea2504c 100644 --- a/build/android/mainApplicationDependency.js.map +++ b/build/android/mainApplicationDependency.js.map @@ -1 +1 @@ -{"version":3,"file":"mainApplicationDependency.js","sourceRoot":"","sources":["../../src/android/mainApplicationDependency.ts"],"names":[],"mappings":";;;AAAA,wDAAwE;AAGxE,gFAA6E;AAE7E;;;GAGG;AACI,MAAM,oCAAoC,GAE7C,CAAC,MAAM,EAAE,EAAE;IACb,OAAO,IAAA,oCAAmB,EAAC,MAAM,EAAE,CAAC,oBAAoB,EAAE,EAAE;QAC1D,2BAA2B;QAC3B,oBAAoB,CAAC,UAAU,CAAC,QAAQ,GAAG,IAAA,mDAAwB,EACjE,oBAAoB,CAAC,UAAU,CAAC,QAAQ,EACxC,6CAA6C,EAC7C,+CAA+C,CAChD,CAAC;QAEF,4CAA4C;QAC5C,MAAM,YAAY,GAAG,2EAA2E,CAAC;QACjG,IAAI,oBAAoB,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE;YACnE;;;;eAIG;YACH,MAAM,0BAA0B,GAAG;;;;OAIlC,CAAC;YACF,oBAAoB,CAAC,UAAU,CAAC,QAAQ,GAAG,IAAA,mDAAwB,EACjE,oBAAoB,CAAC,UAAU,CAAC,QAAQ,EACxC,YAAY,EACZ,0BAA0B,CAC3B,CAAC;SACH;QAED;;;;WAIG;QACH,MAAM,uBAAuB,GAAG;;;;UAI1B,CAAC;QAEP,yBAAyB;QACzB,MAAM,wBAAwB,GAAG,oCAAoC,CAAC;QACtE,IACE,oBAAoB,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAC/C,wBAAwB,CACzB,EACD;YACA,oBAAoB,CAAC,UAAU,CAAC,QAAQ,GAAG,IAAA,mDAAwB,EACjE,oBAAoB,CAAC,UAAU,CAAC,QAAQ,EACxC,wBAAwB,EACxB,uBAAuB,CACxB,CAAC;YAEF,OAAO,oBAAoB,CAAC;SAC7B;QAED,iFAAiF;QACjF,MAAM,qBAAqB,GAAG,6BAA6B,CAAC;QAC5D,IACE,oBAAoB,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,qBAAqB,CAAC,EACxE;YACA,oBAAoB,CAAC,UAAU,CAAC,QAAQ,GAAG,IAAA,mDAAwB,EACjE,oBAAoB,CAAC,UAAU,CAAC,QAAQ,EACxC,qBAAqB,EACrB,uBAAuB,CACxB,CAAC;YAEF,OAAO,oBAAoB,CAAC;SAC7B;QAED,MAAM,IAAI,KAAK,CACb,2EAA2E,CAC5E,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AA5EW,QAAA,oCAAoC,wCA4E/C"} \ No newline at end of file +{"version":3,"file":"mainApplicationDependency.js","sourceRoot":"","sources":["../../src/android/mainApplicationDependency.ts"],"names":[],"mappings":";;;AAAA,wDAAwE;AAGxE,gFAA6E;AAE7E;;;GAGG;AACI,MAAM,oCAAoC,GAE7C,CAAC,MAAM,EAAE,EAAE;IACb,OAAO,IAAA,oCAAmB,EAAC,MAAM,EAAE,CAAC,oBAAoB,EAAE,EAAE;QAC1D,2BAA2B;QAC3B,MAAM,gBAAgB,GAAG,4CAA4C,CAAC;QACtE,MAAM,aAAa,GAAG,8CAA8C,CAAC;QAErE,iDAAiD;QACjD,IAAI,oBAAoB,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAE;YACvE,oBAAoB,CAAC,UAAU,CAAC,QAAQ,GAAG,IAAA,mDAAwB,EACjE,oBAAoB,CAAC,UAAU,CAAC,QAAQ,EACxC,gBAAgB,EAChB,aAAa,CACd,CAAC;SACH;QAED,uCAAuC;QACvC,IACE,oBAAoB,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,gBAAgB,GAAG,CAAC,EACzE;YACA,oBAAoB,CAA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IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AA1FW,QAAA,oCAAoC,wCA0F/C"} \ No newline at end of file diff --git a/build/utils/addBelowAnchorIfNotFound.js b/build/utils/addBelowAnchorIfNotFound.js index 9982ac9..7f4c327 100644 --- a/build/utils/addBelowAnchorIfNotFound.js +++ b/build/utils/addBelowAnchorIfNotFound.js @@ -6,6 +6,9 @@ function addBelowAnchorIfNotFound(originalString, anchor, stringToBeAdded) { if (!originalString.includes(stringToBeAdded)) { return originalString.replace(anchor, `${anchor}\n${stringToBeAdded}`); } + if (!originalString.includes(anchor)) { + throw new Error(`The anchor string "${anchor}" was not found in the original string.`); + } return originalString; } exports.addBelowAnchorIfNotFound = addBelowAnchorIfNotFound; diff --git a/build/utils/addBelowAnchorIfNotFound.js.map b/build/utils/addBelowAnchorIfNotFound.js.map index ace7efb..c4e6c76 100644 --- a/build/utils/addBelowAnchorIfNotFound.js.map +++ b/build/utils/addBelowAnchorIfNotFound.js.map @@ -1 +1 @@ -{"version":3,"file":"addBelowAnchorIfNotFound.js","sourceRoot":"","sources":["../../src/utils/addBelowAnchorIfNotFound.ts"],"names":[],"mappings":";;;AAAA,SAAgB,wBAAwB,CACtC,cAAsB,EACtB,MAAc,EACd,eAAuB;IAEvB,yDAAyD;IACzD,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE;QAC7C,OAAO,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,MAAM,KAAK,eAAe,EAAE,CAAC,CAAC;KACxE;IAED,OAAO,cAAc,CAAC;AACxB,CAAC;AAXD,4DAWC"} \ No newline at end of file +{"version":3,"file":"addBelowAnchorIfNotFound.js","sourceRoot":"","sources":["../../src/utils/addBelowAnchorIfNotFound.ts"],"names":[],"mappings":";;;AAAA,SAAgB,wBAAwB,CACtC,cAAsB,EACtB,MAAc,EACd,eAAuB;IAEvB,yDAAyD;IACzD,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE;QAC7C,OAAO,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,MAAM,KAAK,eAAe,EAAE,CAAC,CAAC;KACxE;IAED,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QACpC,MAAM,IAAI,KAAK,CACb,sBAAsB,MAAM,yCAAyC,CACtE,CAAC;KACH;IAED,OAAO,cAAc,CAAC;AACxB,CAAC;AAjBD,4DAiBC"} \ No newline at end of file diff --git a/src/android/mainApplicationDependency.ts b/src/android/mainApplicationDependency.ts index c73c53f..da3d60b 100644 --- a/src/android/mainApplicationDependency.ts +++ b/src/android/mainApplicationDependency.ts @@ -12,20 +12,38 @@ export const withAndroidMainApplicationDependency: ConfigPlugin< > = (config) => { return withMainApplication(config, (mainApplicationProps) => { // Import the plugin class. - mainApplicationProps.modResults.contents = addBelowAnchorIfNotFound( - mainApplicationProps.modResults.contents, - "import expo.modules.ReactNativeHostWrapper;", - "import com.microsoft.codepush.react.CodePush;" - ); + const hostWrapperClass = "import expo.modules.ReactNativeHostWrapper"; + const codePushClass = "import com.microsoft.codepush.react.CodePush"; + + // Expo 50 uses Kotlin and does not require the ; + if (mainApplicationProps.modResults.contents.includes(hostWrapperClass)) { + mainApplicationProps.modResults.contents = addBelowAnchorIfNotFound( + mainApplicationProps.modResults.contents, + hostWrapperClass, + codePushClass + ); + } + + // Expo 49 uses Java and requires the ; + if ( + mainApplicationProps.modResults.contents.includes(`${hostWrapperClass};`) + ) { + mainApplicationProps.modResults.contents = addBelowAnchorIfNotFound( + mainApplicationProps.modResults.contents, + `${hostWrapperClass};`, + `${codePushClass};` + ); + } + + /** + * Override the getJSBundleFile method in order to let + * the CodePush runtime determine where to get the JS + * bundle location from on each app start + */ // The default on Expo 50, which uses kotlin const kotlinAnchor = `override fun getJSMainModuleName(): String = ".expo/.virtual-metro-entry"`; if (mainApplicationProps.modResults.contents.includes(kotlinAnchor)) { - /** - * Override the getJSBundleFile method in order to let - * the CodePush runtime determine where to get the JS - * bundle location from on each app start - */ const kotlinJSBundleFileOverride = ` override fun getJSBundleFile(): String? { return CodePush.getJSBundleFile() @@ -36,14 +54,10 @@ export const withAndroidMainApplicationDependency: ConfigPlugin< kotlinAnchor, kotlinJSBundleFileOverride ); + return mainApplicationProps; } - /** - * Override the getJSBundleFile method in order to let - * the CodePush runtime determine where to get the JS - * bundle location from on each app start - */ - const getJSBundleFileOverride = ` + const javaJSBundleFileOverride = ` @Override protected String getJSBundleFile() { return CodePush.getJSBundleFile(); @@ -59,7 +73,7 @@ export const withAndroidMainApplicationDependency: ConfigPlugin< mainApplicationProps.modResults.contents = addBelowAnchorIfNotFound( mainApplicationProps.modResults.contents, defaultReactNativeAnchor, - getJSBundleFileOverride + javaJSBundleFileOverride ); return mainApplicationProps; @@ -73,7 +87,7 @@ export const withAndroidMainApplicationDependency: ConfigPlugin< mainApplicationProps.modResults.contents = addBelowAnchorIfNotFound( mainApplicationProps.modResults.contents, reactNativeHostAnchor, - getJSBundleFileOverride + javaJSBundleFileOverride ); return mainApplicationProps; diff --git a/src/utils/addBelowAnchorIfNotFound.ts b/src/utils/addBelowAnchorIfNotFound.ts index 3e5a247..22a916f 100644 --- a/src/utils/addBelowAnchorIfNotFound.ts +++ b/src/utils/addBelowAnchorIfNotFound.ts @@ -8,5 +8,11 @@ export function addBelowAnchorIfNotFound( return originalString.replace(anchor, `${anchor}\n${stringToBeAdded}`); } + if (!originalString.includes(anchor)) { + throw new Error( + `The anchor string "${anchor}" was not found in the original string.` + ); + } + return originalString; } From 72d8a3cfb589359ea873e01bb5282a93f8a85e1e Mon Sep 17 00:00:00 2001 From: Gabriel Taveira Date: Sat, 20 Jan 2024 11:39:32 -0300 Subject: [PATCH 4/6] docs: change changelog --- CHANGELOG.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a47aa6..8987719 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,6 @@ - Update interim README -### @config-plugins/react-native-codepush 1.0.4 +### @config-plugins/react-native-codepush 1.0.5 - Expo SDK 50 support diff --git a/package.json b/package.json index 9a4a834..5be6756 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-code-push-plugin", - "version": "1.0.4", + "version": "1.0.5", "description": "Config plugin to auto configure react-native-code-push on prebuild", "main": "build/index.js", "types": "build/index.d.ts", From b65b4c4571befbef54ec33d7a55dcb5c9395681f Mon Sep 17 00:00:00 2001 From: Gabriel Taveira Date: Sat, 20 Jan 2024 11:42:11 -0300 Subject: [PATCH 5/6] chore: move code a bit --- build/android/mainApplicationDependency.js | 6 +++--- src/android/mainApplicationDependency.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build/android/mainApplicationDependency.js b/build/android/mainApplicationDependency.js index b65941c..e03f341 100644 --- a/build/android/mainApplicationDependency.js +++ b/build/android/mainApplicationDependency.js @@ -29,9 +29,9 @@ const withAndroidMainApplicationDependency = (config) => { const kotlinAnchor = `override fun getJSMainModuleName(): String = ".expo/.virtual-metro-entry"`; if (mainApplicationProps.modResults.contents.includes(kotlinAnchor)) { const kotlinJSBundleFileOverride = ` - override fun getJSBundleFile(): String? { - return CodePush.getJSBundleFile() - } + override fun getJSBundleFile(): String? { + return CodePush.getJSBundleFile() + } `; mainApplicationProps.modResults.contents = (0, addBelowAnchorIfNotFound_1.addBelowAnchorIfNotFound)(mainApplicationProps.modResults.contents, kotlinAnchor, kotlinJSBundleFileOverride); return mainApplicationProps; diff --git a/src/android/mainApplicationDependency.ts b/src/android/mainApplicationDependency.ts index da3d60b..6acb7de 100644 --- a/src/android/mainApplicationDependency.ts +++ b/src/android/mainApplicationDependency.ts @@ -45,9 +45,9 @@ export const withAndroidMainApplicationDependency: ConfigPlugin< const kotlinAnchor = `override fun getJSMainModuleName(): String = ".expo/.virtual-metro-entry"`; if (mainApplicationProps.modResults.contents.includes(kotlinAnchor)) { const kotlinJSBundleFileOverride = ` - override fun getJSBundleFile(): String? { - return CodePush.getJSBundleFile() - } + override fun getJSBundleFile(): String? { + return CodePush.getJSBundleFile() + } `; mainApplicationProps.modResults.contents = addBelowAnchorIfNotFound( mainApplicationProps.modResults.contents, From 8fc804670a5fe7466880d81cb00a47baccccb72a Mon Sep 17 00:00:00 2001 From: MGS Creativa Date: Mon, 22 Jan 2024 10:07:00 -0300 Subject: [PATCH 6/6] Update dependencies --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5be6756..db200c1 100644 --- a/package.json +++ b/package.json @@ -29,10 +29,10 @@ "expo" ], "peerDependencies": { - "expo": "^49" + "expo": ">=49.0.0" }, "devDependencies": { - "expo": "^49", + "expo": ">=49.0.0", "expo-module-scripts": "^3.0.3" }, "upstreamPackage": "react-native-code-push"