@hot-updater/react-native 0.29.3 → 0.29.5

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.
Files changed (47) hide show
  1. package/android/src/oldarch/HotUpdaterModule.kt +12 -4
  2. package/android/src/oldarch/HotUpdaterSpec.kt +3 -5
  3. package/ios/HotUpdater/Internal/HotUpdater-Bridging-Header.h +0 -1
  4. package/ios/HotUpdater/Internal/ZipArchiveExtractor.swift +30 -10
  5. package/lib/commonjs/DefaultResolver.js.map +1 -1
  6. package/lib/commonjs/checkForUpdate.js.map +1 -1
  7. package/lib/commonjs/index.js +0 -7
  8. package/lib/commonjs/index.js.map +1 -1
  9. package/lib/commonjs/native.js.map +1 -1
  10. package/lib/commonjs/native.spec.js.map +1 -1
  11. package/lib/commonjs/store.js.map +1 -1
  12. package/lib/commonjs/types.js.map +1 -1
  13. package/lib/commonjs/wrap.js.map +1 -1
  14. package/lib/module/DefaultResolver.js.map +1 -1
  15. package/lib/module/checkForUpdate.js.map +1 -1
  16. package/lib/module/index.js +0 -7
  17. package/lib/module/index.js.map +1 -1
  18. package/lib/module/native.js.map +1 -1
  19. package/lib/module/native.spec.js.map +1 -1
  20. package/lib/module/store.js.map +1 -1
  21. package/lib/module/types.js.map +1 -1
  22. package/lib/module/wrap.js.map +1 -1
  23. package/lib/typescript/commonjs/DefaultResolver.d.ts.map +1 -1
  24. package/lib/typescript/commonjs/checkForUpdate.d.ts.map +1 -1
  25. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  26. package/lib/typescript/commonjs/native.d.ts.map +1 -1
  27. package/lib/typescript/commonjs/store.d.ts.map +1 -1
  28. package/lib/typescript/commonjs/types.d.ts.map +1 -1
  29. package/lib/typescript/commonjs/wrap.d.ts.map +1 -1
  30. package/lib/typescript/module/DefaultResolver.d.ts.map +1 -1
  31. package/lib/typescript/module/checkForUpdate.d.ts.map +1 -1
  32. package/lib/typescript/module/index.d.ts.map +1 -1
  33. package/lib/typescript/module/native.d.ts.map +1 -1
  34. package/lib/typescript/module/store.d.ts.map +1 -1
  35. package/lib/typescript/module/types.d.ts.map +1 -1
  36. package/lib/typescript/module/wrap.d.ts.map +1 -1
  37. package/package.json +9 -9
  38. package/plugin/build/transformers.js +83 -97
  39. package/plugin/build/withHotUpdater.js +159 -239
  40. package/src/DefaultResolver.ts +1 -0
  41. package/src/checkForUpdate.ts +1 -0
  42. package/src/index.ts +0 -7
  43. package/src/native.spec.ts +4 -6
  44. package/src/native.ts +1 -0
  45. package/src/store.ts +1 -0
  46. package/src/types.ts +1 -0
  47. package/src/wrap.tsx +1 -0
@@ -3,22 +3,13 @@
3
3
  * Pure transformation functions for HotUpdater code injection
4
4
  * These utilities handle code transformations for different React Native patterns
5
5
  */
6
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
7
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
8
- if (ar || !(i in from)) {
9
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
10
- ar[i] = from[i];
11
- }
12
- }
13
- return to.concat(ar || Array.prototype.slice.call(from));
14
- };
15
6
  Object.defineProperty(exports, "__esModule", { value: true });
16
7
  exports.transformAndroid = transformAndroid;
17
8
  exports.transformIOS = transformIOS;
18
9
  function findMatchingClosingParen(source, openParenIndex) {
19
- var depth = 0;
20
- for (var i = openParenIndex; i < source.length; i += 1) {
21
- var char = source[i];
10
+ let depth = 0;
11
+ for (let i = openParenIndex; i < source.length; i += 1) {
12
+ const char = source[i];
22
13
  if (char === "(") {
23
14
  depth += 1;
24
15
  continue;
@@ -36,7 +27,7 @@ function findMatchingClosingParen(source, openParenIndex) {
36
27
  * Helper to add lines if they don't exist, anchored by a specific string.
37
28
  */
38
29
  function addLinesOnce(contents, anchor, linesToAdd) {
39
- if (linesToAdd.every(function (line) { return contents.includes(line); })) {
30
+ if (linesToAdd.every((line) => contents.includes(line))) {
40
31
  // All lines already exist, do nothing
41
32
  return contents;
42
33
  }
@@ -46,15 +37,15 @@ function addLinesOnce(contents, anchor, linesToAdd) {
46
37
  return contents;
47
38
  }
48
39
  // Add lines after the anchor
49
- return contents.replace(anchor, "".concat(anchor, "\n").concat(linesToAdd.join("\n")));
40
+ return contents.replace(anchor, `${anchor}\n${linesToAdd.join("\n")}`);
50
41
  }
51
42
  /**
52
43
  * Android: handle getDefaultReactHost pattern (RN 0.82+ style).
53
44
  * Adds jsBundleFilePath parameter to the call.
54
45
  */
55
46
  function transformAndroidReactHost(contents) {
56
- var kotlinImport = "import com.hotupdater.HotUpdater";
57
- var kotlinImportAnchor = "import com.facebook.react.ReactApplication";
47
+ const kotlinImport = "import com.hotupdater.HotUpdater";
48
+ const kotlinImportAnchor = "import com.facebook.react.ReactApplication";
58
49
  // Quick pattern detection: only touch files using getDefaultReactHost
59
50
  // with the new RN 0.82+ parameter style.
60
51
  if (!contents.includes("getDefaultReactHost(") ||
@@ -62,27 +53,27 @@ function transformAndroidReactHost(contents) {
62
53
  return contents;
63
54
  }
64
55
  // 1. Ensure HotUpdater import exists (idempotent via addLinesOnce)
65
- var result = addLinesOnce(contents, kotlinImportAnchor, [kotlinImport]);
66
- var callNeedle = "getDefaultReactHost(";
67
- var callStartIndex = result.indexOf(callNeedle);
56
+ const result = addLinesOnce(contents, kotlinImportAnchor, [kotlinImport]);
57
+ const callNeedle = "getDefaultReactHost(";
58
+ const callStartIndex = result.indexOf(callNeedle);
68
59
  if (callStartIndex === -1) {
69
60
  return result;
70
61
  }
71
- var openParenIndex = callStartIndex + callNeedle.length - 1;
72
- var closeParenIndex = findMatchingClosingParen(result, openParenIndex);
62
+ const openParenIndex = callStartIndex + callNeedle.length - 1;
63
+ const closeParenIndex = findMatchingClosingParen(result, openParenIndex);
73
64
  if (closeParenIndex === -1) {
74
65
  return result;
75
66
  }
76
- var callContents = result.slice(callStartIndex, closeParenIndex + 1);
67
+ const callContents = result.slice(callStartIndex, closeParenIndex + 1);
77
68
  if (callContents.includes("jsBundleFilePath")) {
78
69
  return result;
79
70
  }
80
- var callLines = callContents.split("\n");
71
+ const callLines = callContents.split("\n");
81
72
  // Determine the indentation used for parameters (e.g. " ")
82
- var paramIndent = "";
83
- for (var i = 1; i < callLines.length; i += 1) {
84
- var line = callLines[i];
85
- var trimmed = line.trim();
73
+ let paramIndent = "";
74
+ for (let i = 1; i < callLines.length; i += 1) {
75
+ const line = callLines[i];
76
+ const trimmed = line.trim();
86
77
  if (trimmed.length === 0) {
87
78
  continue;
88
79
  }
@@ -90,18 +81,18 @@ function transformAndroidReactHost(contents) {
90
81
  // No parameters detected, give up safely.
91
82
  return result;
92
83
  }
93
- var indentMatch = line.match(/^(\s*)/);
84
+ const indentMatch = line.match(/^(\s*)/);
94
85
  paramIndent = indentMatch ? indentMatch[1] : "";
95
86
  break;
96
87
  }
97
88
  if (!paramIndent) {
98
89
  return result;
99
90
  }
100
- var closingLineStartIndex = result.lastIndexOf("\n", closeParenIndex);
101
- var insertionIndex = closingLineStartIndex === -1 ? 0 : closingLineStartIndex + 1;
102
- var prefix = result.slice(0, insertionIndex);
103
- var suffix = result.slice(insertionIndex);
104
- var prevNonWhitespaceIndex = prefix.length - 1;
91
+ const closingLineStartIndex = result.lastIndexOf("\n", closeParenIndex);
92
+ const insertionIndex = closingLineStartIndex === -1 ? 0 : closingLineStartIndex + 1;
93
+ let prefix = result.slice(0, insertionIndex);
94
+ const suffix = result.slice(insertionIndex);
95
+ let prevNonWhitespaceIndex = prefix.length - 1;
105
96
  while (prevNonWhitespaceIndex >= 0 &&
106
97
  /\s/.test(prefix[prevNonWhitespaceIndex])) {
107
98
  prevNonWhitespaceIndex -= 1;
@@ -109,86 +100,81 @@ function transformAndroidReactHost(contents) {
109
100
  if (prevNonWhitespaceIndex >= 0 &&
110
101
  prefix[prevNonWhitespaceIndex] !== "," &&
111
102
  prefix[prevNonWhitespaceIndex] !== "(") {
112
- prefix = "".concat(prefix.slice(0, prevNonWhitespaceIndex + 1), ",").concat(prefix.slice(prevNonWhitespaceIndex + 1));
103
+ prefix = `${prefix.slice(0, prevNonWhitespaceIndex + 1)},${prefix.slice(prevNonWhitespaceIndex + 1)}`;
113
104
  }
114
- var jsBundleLine = "".concat(paramIndent, "jsBundleFilePath = HotUpdater.getJSBundleFile(applicationContext),");
115
- return "".concat(prefix).concat(jsBundleLine, "\n").concat(suffix);
105
+ const jsBundleLine = `${paramIndent}jsBundleFilePath = HotUpdater.getJSBundleFile(applicationContext),`;
106
+ return `${prefix}${jsBundleLine}\n${suffix}`;
116
107
  }
117
108
  /**
118
109
  * Android: DefaultReactNativeHost pattern (RN 0.81 / Expo 54).
119
110
  * Adds getJSBundleFile() override to the host.
120
111
  */
121
112
  function transformAndroidDefaultHost(contents) {
122
- var _a;
123
- var kotlinImport = "import com.hotupdater.HotUpdater";
124
- var kotlinImportAnchor = "import com.facebook.react.ReactApplication";
125
- var kotlinReactNativeHostAnchor = "object : DefaultReactNativeHost(this) {";
126
- var kotlinMethodCheck = "HotUpdater.getJSBundleFile(applicationContext)";
127
- var kotlinExistingMethodRegex = /^\s*override fun getJSBundleFile\(\): String\?\s*\{[\s\S]*?^\s*\}/gm;
128
- var kotlinHermesAnchor = "override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED";
129
- var kotlinNewArchAnchor = "override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED";
113
+ const kotlinImport = "import com.hotupdater.HotUpdater";
114
+ const kotlinImportAnchor = "import com.facebook.react.ReactApplication";
115
+ const kotlinReactNativeHostAnchor = "object : DefaultReactNativeHost(this) {";
116
+ const kotlinMethodCheck = "HotUpdater.getJSBundleFile(applicationContext)";
117
+ const kotlinExistingMethodRegex = /^\s*override fun getJSBundleFile\(\): String\?\s*\{[\s\S]*?^\s*\}/gm;
118
+ const kotlinHermesAnchor = "override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED";
119
+ const kotlinNewArchAnchor = "override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED";
130
120
  // Check if this is the old pattern with DefaultReactNativeHost
131
121
  if (!contents.includes(kotlinReactNativeHostAnchor)) {
132
122
  return contents;
133
123
  }
134
124
  // 1. Add import if missing
135
- var result = addLinesOnce(contents, kotlinImportAnchor, [kotlinImport]);
125
+ let result = addLinesOnce(contents, kotlinImportAnchor, [kotlinImport]);
136
126
  // 2. Add/Replace getJSBundleFile method if needed
137
127
  if (!result.includes(kotlinMethodCheck)) {
138
128
  // Remove potentially existing (different) override first
139
129
  result = result.replace(kotlinExistingMethodRegex, "");
140
- var lines_1 = result.split("\n");
141
- var findLineIndex = function (needle) {
142
- for (var i = 0; i < lines_1.length; i += 1) {
143
- if (lines_1[i].includes(needle)) {
130
+ const lines = result.split("\n");
131
+ const findLineIndex = (needle) => {
132
+ for (let i = 0; i < lines.length; i += 1) {
133
+ if (lines[i].includes(needle)) {
144
134
  return i;
145
135
  }
146
136
  }
147
137
  return -1;
148
138
  };
149
139
  // Prefer inserting after Hermes line, then after new architecture line
150
- var anchorIndex = findLineIndex(kotlinHermesAnchor);
140
+ let anchorIndex = findLineIndex(kotlinHermesAnchor);
151
141
  if (anchorIndex === -1) {
152
142
  anchorIndex = findLineIndex(kotlinNewArchAnchor);
153
143
  }
154
144
  if (anchorIndex !== -1) {
155
- var indentMatch = lines_1[anchorIndex].match(/^\s*/);
156
- var indent = indentMatch ? indentMatch[0] : "";
157
- var objectLine = lines_1.find(function (line) {
158
- return line.includes("object : DefaultReactNativeHost");
159
- });
160
- var indentSize = 2;
145
+ const indentMatch = lines[anchorIndex].match(/^\s*/);
146
+ const indent = indentMatch ? indentMatch[0] : "";
147
+ const objectLine = lines.find((line) => line.includes("object : DefaultReactNativeHost"));
148
+ let indentSize = 2;
161
149
  if (objectLine) {
162
- var objectIndent = (((_a = objectLine.match(/^\s*/)) === null || _a === void 0 ? void 0 : _a[0]) || "").length;
163
- var propertyIndent = indent.length;
164
- var diff = propertyIndent - objectIndent;
150
+ const objectIndent = (objectLine.match(/^\s*/)?.[0] || "").length;
151
+ const propertyIndent = indent.length;
152
+ const diff = propertyIndent - objectIndent;
165
153
  if (diff > 0) {
166
154
  indentSize = diff;
167
155
  }
168
156
  }
169
- var spaces = indentSize === 2 ? " " : " ";
170
- var bodyIndent = indent + spaces;
171
- var methodLines = [
157
+ const spaces = indentSize === 2 ? " " : " ";
158
+ const bodyIndent = indent + spaces;
159
+ const methodLines = [
172
160
  "", // blank line
173
- "".concat(indent, "override fun getJSBundleFile(): String? {"),
174
- "".concat(bodyIndent, "return HotUpdater.getJSBundleFile(applicationContext)"),
175
- "".concat(indent, "}"),
161
+ `${indent}override fun getJSBundleFile(): String? {`,
162
+ `${bodyIndent}return HotUpdater.getJSBundleFile(applicationContext)`,
163
+ `${indent}}`,
176
164
  ];
177
- var insertIndex = anchorIndex + 1;
178
- lines_1.splice.apply(lines_1, __spreadArray([insertIndex, 0], methodLines, false));
179
- result = lines_1.join("\n");
165
+ const insertIndex = anchorIndex + 1;
166
+ lines.splice(insertIndex, 0, ...methodLines);
167
+ result = lines.join("\n");
180
168
  }
181
169
  else {
182
170
  // Fallback: insert before the closing brace of the object block
183
- var hostStartIndex = lines_1.findIndex(function (line) {
184
- return line.includes("object : DefaultReactNativeHost");
185
- });
171
+ const hostStartIndex = lines.findIndex((line) => line.includes("object : DefaultReactNativeHost"));
186
172
  if (hostStartIndex === -1) {
187
173
  throw new Error("[transformAndroidDefaultHost] Could not find DefaultReactNativeHost block.");
188
174
  }
189
- var hostEndIndex = -1;
190
- for (var i = lines_1.length - 1; i > hostStartIndex; i -= 1) {
191
- if (lines_1[i].trim() === "}") {
175
+ let hostEndIndex = -1;
176
+ for (let i = lines.length - 1; i > hostStartIndex; i -= 1) {
177
+ if (lines[i].trim() === "}") {
192
178
  hostEndIndex = i;
193
179
  break;
194
180
  }
@@ -196,16 +182,16 @@ function transformAndroidDefaultHost(contents) {
196
182
  if (hostEndIndex === -1) {
197
183
  throw new Error("[transformAndroidDefaultHost] Could not find end of DefaultReactNativeHost block.");
198
184
  }
199
- var indentMatch = lines_1[hostEndIndex].match(/^\s*/);
200
- var indent = indentMatch ? indentMatch[0] : "";
201
- var bodyIndent = "".concat(indent, " ");
202
- var methodLines = [
203
- "".concat(indent, "override fun getJSBundleFile(): String? {"),
204
- "".concat(bodyIndent, "return HotUpdater.getJSBundleFile(applicationContext)"),
205
- "".concat(indent, "}"),
185
+ const indentMatch = lines[hostEndIndex].match(/^\s*/);
186
+ const indent = indentMatch ? indentMatch[0] : "";
187
+ const bodyIndent = `${indent} `;
188
+ const methodLines = [
189
+ `${indent}override fun getJSBundleFile(): String? {`,
190
+ `${bodyIndent}return HotUpdater.getJSBundleFile(applicationContext)`,
191
+ `${indent}}`,
206
192
  ];
207
- lines_1.splice.apply(lines_1, __spreadArray([hostEndIndex, 0], methodLines, false));
208
- result = lines_1.join("\n");
193
+ lines.splice(hostEndIndex, 0, ...methodLines);
194
+ result = lines.join("\n");
209
195
  }
210
196
  }
211
197
  return result;
@@ -214,7 +200,7 @@ function transformAndroidDefaultHost(contents) {
214
200
  * Public Android transformer that applies all Android-specific transforms.
215
201
  */
216
202
  function transformAndroid(contents) {
217
- var result = contents;
203
+ let result = contents;
218
204
  result = transformAndroidReactHost(result);
219
205
  result = transformAndroidDefaultHost(result);
220
206
  return result;
@@ -224,15 +210,15 @@ function transformAndroid(contents) {
224
210
  * Replaces NSBundle-based bundleURL with HotUpdater bundleURL.
225
211
  */
226
212
  function transformIOSObjC(contents) {
227
- var iosImport = "#import <HotUpdater/HotUpdater.h>";
228
- var iosBundleUrl = "[HotUpdater bundleURL]";
229
- var iosOriginalBundleUrlRegex = /\[\[NSBundle mainBundle\] URLForResource:@"main" withExtension:@"jsbundle"\]/g;
230
- var iosAppDelegateHeader = '#import "AppDelegate.h"';
213
+ const iosImport = "#import <HotUpdater/HotUpdater.h>";
214
+ const iosBundleUrl = "[HotUpdater bundleURL]";
215
+ const iosOriginalBundleUrlRegex = /\[\[NSBundle mainBundle\] URLForResource:@"main" withExtension:@"jsbundle"\]/g;
216
+ const iosAppDelegateHeader = '#import "AppDelegate.h"';
231
217
  // Check if it's likely Obj-C
232
218
  if (!contents.includes(iosAppDelegateHeader)) {
233
219
  return contents;
234
220
  }
235
- var result = contents;
221
+ let result = contents;
236
222
  // 1. Ensure HotUpdater import is present
237
223
  if (!result.includes(iosImport)) {
238
224
  result = addLinesOnce(result, iosAppDelegateHeader, [iosImport]);
@@ -249,21 +235,21 @@ function transformIOSObjC(contents) {
249
235
  * Replaces Bundle.main.url-based bundleURL with HotUpdater.bundleURL().
250
236
  */
251
237
  function transformIOSSwift(contents) {
252
- var swiftImport = "import HotUpdater";
253
- var swiftBundleUrl = "HotUpdater.bundleURL()";
254
- var swiftOriginalBundleUrlRegex = /Bundle\.main\.url\(forResource: "?main"?, withExtension: "jsbundle"\)/g;
238
+ const swiftImport = "import HotUpdater";
239
+ const swiftBundleUrl = "HotUpdater.bundleURL()";
240
+ const swiftOriginalBundleUrlRegex = /Bundle\.main\.url\(forResource: "?main"?, withExtension: "jsbundle"\)/g;
255
241
  // Check if it's likely Swift AppDelegate code
256
242
  if (!contents.includes("import ")) {
257
243
  return contents;
258
244
  }
259
245
  // 1. Add import if missing - find the last import statement and add after it
260
- var result = contents;
246
+ let result = contents;
261
247
  if (!result.includes(swiftImport)) {
262
248
  // Find the last import statement
263
- var lastImportMatch = result.match(/^import .*$/gm);
249
+ const lastImportMatch = result.match(/^import .*$/gm);
264
250
  if (lastImportMatch) {
265
- var lastImport = lastImportMatch[lastImportMatch.length - 1];
266
- result = result.replace(lastImport, "".concat(lastImport, "\n").concat(swiftImport));
251
+ const lastImport = lastImportMatch[lastImportMatch.length - 1];
252
+ result = result.replace(lastImport, `${lastImport}\n${swiftImport}`);
267
253
  }
268
254
  }
269
255
  // 2. Replace bundleURL provider if the original exists and hasn't been replaced
@@ -277,7 +263,7 @@ function transformIOSSwift(contents) {
277
263
  * Public iOS transformer that applies both Objective-C and Swift transforms.
278
264
  */
279
265
  function transformIOS(contents) {
280
- var result = contents;
266
+ let result = contents;
281
267
  result = transformIOSObjC(result);
282
268
  result = transformIOSSwift(result);
283
269
  return result;