@bravemobile/react-native-code-push 12.1.4 → 12.2.0

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/README.md CHANGED
@@ -10,6 +10,9 @@
10
10
 
11
11
  Supports React Native 0.74 ~ 0.82.
12
12
 
13
+ > [!NOTE]
14
+ > If you are using React Native 0.76 or lower, please use version `12.0.2` of this library.
15
+
13
16
  (Tested on the React Native CLI template apps)
14
17
 
15
18
  ### ✅ Requirements
@@ -20,17 +20,14 @@
20
20
  -keepclassmembers class com.facebook.react.ReactInstanceManager {
21
21
  private final ** mBundleLoader;
22
22
  }
23
- -keepclassmembers class com.facebook.react.ReactDelegate {
24
- private ** mReactHost; # bridgeless
25
- public void reload(...); # RN 0.74 and above
26
- }
27
23
  # bridgeless
28
24
  -keepclassmembers class com.facebook.react.defaults.DefaultReactHostDelegate {
29
25
  private ** jsBundleLoader;
30
26
  }
31
27
  # bridgeless
32
28
  -keepclassmembers class com.facebook.react.runtime.ReactHostImpl {
33
- private final ** mReactHostDelegate;
29
+ private final ** mReactHostDelegate; # RN < 0.81
30
+ private final ** reactHostDelegate; # RN 0.81+
34
31
  }
35
32
 
36
33
  # Can't find referenced class org.bouncycastle.**
@@ -12,8 +12,8 @@ import androidx.annotation.OptIn;
12
12
 
13
13
  import com.facebook.react.ReactDelegate;
14
14
  import com.facebook.react.ReactHost;
15
- import com.facebook.react.ReactInstanceManager;
16
15
  import com.facebook.react.ReactActivity;
16
+ import com.facebook.react.ReactInstanceManager;
17
17
  import com.facebook.react.ReactRootView;
18
18
  import com.facebook.react.bridge.Arguments;
19
19
  import com.facebook.react.bridge.JSBundleLoader;
@@ -126,7 +126,9 @@ public class CodePushNativeModule extends ReactContextBaseJavaModule {
126
126
 
127
127
  ReactHost reactHost = resolveReactHost();
128
128
  if (reactHost == null) {
129
+ CodePushUtils.log("Unable to resolve ReactHost");
129
130
  // Bridge, Old Architecture
131
+ setJSBundleLoaderBridge(latestJSBundleLoader);
130
132
  return;
131
133
  }
132
134
 
@@ -138,11 +140,27 @@ public class CodePushNativeModule extends ReactContextBaseJavaModule {
138
140
  }
139
141
  }
140
142
 
143
+ private void setJSBundleLoaderBridge(JSBundleLoader latestJSBundleLoader) throws NoSuchFieldException, IllegalAccessException {
144
+ ReactDelegate reactDelegate = resolveReactDelegate();
145
+ assert reactDelegate != null;
146
+ ReactInstanceManager instanceManager = reactDelegate.getReactInstanceManager();
147
+ Field bundleLoaderField = instanceManager.getClass().getDeclaredField("mBundleLoader");
148
+ bundleLoaderField.setAccessible(true);
149
+ bundleLoaderField.set(instanceManager, latestJSBundleLoader);
150
+ }
151
+
141
152
  @OptIn(markerClass = UnstableReactNativeAPI.class)
142
153
  private void setJSBundleLoaderBridgeless(ReactHost reactHost, JSBundleLoader latestJSBundleLoader) throws NoSuchFieldException, IllegalAccessException {
143
- Field mReactHostDelegateField = reactHost.getClass().getDeclaredField("mReactHostDelegate");
144
- mReactHostDelegateField.setAccessible(true);
145
- ReactHostDelegate reactHostDelegate = (ReactHostDelegate) mReactHostDelegateField.get(reactHost);
154
+ Field reactHostDelegateField;
155
+ try {
156
+ // RN < 0.81
157
+ reactHostDelegateField = reactHost.getClass().getDeclaredField("mReactHostDelegate");
158
+ } catch (NoSuchFieldException e) {
159
+ // RN >= 0.81
160
+ reactHostDelegateField = reactHost.getClass().getDeclaredField("reactHostDelegate");
161
+ }
162
+ reactHostDelegateField.setAccessible(true);
163
+ ReactHostDelegate reactHostDelegate = (ReactHostDelegate) reactHostDelegateField.get(reactHost);
146
164
  assert reactHostDelegate != null;
147
165
  Field jsBundleLoaderField = reactHostDelegate.getClass().getDeclaredField("jsBundleLoader");
148
166
  jsBundleLoaderField.setAccessible(true);
@@ -216,16 +234,11 @@ public class CodePushNativeModule extends ReactContextBaseJavaModule {
216
234
  private ReactHost resolveReactHost() {
217
235
  ReactDelegate reactDelegate = resolveReactDelegate();
218
236
  if (reactDelegate == null) {
237
+ CodePushUtils.log("Unable to resolve ReactDelegate");
219
238
  return null;
220
239
  }
221
240
 
222
- try {
223
- Field reactHostField = reactDelegate.getClass().getDeclaredField("mReactHost");
224
- reactHostField.setAccessible(true);
225
- return (ReactHost) reactHostField.get(reactDelegate);
226
- } catch (Exception e) {
227
- return null;
228
- }
241
+ return reactDelegate.getReactHost();
229
242
  }
230
243
 
231
244
  private void restartAppInternal(boolean onlyIfUpdateIsPending) {
@@ -19,6 +19,7 @@ type Options = {
19
19
  skipBundle: boolean;
20
20
  skipCleanup: boolean;
21
21
  outputBundleDir: string;
22
+ hashCalc?: boolean;
22
23
  }
23
24
 
24
25
  program.command('release')
@@ -36,6 +37,7 @@ program.command('release')
36
37
  .option('--enable <bool>', 'make the release to be enabled', parseBoolean, true)
37
38
  .option('--rollout <number>', 'rollout percentage (0-100)', parseFloat)
38
39
  .option('--skip-bundle <bool>', 'skip bundle process', parseBoolean, false)
40
+ .option('--hash-calc <bool>', 'calculates the bundle file hash used for packageHash in the release history (Requires setting --skip-bundle to true)', parseBoolean)
39
41
  .option('--skip-cleanup <bool>', 'skip cleanup process', parseBoolean, false)
40
42
  .option('--output-bundle-dir <string>', 'name of directory containing the bundle file created by the "bundle" command', OUTPUT_BUNDLE_DIR)
41
43
  .action(async (options: Options) => {
@@ -46,6 +48,11 @@ program.command('release')
46
48
  process.exit(1);
47
49
  }
48
50
 
51
+ if (options.hashCalc && !options.skipBundle) {
52
+ console.error('--hash-calc option can be used only when --skip-bundle is set to true.');
53
+ process.exit(1);
54
+ }
55
+
49
56
  await release(
50
57
  config.bundleUploader,
51
58
  config.getReleaseHistory,
@@ -64,6 +71,7 @@ program.command('release')
64
71
  options.skipBundle,
65
72
  options.skipCleanup,
66
73
  `${options.outputPath}/${options.outputBundleDir}`,
74
+ options.hashCalc,
67
75
  )
68
76
 
69
77
  console.log('🚀 Release completed.')
@@ -3,6 +3,8 @@ import path from "path";
3
3
  import { bundleCodePush } from "../bundleCommand/bundleCodePush.js";
4
4
  import { addToReleaseHistory } from "./addToReleaseHistory.js";
5
5
  import type { CliConfigInterface } from "../../../typings/react-native-code-push.d.ts";
6
+ import { generatePackageHashFromDirectory } from "../../utils/hash-utils.js";
7
+ import { unzip } from "../../utils/unzip.js";
6
8
 
7
9
  export async function release(
8
10
  bundleUploader: CliConfigInterface['bundleUploader'],
@@ -22,12 +24,21 @@ export async function release(
22
24
  skipBundle: boolean,
23
25
  skipCleanup: boolean,
24
26
  bundleDirectory: string,
27
+ hashCalc?: boolean,
25
28
  ): Promise<void> {
26
29
  const bundleFileName = skipBundle
27
30
  ? readBundleFileNameFrom(bundleDirectory)
28
31
  : await bundleCodePush(framework, platform, outputPath, entryFile, jsBundleName, bundleDirectory);
29
32
  const bundleFilePath = `${bundleDirectory}/${bundleFileName}`;
30
33
 
34
+ const packageHash = await (() => {
35
+ if (skipBundle && hashCalc) {
36
+ return calcHashFromBundleFile(bundleFilePath);
37
+ }
38
+ // If not using --skip-bundle, the bundleFileName represents package hash already.
39
+ return bundleFileName;
40
+ })();
41
+
31
42
  const downloadUrl = await (async () => {
32
43
  try {
33
44
  const { downloadUrl } = await bundleUploader(bundleFilePath, platform, identifier);
@@ -42,7 +53,7 @@ export async function release(
42
53
  appVersion,
43
54
  binaryVersion,
44
55
  downloadUrl,
45
- bundleFileName,
56
+ packageHash,
46
57
  getReleaseHistory,
47
58
  setReleaseHistory,
48
59
  platform,
@@ -70,3 +81,22 @@ function readBundleFileNameFrom(bundleDirectory: string): string {
70
81
  const bundleFilePath = path.join(bundleDirectory, files[0]);
71
82
  return path.basename(bundleFilePath);
72
83
  }
84
+
85
+ async function calcHashFromBundleFile(bundleFilePath: string): Promise<string> {
86
+ const tempDir = path.resolve(path.join(path.dirname(bundleFilePath), 'temp_contents_for_hash_calc'));
87
+ const zipFilePath = path.resolve(bundleFilePath);
88
+
89
+ if (fs.existsSync(tempDir)) {
90
+ fs.rmSync(tempDir, { recursive: true, force: true });
91
+ }
92
+ fs.mkdirSync(tempDir, { recursive: true });
93
+
94
+ try {
95
+ await unzip(zipFilePath, tempDir);
96
+ const hash = await generatePackageHashFromDirectory(tempDir, tempDir);
97
+ console.log(`log: Calculated package hash from existing bundle file: ${hash}`);
98
+ return hash;
99
+ } finally {
100
+ fs.rmSync(tempDir, { recursive: true, force: true });
101
+ }
102
+ }
@@ -17,6 +17,7 @@ program.command('release')
17
17
  .option('--enable <bool>', 'make the release to be enabled', parseBoolean, true)
18
18
  .option('--rollout <number>', 'rollout percentage (0-100)', parseFloat)
19
19
  .option('--skip-bundle <bool>', 'skip bundle process', parseBoolean, false)
20
+ .option('--hash-calc <bool>', 'calculates the bundle file hash used for packageHash in the release history (Requires setting --skip-bundle to true)', parseBoolean)
20
21
  .option('--skip-cleanup <bool>', 'skip cleanup process', parseBoolean, false)
21
22
  .option('--output-bundle-dir <string>', 'name of directory containing the bundle file created by the "bundle" command', OUTPUT_BUNDLE_DIR)
22
23
  .action(async (options) => {
@@ -25,7 +26,11 @@ program.command('release')
25
26
  console.error('Rollout percentage number must be between 0 and 100 (inclusive).');
26
27
  process.exit(1);
27
28
  }
28
- await release(config.bundleUploader, config.getReleaseHistory, config.setReleaseHistory, options.binaryVersion, options.appVersion, options.framework, options.platform, options.identifier, options.outputPath, options.entryFile, options.bundleName, options.mandatory, options.enable, options.rollout, options.skipBundle, options.skipCleanup, `${options.outputPath}/${options.outputBundleDir}`);
29
+ if (options.hashCalc && !options.skipBundle) {
30
+ console.error('--hash-calc option can be used only when --skip-bundle is set to true.');
31
+ process.exit(1);
32
+ }
33
+ await release(config.bundleUploader, config.getReleaseHistory, config.setReleaseHistory, options.binaryVersion, options.appVersion, options.framework, options.platform, options.identifier, options.outputPath, options.entryFile, options.bundleName, options.mandatory, options.enable, options.rollout, options.skipBundle, options.skipCleanup, `${options.outputPath}/${options.outputBundleDir}`, options.hashCalc);
29
34
  console.log('🚀 Release completed.');
30
35
  });
31
36
  function parseBoolean(value) {
@@ -2,11 +2,20 @@ import fs from "fs";
2
2
  import path from "path";
3
3
  import { bundleCodePush } from "../bundleCommand/bundleCodePush.js";
4
4
  import { addToReleaseHistory } from "./addToReleaseHistory.js";
5
- export async function release(bundleUploader, getReleaseHistory, setReleaseHistory, binaryVersion, appVersion, framework, platform, identifier, outputPath, entryFile, jsBundleName, mandatory, enable, rollout, skipBundle, skipCleanup, bundleDirectory) {
5
+ import { generatePackageHashFromDirectory } from "../../utils/hash-utils.js";
6
+ import { unzip } from "../../utils/unzip.js";
7
+ export async function release(bundleUploader, getReleaseHistory, setReleaseHistory, binaryVersion, appVersion, framework, platform, identifier, outputPath, entryFile, jsBundleName, mandatory, enable, rollout, skipBundle, skipCleanup, bundleDirectory, hashCalc) {
6
8
  const bundleFileName = skipBundle
7
9
  ? readBundleFileNameFrom(bundleDirectory)
8
10
  : await bundleCodePush(framework, platform, outputPath, entryFile, jsBundleName, bundleDirectory);
9
11
  const bundleFilePath = `${bundleDirectory}/${bundleFileName}`;
12
+ const packageHash = await (() => {
13
+ if (skipBundle && hashCalc) {
14
+ return calcHashFromBundleFile(bundleFilePath);
15
+ }
16
+ // If not using --skip-bundle, the bundleFileName represents package hash already.
17
+ return bundleFileName;
18
+ })();
10
19
  const downloadUrl = await (async () => {
11
20
  try {
12
21
  const { downloadUrl } = await bundleUploader(bundleFilePath, platform, identifier);
@@ -17,7 +26,7 @@ export async function release(bundleUploader, getReleaseHistory, setReleaseHisto
17
26
  process.exit(1);
18
27
  }
19
28
  })();
20
- await addToReleaseHistory(appVersion, binaryVersion, downloadUrl, bundleFileName, getReleaseHistory, setReleaseHistory, platform, identifier, mandatory, enable, rollout);
29
+ await addToReleaseHistory(appVersion, binaryVersion, downloadUrl, packageHash, getReleaseHistory, setReleaseHistory, platform, identifier, mandatory, enable, rollout);
21
30
  if (!skipCleanup) {
22
31
  cleanUpOutputs(outputPath);
23
32
  }
@@ -34,3 +43,20 @@ function readBundleFileNameFrom(bundleDirectory) {
34
43
  const bundleFilePath = path.join(bundleDirectory, files[0]);
35
44
  return path.basename(bundleFilePath);
36
45
  }
46
+ async function calcHashFromBundleFile(bundleFilePath) {
47
+ const tempDir = path.resolve(path.join(path.dirname(bundleFilePath), 'temp_contents_for_hash_calc'));
48
+ const zipFilePath = path.resolve(bundleFilePath);
49
+ if (fs.existsSync(tempDir)) {
50
+ fs.rmSync(tempDir, { recursive: true, force: true });
51
+ }
52
+ fs.mkdirSync(tempDir, { recursive: true });
53
+ try {
54
+ await unzip(zipFilePath, tempDir);
55
+ const hash = await generatePackageHashFromDirectory(tempDir, tempDir);
56
+ console.log(`log: Calculated package hash from existing bundle file: ${hash}`);
57
+ return hash;
58
+ }
59
+ finally {
60
+ fs.rmSync(tempDir, { recursive: true, force: true });
61
+ }
62
+ }
@@ -0,0 +1,41 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import yauzl from "yauzl";
4
+ export function unzip(zipPath, outputDir) {
5
+ return new Promise((resolve, reject) => {
6
+ yauzl.open(zipPath, { lazyEntries: true }, (err, zipFile) => {
7
+ if (err)
8
+ return reject(err);
9
+ zipFile.readEntry();
10
+ zipFile.on("entry", (entry) => {
11
+ const fullPath = path.join(outputDir, entry.fileName);
12
+ // Handle directory entry
13
+ if (/\/$/.test(entry.fileName)) {
14
+ fs.mkdir(fullPath, { recursive: true }, (err) => {
15
+ if (err)
16
+ return reject(err);
17
+ zipFile.readEntry();
18
+ });
19
+ return;
20
+ }
21
+ // Handle file entry
22
+ zipFile.openReadStream(entry, (err, readStream) => {
23
+ if (err)
24
+ return reject(err);
25
+ fs.mkdir(path.dirname(fullPath), { recursive: true }, (err) => {
26
+ if (err)
27
+ return reject(err);
28
+ const writeStream = fs.createWriteStream(fullPath);
29
+ readStream.pipe(writeStream);
30
+ // Continue to the next entry after writing
31
+ writeStream.on("close", () => {
32
+ zipFile.readEntry();
33
+ });
34
+ });
35
+ });
36
+ });
37
+ zipFile.on("end", resolve);
38
+ zipFile.on("error", reject);
39
+ });
40
+ });
41
+ }
package/cli/package.json CHANGED
@@ -14,7 +14,8 @@
14
14
  "commander": "^12.1.0",
15
15
  "shelljs": "^0.10.0",
16
16
  "xcode": "^3.0.1",
17
- "yazl": "^3.3.1"
17
+ "yazl": "^3.3.1",
18
+ "yauzl": "^3.2.0"
18
19
  },
19
20
  "peerDependencies": {
20
21
  "ts-node": ">=10"
@@ -28,6 +29,7 @@
28
29
  "node": ">=18"
29
30
  },
30
31
  "devDependencies": {
31
- "@types/yazl": "^3.3.0"
32
+ "@types/yazl": "^3.3.0",
33
+ "@types/yauzl": "^2.10.3"
32
34
  }
33
35
  }
@@ -0,0 +1,46 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import yauzl from "yauzl";
4
+
5
+ export function unzip(zipPath: string, outputDir: string): Promise<void> {
6
+ return new Promise<void>((resolve, reject) => {
7
+ yauzl.open(zipPath, { lazyEntries: true }, (err, zipFile) => {
8
+ if (err) return reject(err);
9
+
10
+ zipFile.readEntry();
11
+
12
+ zipFile.on("entry", (entry) => {
13
+ const fullPath = path.join(outputDir, entry.fileName);
14
+
15
+ // Handle directory entry
16
+ if (/\/$/.test(entry.fileName)) {
17
+ fs.mkdir(fullPath, { recursive: true }, (err) => {
18
+ if (err) return reject(err);
19
+ zipFile.readEntry();
20
+ });
21
+ return;
22
+ }
23
+
24
+ // Handle file entry
25
+ zipFile.openReadStream(entry, (err, readStream) => {
26
+ if (err) return reject(err);
27
+
28
+ fs.mkdir(path.dirname(fullPath), { recursive: true }, (err) => {
29
+ if (err) return reject(err);
30
+
31
+ const writeStream = fs.createWriteStream(fullPath);
32
+ readStream.pipe(writeStream);
33
+
34
+ // Continue to the next entry after writing
35
+ writeStream.on("close", () => {
36
+ zipFile.readEntry();
37
+ });
38
+ });
39
+ });
40
+ });
41
+
42
+ zipFile.on("end", resolve);
43
+ zipFile.on("error", reject);
44
+ });
45
+ });
46
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bravemobile/react-native-code-push",
3
- "version": "12.1.4",
3
+ "version": "12.2.0",
4
4
  "description": "React Native plugin for the CodePush service",
5
5
  "main": "src/CodePush.js",
6
6
  "react-native": "src/CodePush.js",
@@ -81,7 +81,8 @@
81
81
  "semver": "^7.3.5",
82
82
  "shelljs": "^0.10.0",
83
83
  "xcode": "^3.0.1",
84
- "yazl": "^3.3.1"
84
+ "yazl": "^3.3.1",
85
+ "yauzl": "^3.2.0"
85
86
  },
86
87
  "peerDependencies": {
87
88
  "expo": ">=50.0.0",
@@ -104,6 +105,7 @@
104
105
  "@types/q": "^1.5.4",
105
106
  "@types/semver": "^7.5.8",
106
107
  "@types/shelljs": "^0.8.15",
108
+ "@types/yauzl": "^2.10.3",
107
109
  "archiver": "latest",
108
110
  "babel-jest": "^29.7.0",
109
111
  "body-parser": "latest",