From babcfbca6b952fb19427b2ce55d6a0a77b6ad056 Mon Sep 17 00:00:00 2001 From: Ben Boral Date: Thu, 26 Mar 2026 11:53:40 -0500 Subject: [PATCH 1/3] change insert location for new architecture (android) --- expo.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/expo.js b/expo.js index c27719a48..e744a82ca 100644 --- a/expo.js +++ b/expo.js @@ -198,13 +198,24 @@ const withAndroidMainApplication = (config) => { override fun getJSBundleFile(): String { return CodePush.getJSBundleFile() }`; - const hermesEnabledAnchor = /(override\s+val\s+isHermesEnabled:\s*Boolean\s*=\s*BuildConfig\.IS_HERMES_ENABLED)\s*\n/m; if (!content.includes("override fun getJSBundleFile(): String")) { + const hermesEnabledAnchor = /(override\s+val\s+isHermesEnabled:\s*Boolean\s*=\s*BuildConfig\.IS_HERMES_ENABLED)\s*\n/m; if (hermesEnabledAnchor.test(content)) { + // RN < 0.83: anchor after isHermesEnabled content = content.replace(hermesEnabledAnchor, `$1\n${getJSBundleFileMethodString}\n`); + } else if (content.includes('override fun onCreate()')) { + // RN 0.83+: isHermesEnabled was removed, insert before onCreate() + content = content.replace( + 'override fun onCreate()', + `${getJSBundleFileMethodString}\n\n override fun onCreate()` + ); } else { - WarningAggregator.addWarningAndroid('codepush-plugin', 'Could not find `isHermesEnabled` property to anchor `getJSBundleFile()` insertion. Please review `MainApplication.kt`.'); + // Fallback: insert inside the class body + content = content.replace( + /(class MainApplication[^{]*\{)/, + `$1\n${getJSBundleFileMethodString}` + ); } } From dcd648b605050dad3a170b00bcdbcf210a627f9e Mon Sep 17 00:00:00 2001 From: Ben Boral Date: Thu, 26 Mar 2026 12:32:02 -0500 Subject: [PATCH 2/3] new anchor point --- expo.js | 54 +++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/expo.js b/expo.js index e744a82ca..1b00a1842 100644 --- a/expo.js +++ b/expo.js @@ -193,32 +193,36 @@ const withAndroidMainApplication = (config) => { } } - // --- 4. Add getJSBundleFile method --- - const getJSBundleFileMethodString = ` - override fun getJSBundleFile(): String { - return CodePush.getJSBundleFile() - }`; - - if (!content.includes("override fun getJSBundleFile(): String")) { - const hermesEnabledAnchor = /(override\s+val\s+isHermesEnabled:\s*Boolean\s*=\s*BuildConfig\.IS_HERMES_ENABLED)\s*\n/m; - if (hermesEnabledAnchor.test(content)) { - // RN < 0.83: anchor after isHermesEnabled - content = content.replace(hermesEnabledAnchor, `$1\n${getJSBundleFileMethodString}\n`); - } else if (content.includes('override fun onCreate()')) { - // RN 0.83+: isHermesEnabled was removed, insert before onCreate() - content = content.replace( - 'override fun onCreate()', - `${getJSBundleFileMethodString}\n\n override fun onCreate()` - ); - } else { - // Fallback: insert inside the class body - content = content.replace( - /(class MainApplication[^{]*\{)/, - `$1\n${getJSBundleFileMethodString}` - ); + // --- 4. Wire up CodePush bundle file --- + if (!content.includes("CodePush.getJSBundleFile()")) { + const hermesEnabledAnchor = /(override\s+val\s+isHermesEnabled:\s*Boolean\s*=\s*BuildConfig\.IS_HERMES_ENABLED)\s*\n/m; + if (hermesEnabledAnchor.test(content)) { + // RN < 0.83: uses ReactNativeHost with getJSBundleFile() override + const getJSBundleFileMethodString = ` + override fun getJSBundleFile(): String { + return CodePush.getJSBundleFile() + }`; + content = content.replace(hermesEnabledAnchor, `$1\n${getJSBundleFileMethodString}\n`); + } else { + // RN 0.83+: uses ReactHost via getDefaultReactHost() — pass jsBundleFilePath parameter + // Match the closing parenthesis of the getDefaultReactHost() call + const reactHostCallRegex = /(getDefaultReactHost\([\s\S]*?packageList\s*=[\s\S]*?\})([\s\S]*?\))/m; + if (reactHostCallRegex.test(content)) { + content = content.replace(reactHostCallRegex, (match, beforeClose, closing) => { + // Check if jsBundleFilePath is already set + if (match.includes('jsBundleFilePath')) return match; + // Insert the parameter before the closing parentheses + return `${beforeClose},\n jsBundleFilePath = CodePush.getJSBundleFile()${closing}`; + }); + } else { + WarningAggregator.addWarningAndroid( + 'codepush-plugin', + 'Could not find getDefaultReactHost() call in MainApplication. CodePush bundle file path not configured.' + ); + } + } } - } - + modConfig.modResults.contents = content; return modConfig; }); From 8c1d25bef91a1e5b2d2e3160814dc669fb921386 Mon Sep 17 00:00:00 2001 From: Ben Boral Date: Thu, 26 Mar 2026 13:15:52 -0500 Subject: [PATCH 3/3] 82 not 83 --- expo.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/expo.js b/expo.js index 1b00a1842..c0a4783df 100644 --- a/expo.js +++ b/expo.js @@ -197,14 +197,14 @@ const withAndroidMainApplication = (config) => { if (!content.includes("CodePush.getJSBundleFile()")) { const hermesEnabledAnchor = /(override\s+val\s+isHermesEnabled:\s*Boolean\s*=\s*BuildConfig\.IS_HERMES_ENABLED)\s*\n/m; if (hermesEnabledAnchor.test(content)) { - // RN < 0.83: uses ReactNativeHost with getJSBundleFile() override + // RN < 0.82: uses ReactNativeHost with getJSBundleFile() override const getJSBundleFileMethodString = ` override fun getJSBundleFile(): String { return CodePush.getJSBundleFile() }`; content = content.replace(hermesEnabledAnchor, `$1\n${getJSBundleFileMethodString}\n`); } else { - // RN 0.83+: uses ReactHost via getDefaultReactHost() — pass jsBundleFilePath parameter + // RN 0.82+: uses ReactHost via getDefaultReactHost() — pass jsBundleFilePath parameter // Match the closing parenthesis of the getDefaultReactHost() call const reactHostCallRegex = /(getDefaultReactHost\([\s\S]*?packageList\s*=[\s\S]*?\})([\s\S]*?\))/m; if (reactHostCallRegex.test(content)) {