From 11e24e1df22ad30db9c7aca651f6a2d4b555cb1b Mon Sep 17 00:00:00 2001 From: Hossein Mohammadi Date: Wed, 5 Feb 2025 20:01:15 +0330 Subject: [PATCH 1/4] fix: download,write then run instead of download, write, read, run use the bundle we have instead of read it from file --- .../com/callstack/repack/RemoteScriptLoader.kt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/repack/android/src/main/java/com/callstack/repack/RemoteScriptLoader.kt b/packages/repack/android/src/main/java/com/callstack/repack/RemoteScriptLoader.kt index 775aeccbe..c6c35ec12 100644 --- a/packages/repack/android/src/main/java/com/callstack/repack/RemoteScriptLoader.kt +++ b/packages/repack/android/src/main/java/com/callstack/repack/RemoteScriptLoader.kt @@ -29,7 +29,7 @@ class RemoteScriptLoader(val reactContext: ReactContext, private val nativeLoade return clientPerRequestBuilder.build() } - private fun downloadAndCache(config: ScriptConfig, onSuccess: () -> Unit, onError: (code: String, message: String) -> Unit) { + private fun downloadAndCache(config: ScriptConfig, onSuccess: (bundle: ByteArray) -> Unit, onError: (code: String, message: String) -> Unit) { val path = getScriptFilePath(config.uniqueId) val file = File(reactContext.filesDir, path) @@ -59,13 +59,20 @@ class RemoteScriptLoader(val reactContext: ReactContext, private val nativeLoade CodeSigningUtils.verifyBundle(reactContext, token, bundle) } + if (bundle == null) { + throw Exception("Request should have returned with a valid bundle") + } else if (bundle.isEmpty()) { + throw Exception("Request returned an empty bundle") + } + + file.createNewFile() val outputStream = file.outputStream() val writer = BufferedOutputStream(outputStream) writer.write(bundle) writer.close() - onSuccess() + onSuccess(bundle) } catch (error: Exception) { onError( ScriptLoadingError.ScriptCachingFailure.code, @@ -122,8 +129,8 @@ class RemoteScriptLoader(val reactContext: ReactContext, private val nativeLoade } fun load(config: ScriptConfig, promise: Promise) { - downloadAndCache(config, { - execute(config, promise) + downloadAndCache(config, { bundle: ByteArray -> + nativeLoader.evaluate(bundle, config.sourceUrl, promise) }, { code, message -> promise.reject(code, message) }) } From 0c356519a79e4ac4af76f1b64012b902460c080e Mon Sep 17 00:00:00 2001 From: Hossein Mohammadi Date: Wed, 5 Feb 2025 20:03:46 +0330 Subject: [PATCH 2/4] chore: change set --- .changeset/tough-seas-hide.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tough-seas-hide.md diff --git a/.changeset/tough-seas-hide.md b/.changeset/tough-seas-hide.md new file mode 100644 index 000000000..ff4e660e9 --- /dev/null +++ b/.changeset/tough-seas-hide.md @@ -0,0 +1,5 @@ +--- +"@callstack/repack": patch +--- + +fix: download,write then run instead of download, write, read, run From 05648ea3a40067ba800c5e384ad32927b04f0114 Mon Sep 17 00:00:00 2001 From: Hossein Mohammadi Date: Wed, 5 Feb 2025 20:09:58 +0330 Subject: [PATCH 3/4] chore: update changes set --- .changeset/tough-seas-hide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/tough-seas-hide.md b/.changeset/tough-seas-hide.md index ff4e660e9..00b06ec70 100644 --- a/.changeset/tough-seas-hide.md +++ b/.changeset/tough-seas-hide.md @@ -2,4 +2,4 @@ "@callstack/repack": patch --- -fix: download,write then run instead of download, write, read, run +fix: download, write, run instead of download, write, read, run From f4a485cde6849bdc8e099ee8fe5066bcae80d923 Mon Sep 17 00:00:00 2001 From: Hossein Mohammadi Date: Thu, 6 Feb 2025 22:32:33 +0330 Subject: [PATCH 4/4] fic: handle exception --- .../main/java/com/callstack/repack/RemoteScriptLoader.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/repack/android/src/main/java/com/callstack/repack/RemoteScriptLoader.kt b/packages/repack/android/src/main/java/com/callstack/repack/RemoteScriptLoader.kt index c6c35ec12..c1c11fe79 100644 --- a/packages/repack/android/src/main/java/com/callstack/repack/RemoteScriptLoader.kt +++ b/packages/repack/android/src/main/java/com/callstack/repack/RemoteScriptLoader.kt @@ -130,7 +130,14 @@ class RemoteScriptLoader(val reactContext: ReactContext, private val nativeLoade fun load(config: ScriptConfig, promise: Promise) { downloadAndCache(config, { bundle: ByteArray -> - nativeLoader.evaluate(bundle, config.sourceUrl, promise) + try { + nativeLoader.evaluate(bundle, config.sourceUrl, promise) + } catch (error: Exception) { + promise.reject( + ScriptLoadingError.ScriptEvalFailure.code, + error.message ?: error.toString() + ) + } }, { code, message -> promise.reject(code, message) }) }