@bravemobile/react-native-code-push 12.4.1 → 13.1.0-beta.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/CodePush.podspec +47 -2
- package/README.md +118 -3
- package/THIRD-PARTY-NOTICES +96 -0
- package/android/app/build.gradle +26 -0
- package/android/app/proguard-rules.pro +5 -0
- package/android/app/src/main/cpp/CMakeLists.txt +38 -0
- package/android/app/src/main/cpp/binarypatch_jni.c +181 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/BinaryPatchAttempt.java +92 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/BinaryPatchResult.java +64 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +46 -11
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushBinaryPatch.java +293 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java +25 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +79 -88
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java +159 -4
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java +13 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/HDiffPatchNative.java +52 -0
- package/android/app/src/test/java/com/microsoft/codepush/react/CodePushBinaryPatchTest.java +393 -0
- package/android/app/src/test/java/com/microsoft/codepush/react/CodePushUpdateManagerBinaryPatchTest.java +207 -0
- package/android/app/src/test/java/com/microsoft/codepush/react/CodePushUpdateManagerDownloadTest.java +449 -0
- package/android/codepush-export.gradle +115 -0
- package/cli/commands/bundleCommand/bundleCodePush.ts +39 -7
- package/cli/commands/bundleCommand/index.ts +9 -1
- package/cli/commands/releaseCommand/addToReleaseHistory.ts +7 -0
- package/cli/commands/releaseCommand/index.test.ts +118 -0
- package/cli/commands/releaseCommand/index.ts +20 -2
- package/cli/commands/releaseCommand/release.test.ts +582 -0
- package/cli/commands/releaseCommand/release.ts +232 -15
- package/cli/dist/commands/bundleCommand/bundleCodePush.js +26 -7
- package/cli/dist/commands/bundleCommand/index.js +5 -1
- package/cli/dist/commands/releaseCommand/addToReleaseHistory.js +6 -1
- package/cli/dist/commands/releaseCommand/index.js +8 -1
- package/cli/dist/commands/releaseCommand/index.test.js +96 -0
- package/cli/dist/commands/releaseCommand/release.js +165 -17
- package/cli/dist/commands/releaseCommand/release.test.js +367 -0
- package/cli/dist/functions/makeBinaryPatchBundle.js +248 -0
- package/cli/dist/functions/makeBinaryPatchBundle.test.js +321 -0
- package/cli/dist/functions/makeCodePushBundle.js +4 -2
- package/cli/dist/functions/runHermesEmitBinaryCommand.js +98 -27
- package/cli/dist/functions/runHermesEmitBinaryCommand.test.js +100 -0
- package/cli/dist/jest.globalSetup.js +38 -0
- package/cli/dist/utils/binaryPatch.js +86 -0
- package/cli/dist/utils/binaryPatch.test.js +190 -0
- package/cli/functions/makeBinaryPatchBundle.test.ts +410 -0
- package/cli/functions/makeBinaryPatchBundle.ts +367 -0
- package/cli/functions/makeCodePushBundle.ts +4 -2
- package/cli/functions/runHermesEmitBinaryCommand.test.ts +124 -0
- package/cli/functions/runHermesEmitBinaryCommand.ts +112 -26
- package/cli/jest.globalSetup.ts +43 -0
- package/cli/utils/binaryPatch.test.ts +234 -0
- package/cli/utils/binaryPatch.ts +103 -0
- package/cpp/binarypatch/binarypatch_zstd_decompressor.c +187 -0
- package/cpp/binarypatch/binarypatch_zstd_decompressor.h +47 -0
- package/cpp/binarypatch/vendor/HDiffPatch/libHDiffPatch/HPatch/checksum_plugin.h +52 -0
- package/cpp/binarypatch/vendor/HDiffPatch/libHDiffPatch/HPatch/hpatch_mt/hpatch_mt.h +147 -0
- package/cpp/binarypatch/vendor/HDiffPatch/libHDiffPatch/HPatch/patch.c +3315 -0
- package/cpp/binarypatch/vendor/HDiffPatch/libHDiffPatch/HPatch/patch.h +268 -0
- package/cpp/binarypatch/vendor/HDiffPatch/libHDiffPatch/HPatch/patch_private.h +297 -0
- package/cpp/binarypatch/vendor/HDiffPatch/libHDiffPatch/HPatch/patch_types.h +434 -0
- package/cpp/binarypatch/vendor/zstd/common/allocations.h +55 -0
- package/cpp/binarypatch/vendor/zstd/common/bits.h +205 -0
- package/cpp/binarypatch/vendor/zstd/common/bitstream.h +454 -0
- package/cpp/binarypatch/vendor/zstd/common/compiler.h +464 -0
- package/cpp/binarypatch/vendor/zstd/common/cpu.h +249 -0
- package/cpp/binarypatch/vendor/zstd/common/debug.c +30 -0
- package/cpp/binarypatch/vendor/zstd/common/debug.h +107 -0
- package/cpp/binarypatch/vendor/zstd/common/entropy_common.c +340 -0
- package/cpp/binarypatch/vendor/zstd/common/error_private.c +64 -0
- package/cpp/binarypatch/vendor/zstd/common/error_private.h +158 -0
- package/cpp/binarypatch/vendor/zstd/common/fse.h +625 -0
- package/cpp/binarypatch/vendor/zstd/common/fse_decompress.c +315 -0
- package/cpp/binarypatch/vendor/zstd/common/huf.h +277 -0
- package/cpp/binarypatch/vendor/zstd/common/mem.h +422 -0
- package/cpp/binarypatch/vendor/zstd/common/pool.c +371 -0
- package/cpp/binarypatch/vendor/zstd/common/pool.h +81 -0
- package/cpp/binarypatch/vendor/zstd/common/portability_macros.h +171 -0
- package/cpp/binarypatch/vendor/zstd/common/threading.c +182 -0
- package/cpp/binarypatch/vendor/zstd/common/threading.h +142 -0
- package/cpp/binarypatch/vendor/zstd/common/xxhash.c +18 -0
- package/cpp/binarypatch/vendor/zstd/common/xxhash.h +7094 -0
- package/cpp/binarypatch/vendor/zstd/common/zstd_common.c +48 -0
- package/cpp/binarypatch/vendor/zstd/common/zstd_deps.h +123 -0
- package/cpp/binarypatch/vendor/zstd/common/zstd_internal.h +324 -0
- package/cpp/binarypatch/vendor/zstd/common/zstd_trace.h +156 -0
- package/cpp/binarypatch/vendor/zstd/decompress/huf_decompress.c +1944 -0
- package/cpp/binarypatch/vendor/zstd/decompress/zstd_ddict.c +244 -0
- package/cpp/binarypatch/vendor/zstd/decompress/zstd_ddict.h +44 -0
- package/cpp/binarypatch/vendor/zstd/decompress/zstd_decompress.c +2410 -0
- package/cpp/binarypatch/vendor/zstd/decompress/zstd_decompress_block.c +2209 -0
- package/cpp/binarypatch/vendor/zstd/decompress/zstd_decompress_block.h +73 -0
- package/cpp/binarypatch/vendor/zstd/decompress/zstd_decompress_internal.h +240 -0
- package/cpp/binarypatch/vendor/zstd/zstd.h +3206 -0
- package/cpp/binarypatch/vendor/zstd/zstd_errors.h +107 -0
- package/ios/CodePush/CodePush.h +58 -9
- package/ios/CodePush/{CodePush.m → CodePush.mm} +77 -63
- package/ios/CodePush/CodePushBinaryPatch.h +80 -0
- package/ios/CodePush/CodePushBinaryPatch.m +473 -0
- package/ios/CodePush/CodePushPackage.m +183 -2
- package/ios/CodePush/CodePushUpdateUtils.m +49 -1
- package/ios/CodePush.xcodeproj/project.pbxproj +6 -6
- package/package.json +28 -4
- package/react-native.config.js +3 -1
- package/scripts/binary-patch/build-hdiffpatch.sh +86 -0
- package/scripts/export-embedded-bundle.sh +76 -0
- package/src/CodePush.js +190 -96
- package/src/CodePush.test.js +382 -0
- package/src/native/NativeCodePush.ts +162 -0
- package/src/package-mixins.js +24 -11
- package/src/specs/NativeCodePush.ts +43 -0
- package/typings/react-native-code-push.d.ts +77 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java +0 -102
- package/src/AlertAdapter.js +0 -24
package/src/CodePush.js
CHANGED
|
@@ -1,14 +1,46 @@
|
|
|
1
|
-
import { Alert } from "
|
|
2
|
-
import { AppState, Platform } from "react-native";
|
|
1
|
+
import { Alert, AppState, Platform } from "react-native";
|
|
3
2
|
import log from "./logging";
|
|
4
3
|
import hoistStatics from 'hoist-non-react-statics';
|
|
5
4
|
import { SemverVersioning } from './versioning/SemverVersioning'
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const NativeCodePushModule = require("./native/NativeCodePush");
|
|
7
|
+
let NativeCodePush = NativeCodePushModule.getNativeCodePush?.() ?? NativeCodePushModule.default;
|
|
8
|
+
const { InstallMode, UpdateState } = NativeCodePushModule;
|
|
9
|
+
let PackageMixins = NativeCodePush ? require("./package-mixins")(NativeCodePush) : null;
|
|
9
10
|
|
|
10
11
|
const DEPLOYMENT_KEY = 'deprecated_deployment_key';
|
|
11
12
|
|
|
13
|
+
function getNativeCodePush() {
|
|
14
|
+
if (!NativeCodePush) {
|
|
15
|
+
const NativeCodePushModule = require("./native/NativeCodePush");
|
|
16
|
+
NativeCodePush = NativeCodePushModule.getNativeCodePush?.() ?? NativeCodePushModule.default;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (NativeCodePush && !PackageMixins) {
|
|
20
|
+
PackageMixins = require("./package-mixins")(NativeCodePush);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return NativeCodePush;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function requireNativeCodePush(callerName) {
|
|
27
|
+
const nativeCodePush = getNativeCodePush();
|
|
28
|
+
if (!nativeCodePush) {
|
|
29
|
+
throw new Error(`The CodePush native module isn't available during ${callerName}.`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return nativeCodePush;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function requirePackageMixins(callerName) {
|
|
36
|
+
const nativeCodePush = requireNativeCodePush(callerName);
|
|
37
|
+
if (!PackageMixins) {
|
|
38
|
+
PackageMixins = require("./package-mixins")(nativeCodePush);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return PackageMixins;
|
|
42
|
+
}
|
|
43
|
+
|
|
12
44
|
/**
|
|
13
45
|
* @param deviceId {string}
|
|
14
46
|
* @returns {number}
|
|
@@ -67,7 +99,7 @@ async function checkForUpdate(handleBinaryVersionMismatchCallback = null) {
|
|
|
67
99
|
* for their specific deployment and version and which are actually
|
|
68
100
|
* different from the CodePush update they have already installed.
|
|
69
101
|
*/
|
|
70
|
-
const nativeConfig = await getConfiguration();
|
|
102
|
+
const nativeConfig = await getConfiguration("checkForUpdate");
|
|
71
103
|
|
|
72
104
|
// Use dynamically overridden getCurrentPackage() during tests.
|
|
73
105
|
const localPackage = await module.exports.getCurrentPackage();
|
|
@@ -149,6 +181,11 @@ async function checkForUpdate(handleBinaryVersionMismatchCallback = null) {
|
|
|
149
181
|
*/
|
|
150
182
|
const updateInfo = {
|
|
151
183
|
download_url: latestReleaseInfo.downloadUrl,
|
|
184
|
+
/**
|
|
185
|
+
* Only released updates that were published with a binary patch carry this.
|
|
186
|
+
* When it is missing, the update is downloaded in full from `download_url`.
|
|
187
|
+
*/
|
|
188
|
+
binary_patch_download_url: latestReleaseInfo.binaryPatchDownloadUrl,
|
|
152
189
|
// (`enabled` will always be true in the release information obtained from the previous process.)
|
|
153
190
|
is_available: latestReleaseInfo.enabled,
|
|
154
191
|
package_hash: latestReleaseInfo.packageHash,
|
|
@@ -202,8 +239,9 @@ async function checkForUpdate(handleBinaryVersionMismatchCallback = null) {
|
|
|
202
239
|
* 4) The server said there is an update, but the update's hash is the same as that
|
|
203
240
|
* of the binary's currently running version. This should only happen in Android -
|
|
204
241
|
* unlike iOS, we don't attach the binary's hash to the updateCheck request
|
|
205
|
-
* because
|
|
206
|
-
*
|
|
242
|
+
* because an update built against the binary's version does not need one: a
|
|
243
|
+
* release published with a binary patch carries the patch archive next to the
|
|
244
|
+
* full one, and the client decides for itself which of the two to install.
|
|
207
245
|
*/
|
|
208
246
|
if (!update || update.updateAppVersion ||
|
|
209
247
|
localPackage && (update.packageHash === localPackage.packageHash) ||
|
|
@@ -217,8 +255,10 @@ async function checkForUpdate(handleBinaryVersionMismatchCallback = null) {
|
|
|
217
255
|
|
|
218
256
|
return null;
|
|
219
257
|
} else {
|
|
220
|
-
const
|
|
221
|
-
|
|
258
|
+
const nativeCodePush = requireNativeCodePush("checkForUpdate");
|
|
259
|
+
const packageMixins = requirePackageMixins("checkForUpdate");
|
|
260
|
+
const remotePackage = { ...update, ...packageMixins.remote() };
|
|
261
|
+
remotePackage.failedInstall = await nativeCodePush.isFailedUpdate(remotePackage.packageHash);
|
|
222
262
|
return remotePackage;
|
|
223
263
|
}
|
|
224
264
|
}
|
|
@@ -247,18 +287,24 @@ function mapToRemotePackageMetadata(updateInfo) {
|
|
|
247
287
|
packageHash: updateInfo.package_hash ?? '',
|
|
248
288
|
packageSize: updateInfo.package_size ?? 0,
|
|
249
289
|
downloadUrl: updateInfo.download_url ?? '',
|
|
290
|
+
// The field stays out of the package unless the update really has a binary patch,
|
|
291
|
+
// so that the native side sees exactly what it saw before patches existed.
|
|
292
|
+
...(updateInfo.binary_patch_download_url
|
|
293
|
+
? { binaryPatchDownloadUrl: updateInfo.binary_patch_download_url }
|
|
294
|
+
: {}),
|
|
250
295
|
};
|
|
251
296
|
}
|
|
252
297
|
|
|
253
298
|
const getConfiguration = (() => {
|
|
254
299
|
let config;
|
|
255
|
-
return async function getConfiguration() {
|
|
300
|
+
return async function getConfiguration(callerName = "getConfiguration") {
|
|
256
301
|
if (config) {
|
|
257
302
|
return config;
|
|
258
303
|
} else if (testConfig) {
|
|
259
304
|
return testConfig;
|
|
260
305
|
} else {
|
|
261
|
-
|
|
306
|
+
const nativeCodePush = requireNativeCodePush(callerName);
|
|
307
|
+
config = await nativeCodePush.getConfiguration();
|
|
262
308
|
return config;
|
|
263
309
|
}
|
|
264
310
|
}
|
|
@@ -269,11 +315,13 @@ async function getCurrentPackage() {
|
|
|
269
315
|
}
|
|
270
316
|
|
|
271
317
|
async function getUpdateMetadata(updateState) {
|
|
272
|
-
|
|
318
|
+
const nativeCodePush = requireNativeCodePush("getUpdateMetadata");
|
|
319
|
+
const packageMixins = requirePackageMixins("getUpdateMetadata");
|
|
320
|
+
let updateMetadata = await nativeCodePush.getUpdateMetadata(updateState || CodePush.UpdateState.RUNNING);
|
|
273
321
|
if (updateMetadata) {
|
|
274
|
-
updateMetadata = { ...
|
|
275
|
-
updateMetadata.failedInstall = await
|
|
276
|
-
updateMetadata.isFirstRun = await
|
|
322
|
+
updateMetadata = { ...packageMixins.local, ...updateMetadata };
|
|
323
|
+
updateMetadata.failedInstall = await nativeCodePush.isFailedUpdate(updateMetadata.packageHash);
|
|
324
|
+
updateMetadata.isFirstRun = await nativeCodePush.isFirstRun(updateMetadata.packageHash);
|
|
277
325
|
}
|
|
278
326
|
return updateMetadata;
|
|
279
327
|
}
|
|
@@ -292,14 +340,21 @@ const notifyApplicationReady = (() => {
|
|
|
292
340
|
})();
|
|
293
341
|
|
|
294
342
|
async function notifyApplicationReadyInternal() {
|
|
295
|
-
|
|
296
|
-
|
|
343
|
+
const nativeCodePush = requireNativeCodePush("notifyApplicationReady");
|
|
344
|
+
await nativeCodePush.notifyApplicationReady();
|
|
345
|
+
const statusReport = await nativeCodePush.getNewStatusReport();
|
|
297
346
|
statusReport && tryReportStatus(statusReport); // Don't wait for this to complete.
|
|
298
347
|
|
|
299
348
|
return statusReport;
|
|
300
349
|
}
|
|
301
350
|
|
|
302
351
|
async function tryReportStatus(statusReport, retryOnAppResume) {
|
|
352
|
+
const nativeCodePush = getNativeCodePush();
|
|
353
|
+
if (!nativeCodePush) {
|
|
354
|
+
retryOnAppResume && retryOnAppResume.remove();
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
|
|
303
358
|
try {
|
|
304
359
|
if (statusReport.appVersion) {
|
|
305
360
|
log(`Reporting binary update (${statusReport.appVersion})`);
|
|
@@ -310,22 +365,27 @@ async function tryReportStatus(statusReport, retryOnAppResume) {
|
|
|
310
365
|
sharedCodePushOptions?.onUpdateSuccess?.(label);
|
|
311
366
|
} else {
|
|
312
367
|
log(`Reporting CodePush update rollback (${label})`);
|
|
313
|
-
await
|
|
368
|
+
await nativeCodePush.setLatestRollbackInfo(statusReport.package.packageHash);
|
|
314
369
|
sharedCodePushOptions?.onUpdateRollback?.(label);
|
|
315
370
|
}
|
|
316
371
|
}
|
|
317
372
|
|
|
318
|
-
|
|
373
|
+
nativeCodePush.recordStatusReported(statusReport);
|
|
319
374
|
retryOnAppResume && retryOnAppResume.remove();
|
|
320
375
|
} catch (e) {
|
|
321
376
|
log(`${e}`)
|
|
322
377
|
log(`Report status failed: ${JSON.stringify(statusReport)}`);
|
|
323
|
-
|
|
378
|
+
nativeCodePush.saveStatusReportForRetry(statusReport);
|
|
324
379
|
// Try again when the app resumes
|
|
325
380
|
if (!retryOnAppResume) {
|
|
326
381
|
const resumeListener = AppState.addEventListener("change", async (newState) => {
|
|
327
382
|
if (newState !== "active") return;
|
|
328
|
-
const
|
|
383
|
+
const refreshedNativeCodePush = getNativeCodePush();
|
|
384
|
+
if (!refreshedNativeCodePush) {
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const refreshedStatusReport = await refreshedNativeCodePush.getNewStatusReport();
|
|
329
389
|
if (refreshedStatusReport) {
|
|
330
390
|
tryReportStatus(refreshedStatusReport, resumeListener);
|
|
331
391
|
} else {
|
|
@@ -358,7 +418,8 @@ async function shouldUpdateBeIgnored(remotePackage, syncOptions) {
|
|
|
358
418
|
return true;
|
|
359
419
|
}
|
|
360
420
|
|
|
361
|
-
const
|
|
421
|
+
const nativeCodePush = requireNativeCodePush("shouldUpdateBeIgnored");
|
|
422
|
+
const latestRollbackInfo = await nativeCodePush.getLatestRollbackInfo();
|
|
362
423
|
if (!validateLatestRollbackInfo(latestRollbackInfo, remotePackage.packageHash)) {
|
|
363
424
|
log("The latest rollback info is not valid.");
|
|
364
425
|
return true;
|
|
@@ -407,11 +468,15 @@ let testConfig;
|
|
|
407
468
|
function setUpTestDependencies(testSdk, providedTestConfig, testNativeBridge) {
|
|
408
469
|
if (testSdk) module.exports.AcquisitionSdk = testSdk;
|
|
409
470
|
if (providedTestConfig) testConfig = providedTestConfig;
|
|
410
|
-
if (testNativeBridge)
|
|
471
|
+
if (testNativeBridge) {
|
|
472
|
+
NativeCodePush = testNativeBridge;
|
|
473
|
+
PackageMixins = require("./package-mixins")(NativeCodePush);
|
|
474
|
+
}
|
|
411
475
|
}
|
|
412
476
|
|
|
413
477
|
async function restartApp(onlyIfUpdateIsPending = false) {
|
|
414
|
-
|
|
478
|
+
const nativeCodePush = requireNativeCodePush("restartApp");
|
|
479
|
+
nativeCodePush.restartApp(onlyIfUpdateIsPending);
|
|
415
480
|
}
|
|
416
481
|
|
|
417
482
|
// This function allows only one syncInternal operation to proceed at any given time.
|
|
@@ -478,9 +543,28 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg
|
|
|
478
543
|
mandatoryInstallMode: CodePush.InstallMode.IMMEDIATE,
|
|
479
544
|
minimumBackgroundDuration: 0,
|
|
480
545
|
updateDialog: null,
|
|
546
|
+
// The callback registered on the decorator is the default for every sync, including a
|
|
547
|
+
// manual one; a callback passed to this call overrides it for this call.
|
|
548
|
+
onBinaryPatchResult: sharedCodePushOptions.onBinaryPatchResult ?? null,
|
|
481
549
|
...options,
|
|
482
550
|
};
|
|
483
551
|
|
|
552
|
+
/*
|
|
553
|
+
* A callback an app registered to observe how a binary patch went must not be able to
|
|
554
|
+
* cost it an update, so it is isolated the way the other sync callbacks are: whatever it
|
|
555
|
+
* throws is logged and the install carries on. An app that registered none leaves the
|
|
556
|
+
* download exactly as it was before this option existed.
|
|
557
|
+
*/
|
|
558
|
+
const onBinaryPatchResult = typeof syncOptions.onBinaryPatchResult === "function"
|
|
559
|
+
? (label, result) => {
|
|
560
|
+
try {
|
|
561
|
+
syncOptions.onBinaryPatchResult(label, result);
|
|
562
|
+
} catch (error) {
|
|
563
|
+
log(`An error has occurred : ${error.stack}`);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
: null;
|
|
567
|
+
|
|
484
568
|
syncStatusChangeCallback = typeof syncStatusChangeCallback === "function"
|
|
485
569
|
? syncStatusChangeCallback
|
|
486
570
|
: (syncStatus) => {
|
|
@@ -532,7 +616,10 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg
|
|
|
532
616
|
syncStatusChangeCallback(CodePush.SyncStatus.DOWNLOADING_PACKAGE);
|
|
533
617
|
sharedCodePushOptions.onDownloadStart?.(remotePackageLabel);
|
|
534
618
|
|
|
535
|
-
const localPackage = await remotePackage.download(
|
|
619
|
+
const localPackage = await remotePackage.download(
|
|
620
|
+
downloadProgressCallback,
|
|
621
|
+
onBinaryPatchResult && ((result) => onBinaryPatchResult(remotePackageLabel, result)),
|
|
622
|
+
);
|
|
536
623
|
|
|
537
624
|
sharedCodePushOptions.onDownloadSuccess?.(remotePackageLabel);
|
|
538
625
|
|
|
@@ -666,6 +753,9 @@ let CodePush;
|
|
|
666
753
|
*
|
|
667
754
|
* onRolloutSkipped: (label: string, error: Error) => void | undefined,
|
|
668
755
|
* setOnRolloutSkipped(onRolloutSkippedFunction: (label: string, error: Error) => void | undefined): void,
|
|
756
|
+
*
|
|
757
|
+
* onBinaryPatchResult: (label: string, result: object) => void | undefined,
|
|
758
|
+
* setOnBinaryPatchResult(onBinaryPatchResultFunction: (label: string, result: object) => void | undefined): void,
|
|
669
759
|
* }}
|
|
670
760
|
*/
|
|
671
761
|
const sharedCodePushOptions = {
|
|
@@ -716,6 +806,12 @@ const sharedCodePushOptions = {
|
|
|
716
806
|
if (typeof onRolloutSkippedFunction !== 'function') throw new Error('Please pass a function to onRolloutSkipped');
|
|
717
807
|
this.onRolloutSkipped = onRolloutSkippedFunction;
|
|
718
808
|
},
|
|
809
|
+
onBinaryPatchResult: undefined,
|
|
810
|
+
setOnBinaryPatchResult(onBinaryPatchResultFunction) {
|
|
811
|
+
if (!onBinaryPatchResultFunction) return;
|
|
812
|
+
if (typeof onBinaryPatchResultFunction !== 'function') throw new Error('Please pass a function to onBinaryPatchResult');
|
|
813
|
+
this.onBinaryPatchResult = onBinaryPatchResultFunction;
|
|
814
|
+
},
|
|
719
815
|
}
|
|
720
816
|
|
|
721
817
|
function codePushify(options = {}) {
|
|
@@ -752,6 +848,7 @@ function codePushify(options = {}) {
|
|
|
752
848
|
sharedCodePushOptions.setOnDownloadSuccess(options.onDownloadSuccess);
|
|
753
849
|
sharedCodePushOptions.setOnSyncError(options.onSyncError);
|
|
754
850
|
sharedCodePushOptions.setOnRolloutSkipped(options.onRolloutSkipped);
|
|
851
|
+
sharedCodePushOptions.setOnBinaryPatchResult(options.onBinaryPatchResult);
|
|
755
852
|
|
|
756
853
|
const decorator = (RootComponent) => {
|
|
757
854
|
class CodePushComponent extends React.Component {
|
|
@@ -817,76 +914,73 @@ function codePushify(options = {}) {
|
|
|
817
914
|
}
|
|
818
915
|
}
|
|
819
916
|
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
} else {
|
|
889
|
-
log("The CodePush module doesn't appear to be properly installed. Please double-check that everything is setup correctly.");
|
|
890
|
-
}
|
|
917
|
+
CodePush = codePushify;
|
|
918
|
+
Object.assign(CodePush, {
|
|
919
|
+
checkForUpdate,
|
|
920
|
+
getConfiguration,
|
|
921
|
+
getCurrentPackage,
|
|
922
|
+
getUpdateMetadata,
|
|
923
|
+
log,
|
|
924
|
+
notifyAppReady: notifyApplicationReady,
|
|
925
|
+
notifyApplicationReady,
|
|
926
|
+
restartApp,
|
|
927
|
+
setUpTestDependencies,
|
|
928
|
+
sync,
|
|
929
|
+
disallowRestart: () => {
|
|
930
|
+
const nativeCodePush = requireNativeCodePush("disallowRestart");
|
|
931
|
+
return nativeCodePush.disallow();
|
|
932
|
+
},
|
|
933
|
+
allowRestart: () => {
|
|
934
|
+
const nativeCodePush = requireNativeCodePush("allowRestart");
|
|
935
|
+
return nativeCodePush.allow();
|
|
936
|
+
},
|
|
937
|
+
clearUpdates: () => {
|
|
938
|
+
const nativeCodePush = requireNativeCodePush("clearUpdates");
|
|
939
|
+
return nativeCodePush.clearUpdates();
|
|
940
|
+
},
|
|
941
|
+
InstallMode: {
|
|
942
|
+
IMMEDIATE: InstallMode.IMMEDIATE, // Restart the app immediately
|
|
943
|
+
ON_NEXT_RESTART: InstallMode.ON_NEXT_RESTART, // Don't artificially restart the app. Allow the update to be "picked up" on the next app restart
|
|
944
|
+
ON_NEXT_RESUME: InstallMode.ON_NEXT_RESUME, // Restart the app the next time it is resumed from the background
|
|
945
|
+
ON_NEXT_SUSPEND: InstallMode.ON_NEXT_SUSPEND, // Restart the app _while_ it is in the background,
|
|
946
|
+
// but only after it has been in the background for "minimumBackgroundDuration" seconds (0 by default),
|
|
947
|
+
// so that user context isn't lost unless the app suspension is long enough to not matter
|
|
948
|
+
},
|
|
949
|
+
SyncStatus: {
|
|
950
|
+
UP_TO_DATE: 0, // The running app is up-to-date
|
|
951
|
+
UPDATE_INSTALLED: 1, // The app had an optional/mandatory update that was successfully downloaded and is about to be installed.
|
|
952
|
+
UPDATE_IGNORED: 2, // The app had an optional update and the end-user chose to ignore it
|
|
953
|
+
UNKNOWN_ERROR: 3,
|
|
954
|
+
SYNC_IN_PROGRESS: 4, // There is an ongoing "sync" operation in progress.
|
|
955
|
+
CHECKING_FOR_UPDATE: 5,
|
|
956
|
+
AWAITING_USER_ACTION: 6,
|
|
957
|
+
DOWNLOADING_PACKAGE: 7,
|
|
958
|
+
INSTALLING_UPDATE: 8,
|
|
959
|
+
},
|
|
960
|
+
CheckFrequency: {
|
|
961
|
+
ON_APP_START: 0,
|
|
962
|
+
ON_APP_RESUME: 1,
|
|
963
|
+
MANUAL: 2,
|
|
964
|
+
},
|
|
965
|
+
UpdateState,
|
|
966
|
+
DeploymentStatus: {
|
|
967
|
+
FAILED: "DeploymentFailed",
|
|
968
|
+
SUCCEEDED: "DeploymentSucceeded",
|
|
969
|
+
},
|
|
970
|
+
DEFAULT_UPDATE_DIALOG: {
|
|
971
|
+
appendReleaseDescription: false,
|
|
972
|
+
descriptionPrefix: " Description: ",
|
|
973
|
+
mandatoryContinueButtonLabel: "Continue",
|
|
974
|
+
mandatoryUpdateMessage: "An update is available that must be installed.",
|
|
975
|
+
optionalIgnoreButtonLabel: "Ignore",
|
|
976
|
+
optionalInstallButtonLabel: "Install",
|
|
977
|
+
optionalUpdateMessage: "An update is available. Would you like to install it?",
|
|
978
|
+
title: "Update available",
|
|
979
|
+
},
|
|
980
|
+
DEFAULT_ROLLBACK_RETRY_OPTIONS: {
|
|
981
|
+
delayInHours: 24,
|
|
982
|
+
maxRetryAttempts: 1,
|
|
983
|
+
},
|
|
984
|
+
});
|
|
891
985
|
|
|
892
986
|
module.exports = CodePush;
|