@bravemobile/react-native-code-push 13.0.0 → 13.1.0-beta.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.
Files changed (109) hide show
  1. package/CodePush.podspec +35 -3
  2. package/README.md +117 -3
  3. package/THIRD-PARTY-NOTICES +96 -0
  4. package/android/app/build.gradle +19 -0
  5. package/android/app/proguard-rules.pro +5 -0
  6. package/android/app/src/main/cpp/CMakeLists.txt +38 -0
  7. package/android/app/src/main/cpp/binarypatch_jni.c +181 -0
  8. package/android/app/src/main/java/com/microsoft/codepush/react/BinaryPatchAttempt.java +92 -0
  9. package/android/app/src/main/java/com/microsoft/codepush/react/BinaryPatchResult.java +64 -0
  10. package/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +1 -1
  11. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushBinaryPatch.java +293 -0
  12. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java +25 -0
  13. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +20 -6
  14. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java +168 -4
  15. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java +13 -0
  16. package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgressCallback.java +7 -0
  17. package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgressEventDispatcher.java +25 -4
  18. package/android/app/src/main/java/com/microsoft/codepush/react/HDiffPatchNative.java +52 -0
  19. package/android/app/src/test/java/com/microsoft/codepush/react/CodePushBinaryPatchTest.java +393 -0
  20. package/android/app/src/test/java/com/microsoft/codepush/react/CodePushUpdateManagerBinaryPatchTest.java +211 -0
  21. package/android/app/src/test/java/com/microsoft/codepush/react/CodePushUpdateManagerDownloadTest.java +489 -0
  22. package/android/app/src/test/java/com/microsoft/codepush/react/DownloadProgressEventDispatcherTest.java +80 -0
  23. package/android/codepush-export.gradle +115 -0
  24. package/cli/commands/bundleCommand/bundleCodePush.ts +39 -7
  25. package/cli/commands/bundleCommand/index.ts +9 -1
  26. package/cli/commands/releaseCommand/addToReleaseHistory.ts +7 -0
  27. package/cli/commands/releaseCommand/index.test.ts +118 -0
  28. package/cli/commands/releaseCommand/index.ts +20 -2
  29. package/cli/commands/releaseCommand/release.test.ts +582 -0
  30. package/cli/commands/releaseCommand/release.ts +232 -15
  31. package/cli/dist/commands/bundleCommand/bundleCodePush.js +26 -7
  32. package/cli/dist/commands/bundleCommand/index.js +5 -1
  33. package/cli/dist/commands/releaseCommand/addToReleaseHistory.js +6 -1
  34. package/cli/dist/commands/releaseCommand/index.js +8 -1
  35. package/cli/dist/commands/releaseCommand/index.test.js +96 -0
  36. package/cli/dist/commands/releaseCommand/release.js +165 -17
  37. package/cli/dist/commands/releaseCommand/release.test.js +367 -0
  38. package/cli/dist/functions/makeBinaryPatchBundle.js +248 -0
  39. package/cli/dist/functions/makeBinaryPatchBundle.test.js +321 -0
  40. package/cli/dist/functions/makeCodePushBundle.js +4 -2
  41. package/cli/dist/functions/runHermesEmitBinaryCommand.js +48 -1
  42. package/cli/dist/functions/runHermesEmitBinaryCommand.test.js +100 -0
  43. package/cli/dist/jest.globalSetup.js +38 -0
  44. package/cli/dist/utils/binaryPatch.js +86 -0
  45. package/cli/dist/utils/binaryPatch.test.js +190 -0
  46. package/cli/functions/makeBinaryPatchBundle.test.ts +410 -0
  47. package/cli/functions/makeBinaryPatchBundle.ts +367 -0
  48. package/cli/functions/makeCodePushBundle.ts +4 -2
  49. package/cli/functions/runHermesEmitBinaryCommand.test.ts +124 -0
  50. package/cli/functions/runHermesEmitBinaryCommand.ts +57 -1
  51. package/cli/jest.globalSetup.ts +43 -0
  52. package/cli/utils/binaryPatch.test.ts +234 -0
  53. package/cli/utils/binaryPatch.ts +103 -0
  54. package/cpp/binarypatch/binarypatch_zstd_decompressor.c +187 -0
  55. package/cpp/binarypatch/binarypatch_zstd_decompressor.h +47 -0
  56. package/cpp/binarypatch/vendor/HDiffPatch/libHDiffPatch/HPatch/checksum_plugin.h +52 -0
  57. package/cpp/binarypatch/vendor/HDiffPatch/libHDiffPatch/HPatch/hpatch_mt/hpatch_mt.h +147 -0
  58. package/cpp/binarypatch/vendor/HDiffPatch/libHDiffPatch/HPatch/patch.c +3315 -0
  59. package/cpp/binarypatch/vendor/HDiffPatch/libHDiffPatch/HPatch/patch.h +268 -0
  60. package/cpp/binarypatch/vendor/HDiffPatch/libHDiffPatch/HPatch/patch_private.h +297 -0
  61. package/cpp/binarypatch/vendor/HDiffPatch/libHDiffPatch/HPatch/patch_types.h +434 -0
  62. package/cpp/binarypatch/vendor/zstd/common/allocations.h +55 -0
  63. package/cpp/binarypatch/vendor/zstd/common/bits.h +205 -0
  64. package/cpp/binarypatch/vendor/zstd/common/bitstream.h +454 -0
  65. package/cpp/binarypatch/vendor/zstd/common/compiler.h +464 -0
  66. package/cpp/binarypatch/vendor/zstd/common/cpu.h +249 -0
  67. package/cpp/binarypatch/vendor/zstd/common/debug.c +30 -0
  68. package/cpp/binarypatch/vendor/zstd/common/debug.h +107 -0
  69. package/cpp/binarypatch/vendor/zstd/common/entropy_common.c +340 -0
  70. package/cpp/binarypatch/vendor/zstd/common/error_private.c +64 -0
  71. package/cpp/binarypatch/vendor/zstd/common/error_private.h +158 -0
  72. package/cpp/binarypatch/vendor/zstd/common/fse.h +625 -0
  73. package/cpp/binarypatch/vendor/zstd/common/fse_decompress.c +315 -0
  74. package/cpp/binarypatch/vendor/zstd/common/huf.h +277 -0
  75. package/cpp/binarypatch/vendor/zstd/common/mem.h +422 -0
  76. package/cpp/binarypatch/vendor/zstd/common/pool.c +371 -0
  77. package/cpp/binarypatch/vendor/zstd/common/pool.h +81 -0
  78. package/cpp/binarypatch/vendor/zstd/common/portability_macros.h +171 -0
  79. package/cpp/binarypatch/vendor/zstd/common/threading.c +182 -0
  80. package/cpp/binarypatch/vendor/zstd/common/threading.h +142 -0
  81. package/cpp/binarypatch/vendor/zstd/common/xxhash.c +18 -0
  82. package/cpp/binarypatch/vendor/zstd/common/xxhash.h +7094 -0
  83. package/cpp/binarypatch/vendor/zstd/common/zstd_common.c +48 -0
  84. package/cpp/binarypatch/vendor/zstd/common/zstd_deps.h +123 -0
  85. package/cpp/binarypatch/vendor/zstd/common/zstd_internal.h +324 -0
  86. package/cpp/binarypatch/vendor/zstd/common/zstd_trace.h +156 -0
  87. package/cpp/binarypatch/vendor/zstd/decompress/huf_decompress.c +1944 -0
  88. package/cpp/binarypatch/vendor/zstd/decompress/zstd_ddict.c +244 -0
  89. package/cpp/binarypatch/vendor/zstd/decompress/zstd_ddict.h +44 -0
  90. package/cpp/binarypatch/vendor/zstd/decompress/zstd_decompress.c +2410 -0
  91. package/cpp/binarypatch/vendor/zstd/decompress/zstd_decompress_block.c +2209 -0
  92. package/cpp/binarypatch/vendor/zstd/decompress/zstd_decompress_block.h +73 -0
  93. package/cpp/binarypatch/vendor/zstd/decompress/zstd_decompress_internal.h +240 -0
  94. package/cpp/binarypatch/vendor/zstd/zstd.h +3206 -0
  95. package/cpp/binarypatch/vendor/zstd/zstd_errors.h +107 -0
  96. package/ios/CodePush/CodePush.h +18 -1
  97. package/ios/CodePush/CodePush.mm +24 -1
  98. package/ios/CodePush/CodePushBinaryPatch.h +80 -0
  99. package/ios/CodePush/CodePushBinaryPatch.m +473 -0
  100. package/ios/CodePush/CodePushDownloadHandler.m +6 -0
  101. package/ios/CodePush/CodePushPackage.m +183 -2
  102. package/ios/CodePush/CodePushUpdateUtils.m +49 -1
  103. package/package.json +10 -3
  104. package/scripts/binary-patch/build-hdiffpatch.sh +86 -0
  105. package/scripts/export-embedded-bundle.sh +76 -0
  106. package/src/CodePush.js +46 -3
  107. package/src/CodePush.test.js +382 -0
  108. package/src/package-mixins.js +20 -2
  109. package/typings/react-native-code-push.d.ts +80 -1
@@ -0,0 +1,107 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under both the BSD-style license (found in the
6
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
+ * in the COPYING file in the root directory of this source tree).
8
+ * You may select, at your option, one of the above-listed licenses.
9
+ */
10
+
11
+ #ifndef ZSTD_ERRORS_H_398273423
12
+ #define ZSTD_ERRORS_H_398273423
13
+
14
+ #if defined (__cplusplus)
15
+ extern "C" {
16
+ #endif
17
+
18
+ /* ===== ZSTDERRORLIB_API : control library symbols visibility ===== */
19
+ #ifndef ZSTDERRORLIB_VISIBLE
20
+ /* Backwards compatibility with old macro name */
21
+ # ifdef ZSTDERRORLIB_VISIBILITY
22
+ # define ZSTDERRORLIB_VISIBLE ZSTDERRORLIB_VISIBILITY
23
+ # elif defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
24
+ # define ZSTDERRORLIB_VISIBLE __attribute__ ((visibility ("default")))
25
+ # else
26
+ # define ZSTDERRORLIB_VISIBLE
27
+ # endif
28
+ #endif
29
+
30
+ #ifndef ZSTDERRORLIB_HIDDEN
31
+ # if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
32
+ # define ZSTDERRORLIB_HIDDEN __attribute__ ((visibility ("hidden")))
33
+ # else
34
+ # define ZSTDERRORLIB_HIDDEN
35
+ # endif
36
+ #endif
37
+
38
+ #if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
39
+ # define ZSTDERRORLIB_API __declspec(dllexport) ZSTDERRORLIB_VISIBLE
40
+ #elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1)
41
+ # define ZSTDERRORLIB_API __declspec(dllimport) ZSTDERRORLIB_VISIBLE /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
42
+ #else
43
+ # define ZSTDERRORLIB_API ZSTDERRORLIB_VISIBLE
44
+ #endif
45
+
46
+ /*-*********************************************
47
+ * Error codes list
48
+ *-*********************************************
49
+ * Error codes _values_ are pinned down since v1.3.1 only.
50
+ * Therefore, don't rely on values if you may link to any version < v1.3.1.
51
+ *
52
+ * Only values < 100 are considered stable.
53
+ *
54
+ * note 1 : this API shall be used with static linking only.
55
+ * dynamic linking is not yet officially supported.
56
+ * note 2 : Prefer relying on the enum than on its value whenever possible
57
+ * This is the only supported way to use the error list < v1.3.1
58
+ * note 3 : ZSTD_isError() is always correct, whatever the library version.
59
+ **********************************************/
60
+ typedef enum {
61
+ ZSTD_error_no_error = 0,
62
+ ZSTD_error_GENERIC = 1,
63
+ ZSTD_error_prefix_unknown = 10,
64
+ ZSTD_error_version_unsupported = 12,
65
+ ZSTD_error_frameParameter_unsupported = 14,
66
+ ZSTD_error_frameParameter_windowTooLarge = 16,
67
+ ZSTD_error_corruption_detected = 20,
68
+ ZSTD_error_checksum_wrong = 22,
69
+ ZSTD_error_literals_headerWrong = 24,
70
+ ZSTD_error_dictionary_corrupted = 30,
71
+ ZSTD_error_dictionary_wrong = 32,
72
+ ZSTD_error_dictionaryCreation_failed = 34,
73
+ ZSTD_error_parameter_unsupported = 40,
74
+ ZSTD_error_parameter_combination_unsupported = 41,
75
+ ZSTD_error_parameter_outOfBound = 42,
76
+ ZSTD_error_tableLog_tooLarge = 44,
77
+ ZSTD_error_maxSymbolValue_tooLarge = 46,
78
+ ZSTD_error_maxSymbolValue_tooSmall = 48,
79
+ ZSTD_error_cannotProduce_uncompressedBlock = 49,
80
+ ZSTD_error_stabilityCondition_notRespected = 50,
81
+ ZSTD_error_stage_wrong = 60,
82
+ ZSTD_error_init_missing = 62,
83
+ ZSTD_error_memory_allocation = 64,
84
+ ZSTD_error_workSpace_tooSmall= 66,
85
+ ZSTD_error_dstSize_tooSmall = 70,
86
+ ZSTD_error_srcSize_wrong = 72,
87
+ ZSTD_error_dstBuffer_null = 74,
88
+ ZSTD_error_noForwardProgress_destFull = 80,
89
+ ZSTD_error_noForwardProgress_inputEmpty = 82,
90
+ /* following error codes are __NOT STABLE__, they can be removed or changed in future versions */
91
+ ZSTD_error_frameIndex_tooLarge = 100,
92
+ ZSTD_error_seekableIO = 102,
93
+ ZSTD_error_dstBuffer_wrong = 104,
94
+ ZSTD_error_srcBuffer_wrong = 105,
95
+ ZSTD_error_sequenceProducer_failed = 106,
96
+ ZSTD_error_externalSequences_invalid = 107,
97
+ ZSTD_error_maxCode = 120 /* never EVER use this value directly, it can change in future versions! Use ZSTD_isError() instead */
98
+ } ZSTD_ErrorCode;
99
+
100
+ ZSTDERRORLIB_API const char* ZSTD_getErrorString(ZSTD_ErrorCode code); /**< Same as ZSTD_getErrorName, but using a `ZSTD_ErrorCode` enum argument */
101
+
102
+
103
+ #if defined (__cplusplus)
104
+ }
105
+ #endif
106
+
107
+ #endif /* ZSTD_ERRORS_H_398273423 */
@@ -163,11 +163,16 @@ failCallback:(void (^)(NSError *err))failCallback;
163
163
 
164
164
  @interface CodePushPackage : NSObject
165
165
 
166
+ /*
167
+ * doneCallback is given what the attempt at installing the update from its binary patch
168
+ * archive ended in, or nil when the update had no patch archive to attempt. The result
169
+ * describes the download and not the update: it is never part of the update's metadata.
170
+ */
166
171
  + (void)downloadPackage:(NSDictionary *)updatePackage
167
172
  expectedBundleFileName:(NSString *)expectedBundleFileName
168
173
  operationQueue:(dispatch_queue_t)operationQueue
169
174
  progressCallback:(void (^)(long long, long long))progressCallback
170
- doneCallback:(void (^)())doneCallback
175
+ doneCallback:(void (^)(NSDictionary *binaryPatchResult))doneCallback
171
176
  failCallback:(void (^)(NSError *err))failCallback;
172
177
 
173
178
  + (NSDictionary *)getCurrentPackage:(NSError **)error;
@@ -206,6 +211,18 @@ failCallback:(void (^)(NSError *err))failCallback;
206
211
 
207
212
  @interface CodePushUpdateUtils : NSObject
208
213
 
214
+ /*
215
+ * The SHA-256 of some bytes, written the way every hash of an update's
216
+ * contents is: lower case hex.
217
+ */
218
+ + (NSString *)computeHashForData:(NSData *)inputData;
219
+
220
+ /*
221
+ * The same hash, of the contents of a file. Returns nil when the file
222
+ * cannot be read.
223
+ */
224
+ + (NSString *)computeHashForFileAtPath:(NSString *)filePath;
225
+
209
226
  + (BOOL)copyEntriesInFolder:(NSString *)sourceFolder
210
227
  destFolder:(NSString *)destFolder
211
228
  error:(NSError **)error;
@@ -61,6 +61,10 @@ static NSString *const BinaryBundleDateKey = @"binaryDate";
61
61
  static NSString *const PackageHashKey = @"packageHash";
62
62
  static NSString *const PackageIsPendingKey = @"isPending";
63
63
 
64
+ // Not one of those keys: the field a download that tried a binary patch reports its outcome
65
+ // under, on the package it resolves with and on no package it stores.
66
+ static NSString *const BinaryPatchResultKey = @"binaryPatchResult";
67
+
64
68
  #pragma mark - Static variables
65
69
 
66
70
  static BOOL isRunningBinaryVersion = NO;
@@ -735,6 +739,14 @@ RCT_EXPORT_METHOD(downloadUpdate:(NSDictionary*)updatePackage
735
739
  operationQueue:_methodQueue
736
740
  // The download is progressing forward
737
741
  progressCallback:^(long long expectedContentLength, long long receivedContentLength) {
742
+ // Received bytes only run backwards when a new download starts a stream of its
743
+ // own - the full archive after a binary patch fallback. The pause left over
744
+ // from the finished patch download would swallow that whole stream, so frame
745
+ // observation resumes here and the throttle forgets the previous stream.
746
+ if (notifyProgress && receivedContentLength < _latestReceivedConentLength) {
747
+ self.paused = NO;
748
+ _lastProgressEventTime = 0;
749
+ }
738
750
  // Update the download progress so that the frame observer can notify the JS side
739
751
  _latestExpectedContentLength = expectedContentLength;
740
752
  _latestReceivedConentLength = receivedContentLength;
@@ -755,13 +767,24 @@ RCT_EXPORT_METHOD(downloadUpdate:(NSDictionary*)updatePackage
755
767
  }
756
768
  }
757
769
  // The download completed
758
- doneCallback:^{
770
+ doneCallback:^(NSDictionary *binaryPatchResult) {
759
771
  NSError *err;
760
772
  NSDictionary *newPackage = [CodePushPackage getPackage:mutableUpdatePackage[PackageHashKey] error:&err];
761
773
 
762
774
  if (err) {
763
775
  return reject([NSString stringWithFormat: @"%lu", (long)err.code], err.localizedDescription, err);
764
776
  }
777
+
778
+ if (binaryPatchResult) {
779
+ // The result describes this download rather than the update, so it is put on
780
+ // what this call resolves with and nowhere else: the metadata that was
781
+ // written for the update knows nothing about it, and whoever asked for the
782
+ // download decides what the result is worth.
783
+ NSMutableDictionary *downloadedPackage = [newPackage mutableCopy];
784
+ downloadedPackage[BinaryPatchResultKey] = binaryPatchResult;
785
+ return resolve(downloadedPackage);
786
+ }
787
+
765
788
  resolve(newPackage);
766
789
  }
767
790
  // The download failed
@@ -0,0 +1,80 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ /*
4
+ * Why an update that was downloaded as a binary patch has to be downloaded in full
5
+ * instead.
6
+ *
7
+ * A failed restore is not an error the user ever hears about: it is the signal to
8
+ * download the update's full archive. These reasons are the vocabulary the appliers of
9
+ * every platform report, and the logs a rollout is judged from are read for exactly
10
+ * these words, so they must not be reworded.
11
+ */
12
+
13
+ /** The bundle inside the app binary could not be opened or read. */
14
+ extern NSString *const CodePushBinaryPatchReasonBaseBundleUnavailable;
15
+
16
+ /** The bundle inside the app binary is not the one the patch was computed against. */
17
+ extern NSString *const CodePushBinaryPatchReasonBaseHashMismatch;
18
+
19
+ /** The manifest is missing, malformed, points outside the archive, or asks for too much. */
20
+ extern NSString *const CodePushBinaryPatchReasonInvalidManifest;
21
+
22
+ /** The patch was produced by a format or a codec this client cannot apply. */
23
+ extern NSString *const CodePushBinaryPatchReasonUnsupportedFormat;
24
+
25
+ /** The applier refused the patch, or the restored bundle could not be written. */
26
+ extern NSString *const CodePushBinaryPatchReasonPatchApplyFailed;
27
+
28
+ /** The restored bundle is not the one the manifest promised. */
29
+ extern NSString *const CodePushBinaryPatchReasonTargetVerificationFailed;
30
+
31
+ /**
32
+ * The update restored from the patch did not pass the checks every update passes before
33
+ * it is installed - the folder hash above all.
34
+ *
35
+ * This one is reported by the caller rather than by the applier: by the time it applies,
36
+ * the applier has already handed back a bundle it was happy with.
37
+ */
38
+ extern NSString *const CodePushBinaryPatchReasonPackageVerificationFailed;
39
+
40
+ /**
41
+ * Rebuilds the JS bundle of an update that was downloaded as a binary patch archive.
42
+ *
43
+ * A patch archive holds everything the full archive holds except the JS bundle, which it
44
+ * carries as a patch against the bundle that shipped inside the app binary, plus a
45
+ * manifest describing how to rebuild it. Restoring means applying that patch, verifying
46
+ * the result, moving it to where the bundle belongs and deleting the two patch-only
47
+ * files. What is left is byte for byte the contents of the full archive, so the folder
48
+ * hash check that follows the install is unchanged and stays the last line of defence.
49
+ *
50
+ * Nothing here trusts the patch. Neither the diff format nor the zstd streams inside it
51
+ * carry a checksum of the data they produce, so an apply that reports success is not
52
+ * proof of a correct result: a base bundle of the right size but the wrong content, or a
53
+ * corrupted patch body, both produce wrong bytes without any error. The base bundle is
54
+ * hashed before the patch is applied and the restored bundle is hashed afterwards, and
55
+ * the restored bytes only reach the update contents once both checks have passed.
56
+ *
57
+ * Every failure is reported as a reason, never as an exception: the caller answers all
58
+ * of them the same way, by downloading the full archive instead.
59
+ */
60
+ @interface CodePushBinaryPatch : NSObject
61
+
62
+ /**
63
+ * Turns the contents of a downloaded patch archive into the contents of the full one.
64
+ *
65
+ * This reads and hashes whole bundles, so it belongs on the queue the download runs on
66
+ * and never on the main queue.
67
+ *
68
+ * @param unzippedFolderPath the unzipped archive, which is modified in place
69
+ * @param workingFolderPath scratch directory for the restored bundle, emptied before
70
+ * and after the attempt so an interrupted run leaves nothing
71
+ * @param baseBundleURL the JS bundle that shipped inside the app binary
72
+ * @param failureReason set to the reason the full archive has to be downloaded
73
+ * instead, whenever this returns NO
74
+ */
75
+ + (BOOL)restoreBundleInUnzippedFolder:(NSString *)unzippedFolderPath
76
+ workingFolder:(NSString *)workingFolderPath
77
+ baseBundleURL:(NSURL *)baseBundleURL
78
+ failureReason:(NSString **)failureReason;
79
+
80
+ @end