@hot-updater/react-native 0.25.11 → 0.25.13

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": "@hot-updater/react-native",
3
- "version": "0.25.11",
3
+ "version": "0.25.13",
4
4
  "description": "React Native OTA solution for self-hosted",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -120,14 +120,14 @@
120
120
  "react-native": "0.79.1",
121
121
  "react-native-builder-bob": "^0.40.10",
122
122
  "typescript": "^5.8.3",
123
- "hot-updater": "0.25.11"
123
+ "hot-updater": "0.25.13"
124
124
  },
125
125
  "dependencies": {
126
126
  "use-sync-external-store": "1.5.0",
127
- "@hot-updater/cli-tools": "0.25.11",
128
- "@hot-updater/core": "0.25.11",
129
- "@hot-updater/js": "0.25.11",
130
- "@hot-updater/plugin-core": "0.25.11"
127
+ "@hot-updater/cli-tools": "0.25.13",
128
+ "@hot-updater/js": "0.25.13",
129
+ "@hot-updater/plugin-core": "0.25.13",
130
+ "@hot-updater/core": "0.25.13"
131
131
  },
132
132
  "scripts": {
133
133
  "build": "bob build && tsc -p plugin/tsconfig.build.json",
@@ -15,6 +15,23 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.transformAndroid = transformAndroid;
17
17
  exports.transformIOS = transformIOS;
18
+ function findMatchingClosingParen(source, openParenIndex) {
19
+ var depth = 0;
20
+ for (var i = openParenIndex; i < source.length; i += 1) {
21
+ var char = source[i];
22
+ if (char === "(") {
23
+ depth += 1;
24
+ continue;
25
+ }
26
+ if (char === ")") {
27
+ depth -= 1;
28
+ if (depth === 0) {
29
+ return i;
30
+ }
31
+ }
32
+ }
33
+ return -1;
34
+ }
18
35
  /**
19
36
  * Helper to add lines if they don't exist, anchored by a specific string.
20
37
  */
@@ -38,7 +55,6 @@ function addLinesOnce(contents, anchor, linesToAdd) {
38
55
  function transformAndroidReactHost(contents) {
39
56
  var kotlinImport = "import com.hotupdater.HotUpdater";
40
57
  var kotlinImportAnchor = "import com.facebook.react.ReactApplication";
41
- var kotlinMethodCheck = "HotUpdater.getJSBundleFile(applicationContext)";
42
58
  // Quick pattern detection: only touch files using getDefaultReactHost
43
59
  // with the new RN 0.82+ parameter style.
44
60
  if (!contents.includes("getDefaultReactHost(") ||
@@ -47,22 +63,25 @@ function transformAndroidReactHost(contents) {
47
63
  }
48
64
  // 1. Ensure HotUpdater import exists (idempotent via addLinesOnce)
49
65
  var result = addLinesOnce(contents, kotlinImportAnchor, [kotlinImport]);
50
- // 2. If jsBundleFilePath is already wired to HotUpdater, do nothing
51
- if (result.includes(kotlinMethodCheck) &&
52
- result.includes("jsBundleFilePath")) {
66
+ var callNeedle = "getDefaultReactHost(";
67
+ var callStartIndex = result.indexOf(callNeedle);
68
+ if (callStartIndex === -1) {
53
69
  return result;
54
70
  }
55
- var lines = result.split("\n");
56
- var callIndex = lines.findIndex(function (line) {
57
- return line.includes("getDefaultReactHost(");
58
- });
59
- if (callIndex === -1) {
71
+ var openParenIndex = callStartIndex + callNeedle.length - 1;
72
+ var closeParenIndex = findMatchingClosingParen(result, openParenIndex);
73
+ if (closeParenIndex === -1) {
60
74
  return result;
61
75
  }
76
+ var callContents = result.slice(callStartIndex, closeParenIndex + 1);
77
+ if (callContents.includes("jsBundleFilePath")) {
78
+ return result;
79
+ }
80
+ var callLines = callContents.split("\n");
62
81
  // Determine the indentation used for parameters (e.g. " ")
63
82
  var paramIndent = "";
64
- for (var i = callIndex + 1; i < lines.length; i += 1) {
65
- var line = lines[i];
83
+ for (var i = 1; i < callLines.length; i += 1) {
84
+ var line = callLines[i];
66
85
  var trimmed = line.trim();
67
86
  if (trimmed.length === 0) {
68
87
  continue;
@@ -78,26 +97,22 @@ function transformAndroidReactHost(contents) {
78
97
  if (!paramIndent) {
79
98
  return result;
80
99
  }
81
- // Find the closing line of the call (a line that is just ")" with indentation).
82
- var closingIndex = -1;
83
- for (var i = callIndex + 1; i < lines.length; i += 1) {
84
- if (lines[i].trim() === ")") {
85
- closingIndex = i;
86
- break;
87
- }
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;
105
+ while (prevNonWhitespaceIndex >= 0 &&
106
+ /\s/.test(prefix[prevNonWhitespaceIndex])) {
107
+ prevNonWhitespaceIndex -= 1;
88
108
  }
89
- if (closingIndex === -1) {
90
- return result;
91
- }
92
- // Avoid inserting twice if jsBundleFilePath already added somewhere in the call.
93
- for (var i = callIndex; i < closingIndex; i += 1) {
94
- if (lines[i].includes("jsBundleFilePath")) {
95
- return result;
96
- }
109
+ if (prevNonWhitespaceIndex >= 0 &&
110
+ prefix[prevNonWhitespaceIndex] !== "," &&
111
+ prefix[prevNonWhitespaceIndex] !== "(") {
112
+ prefix = "".concat(prefix.slice(0, prevNonWhitespaceIndex + 1), ",").concat(prefix.slice(prevNonWhitespaceIndex + 1));
97
113
  }
98
114
  var jsBundleLine = "".concat(paramIndent, "jsBundleFilePath = HotUpdater.getJSBundleFile(applicationContext),");
99
- lines.splice(closingIndex, 0, jsBundleLine);
100
- return lines.join("\n");
115
+ return "".concat(prefix).concat(jsBundleLine, "\n").concat(suffix);
101
116
  }
102
117
  /**
103
118
  * Android: DefaultReactNativeHost pattern (RN 0.81 / Expo 54).