react-native-bspatch 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-bspatch",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Premium OTA Update Solution for React Native using TurboModules and bsdiff",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "module": "lib/module/index.js",
@@ -254,7 +254,6 @@ fi
254
254
 
255
255
  # ── Reset ─────────────────────────────────────────────────────────────────────
256
256
  if [ "$ACTION" = "reset" ]; then
257
- FLAVOR_LOWER=$(echo "$FLAVOR" | tr '[:upper:]' '[:lower:]')
258
257
  echo "Resetting OTA registry and output for flavor '$FLAVOR_LOWER'..."
259
258
 
260
259
  # Reset only the specific flavor in registry JSON if registry exists
@@ -523,4 +522,3 @@ echo "=== All Builds Complete ==="
523
522
 
524
523
 
525
524
 
526
-
@@ -85,6 +85,22 @@ const IOS_BUNDLE_URL_OVERRIDE = `
85
85
  const ANDROID_IMPORT = 'import vn.reactnativebspatch.OtaBundleResolver';
86
86
  const ANDROID_JS_BUNDLE = 'jsBundleFilePath = OtaBundleResolver.resolve(applicationContext)';
87
87
 
88
+ function findClosingParen(source, openParenIdx) {
89
+ let depth = 0;
90
+ for (let i = openParenIdx; i < source.length; i += 1) {
91
+ const char = source[i];
92
+ if (char === '(') {
93
+ depth += 1;
94
+ } else if (char === ')') {
95
+ depth -= 1;
96
+ if (depth === 0) {
97
+ return i;
98
+ }
99
+ }
100
+ }
101
+ return -1;
102
+ }
103
+
88
104
  // ── iOS: project.pbxproj ─────────────────────────────────────────────────────
89
105
 
90
106
  function patchPbxproj(content) {
@@ -172,18 +188,35 @@ function patchMainApplication(content) {
172
188
 
173
189
  // 2. Add jsBundleFilePath if missing
174
190
  if (!result.includes('OtaBundleResolver.resolve')) {
175
- // Find getDefaultReactHost(... call and inject jsBundleFilePath param
176
- // Look for closing paren of getDefaultReactHost block
177
- const hostCallRegex = /getDefaultReactHost\s*\(\s*([\s\S]*?)\)/m;
178
- const hostMatch = result.match(hostCallRegex);
179
- if (hostMatch) {
180
- // Insert before the closing paren
181
- const closeIdx = hostMatch.index + hostMatch[0].length - 1;
182
- result =
183
- result.slice(0, closeIdx) +
184
- ',\n ' + ANDROID_JS_BUNDLE + '\n ' +
185
- result.slice(closeIdx);
186
- changed = true;
191
+ const hostCallMatch = result.match(/getDefaultReactHost\s*\(/);
192
+ if (hostCallMatch && hostCallMatch.index !== undefined) {
193
+ const hostCallStart = hostCallMatch.index;
194
+ const openParenIdx = result.indexOf('(', hostCallStart);
195
+ const closeIdx =
196
+ openParenIdx === -1
197
+ ? -1
198
+ : findClosingParen(result, openParenIdx);
199
+
200
+ if (closeIdx === -1) {
201
+ console.log(' ⚠ Could not find the closing parenthesis for getDefaultReactHost(...). Please add jsBundleFilePath manually.');
202
+ } else {
203
+ const trailingWhitespaceMatch = result
204
+ .slice(0, closeIdx)
205
+ .match(/\s*$/);
206
+ const trailingWhitespace =
207
+ trailingWhitespaceMatch?.[0] ?? '';
208
+ const insertIdx = closeIdx - trailingWhitespace.length;
209
+ const beforeClose = result.slice(0, insertIdx).trimEnd();
210
+ const separator = beforeClose.endsWith(',') ? '\n' : ',\n';
211
+ result =
212
+ result.slice(0, insertIdx) +
213
+ separator +
214
+ ' ' +
215
+ ANDROID_JS_BUNDLE +
216
+ trailingWhitespace +
217
+ result.slice(closeIdx);
218
+ changed = true;
219
+ }
187
220
  } else {
188
221
  console.log(' ⚠ Could not find getDefaultReactHost(...) call. Please add jsBundleFilePath manually.');
189
222
  }
@@ -107,6 +107,15 @@ if [[ "$BASE_URL" == *"github"* ]] || [[ "$BASE_URL" == *"raw.githubusercontent"
107
107
  for FILE in "$OUTPUT_DIR"/*_${CHANNEL}.json "$OUTPUT_DIR"/*_${CHANNEL}.hbc "$OUTPUT_DIR"/*_${CHANNEL}_*.patch "$OUTPUT_DIR"/*_${CHANNEL}.patch; do
108
108
  [[ -f "$FILE" ]] || continue
109
109
  FNAME=$(basename "$FILE")
110
+ if [[ "$FNAME" == "patch_"* ]] || [[ "$FNAME" == "bundle_"* ]]; then
111
+ if [[ "$FNAME" != *"_${APP_VERSION}_"* ]]; then
112
+ continue
113
+ fi
114
+ fi
115
+
116
+ if [[ "$FNAME" != *"_${APP_VERSION}_"* ]] && [[ "$FNAME" != *"_${CHANNEL}_"* ]] && [[ "$FNAME" != "asset-manifest"* ]] && [[ "$FNAME" != "base-assets"* ]]; then
117
+ continue
118
+ fi
110
119
  cp "$FILE" "$TARGET_RELEASE_DIR/$FNAME"
111
120
  done
112
121