@bravemobile/react-native-code-push 9.0.0-beta.1 → 9.0.0-beta.2
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.js +107 -70
- package/package.json +1 -1
- package/typings/react-native-code-push.d.ts +10 -0
package/CodePush.js
CHANGED
|
@@ -61,83 +61,75 @@ async function checkForUpdate(deploymentKey = null, handleBinaryVersionMismatchC
|
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
|
-
*
|
|
65
|
-
* @
|
|
64
|
+
* @type {updateChecker|undefined}
|
|
65
|
+
* @deprecated
|
|
66
66
|
*/
|
|
67
|
-
const
|
|
67
|
+
const updateChecker = sharedCodePushOptions.updateChecker;
|
|
68
|
+
if (updateChecker) {
|
|
69
|
+
const { update_info } = await updateChecker(updateRequest);
|
|
68
70
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
return mapToRemotePackageMetadata(update_info, config.deploymentKey);
|
|
72
|
+
} else {
|
|
73
|
+
/**
|
|
74
|
+
* `releaseHistory`
|
|
75
|
+
* @type {ReleaseHistoryInterface}
|
|
76
|
+
*/
|
|
77
|
+
const releaseHistory = await sharedCodePushOptions.releaseHistoryFetcher(updateRequest);
|
|
75
78
|
|
|
76
|
-
|
|
79
|
+
/**
|
|
80
|
+
* `runtimeVersion`
|
|
81
|
+
* The version of currently running CodePush update. (It can be undefined if the app is running without CodePush update.)
|
|
82
|
+
* @type {string|undefined}
|
|
83
|
+
*/
|
|
84
|
+
const runtimeVersion = updateRequest.label;
|
|
77
85
|
|
|
78
|
-
|
|
79
|
-
if (shouldRollbackToBinary) {
|
|
80
|
-
// Reset to latest major version and restart
|
|
81
|
-
CodePush.clearUpdates();
|
|
82
|
-
CodePush.allowRestart();
|
|
83
|
-
CodePush.restartApp();
|
|
84
|
-
}
|
|
86
|
+
const versioning = new SemverVersioning(releaseHistory);
|
|
85
87
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
const shouldRollbackToBinary = versioning.shouldRollbackToBinary(runtimeVersion)
|
|
89
|
+
if (shouldRollbackToBinary) {
|
|
90
|
+
// Reset to latest major version and restart
|
|
91
|
+
CodePush.clearUpdates();
|
|
92
|
+
CodePush.allowRestart();
|
|
93
|
+
CodePush.restartApp();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const [latestVersion, latestReleaseInfo] = versioning.findLatestRelease();
|
|
97
|
+
const isMandatory = versioning.checkIsMandatory(runtimeVersion);
|
|
88
98
|
|
|
89
|
-
/**
|
|
90
|
-
* Convert the update information decided from `ReleaseHistoryInterface` to be passed to the library core (original CodePush library).
|
|
91
|
-
*
|
|
92
|
-
* @type {UpdateCheckResponse} the interface required by the original CodePush library.
|
|
93
|
-
*/
|
|
94
|
-
const updateInfo = {
|
|
95
|
-
download_url: latestReleaseInfo.downloadUrl,
|
|
96
|
-
// (`enabled` will always be true in the release information obtained from the previous process.)
|
|
97
|
-
is_available: latestReleaseInfo.enabled,
|
|
98
|
-
package_hash: latestReleaseInfo.packageHash,
|
|
99
|
-
is_mandatory: isMandatory,
|
|
100
|
-
// 이건 항상 현재 실행중인 바이너리 버전을 전달한다.
|
|
101
|
-
// 조회한 업데이트가 현재 바이너리를 타겟하는가? 를 API 서버에서 판단한 다음, 해당 된다면 런타임 바이너리 버전을 그대로 돌려주던 것임.
|
|
102
|
-
// 우리는 updateChecker 조회 결과가 넘어왔다면 해당 정보는 현재 런타임 바이너리에 호환됨을 전제로 하고있음.
|
|
103
|
-
target_binary_range: updateRequest.app_version,
|
|
104
99
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
100
|
+
* Convert the update information decided from `ReleaseHistoryInterface` to be passed to the library core (original CodePush library).
|
|
101
|
+
*
|
|
102
|
+
* @type {UpdateCheckResponse} the interface required by the original CodePush library.
|
|
107
103
|
*/
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
104
|
+
const updateInfo = {
|
|
105
|
+
download_url: latestReleaseInfo.downloadUrl,
|
|
106
|
+
// (`enabled` will always be true in the release information obtained from the previous process.)
|
|
107
|
+
is_available: latestReleaseInfo.enabled,
|
|
108
|
+
package_hash: latestReleaseInfo.packageHash,
|
|
109
|
+
is_mandatory: isMandatory,
|
|
110
|
+
// 이건 항상 현재 실행중인 바이너리 버전을 전달한다.
|
|
111
|
+
// 조회한 업데이트가 현재 바이너리를 타겟하는가? 를 API 서버에서 판단한 다음, 해당 된다면 런타임 바이너리 버전을 그대로 돌려주던 것임.
|
|
112
|
+
// 우리는 updateChecker 조회 결과가 넘어왔다면 해당 정보는 현재 런타임 바이너리에 호환됨을 전제로 하고있음.
|
|
113
|
+
target_binary_range: updateRequest.app_version,
|
|
114
|
+
/**
|
|
115
|
+
* Retrieve the update version from the ReleaseHistory and store it in the label.
|
|
116
|
+
* This information can be accessed at runtime through the CodePush bundle metadata.
|
|
117
|
+
*/
|
|
118
|
+
label: latestVersion,
|
|
119
|
+
// false 전달해야 정상 동작함
|
|
120
|
+
update_app_version: false,
|
|
121
|
+
// 그닥 쓸모 없음
|
|
122
|
+
description: '',
|
|
123
|
+
// 런타임에 안쓰임
|
|
124
|
+
is_disabled: false,
|
|
125
|
+
// 런타임에 안쓰임
|
|
126
|
+
package_size: 0,
|
|
127
|
+
// 런타임에 안쓰임
|
|
128
|
+
should_run_binary_version: false,
|
|
129
|
+
}
|
|
121
130
|
|
|
122
|
-
|
|
123
|
-
return null;
|
|
124
|
-
} else if (!updateInfo.download_url) {
|
|
125
|
-
return null;
|
|
126
|
-
} else if (!updateInfo.is_available) {
|
|
127
|
-
return null;
|
|
131
|
+
return mapToRemotePackageMetadata(updateInfo, config.deploymentKey);
|
|
128
132
|
}
|
|
129
|
-
|
|
130
|
-
// refer to `RemotePackage` type inside code-push SDK
|
|
131
|
-
return {
|
|
132
|
-
deploymentKey: config.deploymentKey,
|
|
133
|
-
description: updateInfo.description ?? '',
|
|
134
|
-
label: updateInfo.label ?? '',
|
|
135
|
-
appVersion: updateInfo.target_binary_range ?? '',
|
|
136
|
-
isMandatory: updateInfo.is_mandatory ?? false,
|
|
137
|
-
packageHash: updateInfo.package_hash ?? '',
|
|
138
|
-
packageSize: updateInfo.package_size ?? 0,
|
|
139
|
-
downloadUrl: updateInfo.download_url ?? '',
|
|
140
|
-
};
|
|
141
133
|
} catch (error) {
|
|
142
134
|
log(`An error has occurred at update checker :`, error);
|
|
143
135
|
// update will not happen
|
|
@@ -182,6 +174,34 @@ async function checkForUpdate(deploymentKey = null, handleBinaryVersionMismatchC
|
|
|
182
174
|
}
|
|
183
175
|
}
|
|
184
176
|
|
|
177
|
+
/**
|
|
178
|
+
* @param updateInfo {UpdateCheckResponse}
|
|
179
|
+
* @param deploymentKey {string}
|
|
180
|
+
* @return {RemotePackage | null}
|
|
181
|
+
*/
|
|
182
|
+
function mapToRemotePackageMetadata(updateInfo, deploymentKey) {
|
|
183
|
+
if (!updateInfo) {
|
|
184
|
+
return null;
|
|
185
|
+
} else if (!updateInfo.download_url) {
|
|
186
|
+
log("download_url is missed in the release history.");
|
|
187
|
+
return null;
|
|
188
|
+
} else if (!updateInfo.is_available) {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// refer to `RemotePackage` type inside code-push SDK
|
|
193
|
+
return {
|
|
194
|
+
deploymentKey: deploymentKey,
|
|
195
|
+
description: updateInfo.description ?? '',
|
|
196
|
+
label: updateInfo.label ?? '',
|
|
197
|
+
appVersion: updateInfo.target_binary_range ?? '',
|
|
198
|
+
isMandatory: updateInfo.is_mandatory ?? false,
|
|
199
|
+
packageHash: updateInfo.package_hash ?? '',
|
|
200
|
+
packageSize: updateInfo.package_size ?? 0,
|
|
201
|
+
downloadUrl: updateInfo.download_url ?? '',
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
185
205
|
const getConfiguration = (() => {
|
|
186
206
|
let config;
|
|
187
207
|
return async function getConfiguration() {
|
|
@@ -560,19 +580,35 @@ let CodePush;
|
|
|
560
580
|
* @returns {Promise<ReleaseHistoryInterface>} The release history of the updates deployed for a specific binary version.
|
|
561
581
|
*/
|
|
562
582
|
|
|
583
|
+
/**
|
|
584
|
+
* @callback updateChecker
|
|
585
|
+
* @param {UpdateCheckRequest} updateRequest Current package information to check for updates.
|
|
586
|
+
* @returns {Promise<{update_info: UpdateCheckResponse}>} The result of the update check. Follows the AppCenter API response interface.
|
|
587
|
+
*
|
|
588
|
+
* @deprecated It will be removed in the next major version.
|
|
589
|
+
*/
|
|
590
|
+
|
|
563
591
|
/**
|
|
564
592
|
* If you pass options once when calling `codePushify`, they will be shared with related functions.
|
|
565
593
|
* @type {{
|
|
566
594
|
* releaseHistoryFetcher: releaseHistoryFetcher | undefined,
|
|
567
|
-
* setReleaseHistoryFetcher(releaseHistoryFetcherFunction: releaseHistoryFetcher): void,
|
|
595
|
+
* setReleaseHistoryFetcher(releaseHistoryFetcherFunction: releaseHistoryFetcher | undefined): void,
|
|
596
|
+
* updateChecker: updateChecker | undefined,
|
|
597
|
+
* setUpdateChecker(updateCheckerFunction: updateChecker | undefined): void,
|
|
568
598
|
* }}
|
|
569
599
|
*/
|
|
570
600
|
const sharedCodePushOptions = {
|
|
571
601
|
releaseHistoryFetcher: undefined,
|
|
572
602
|
setReleaseHistoryFetcher(releaseHistoryFetcherFunction) {
|
|
573
|
-
if (!releaseHistoryFetcherFunction || typeof releaseHistoryFetcherFunction !== 'function') throw new Error('
|
|
603
|
+
if (!releaseHistoryFetcherFunction || typeof releaseHistoryFetcherFunction !== 'function') throw new Error('Please implement the releaseHistoryFetcher function');
|
|
574
604
|
this.releaseHistoryFetcher = releaseHistoryFetcherFunction;
|
|
575
|
-
}
|
|
605
|
+
},
|
|
606
|
+
updateChecker: undefined,
|
|
607
|
+
setUpdateChecker(updateCheckerFunction) {
|
|
608
|
+
if (!updateCheckerFunction) return;
|
|
609
|
+
if (typeof updateCheckerFunction !== 'function') throw new Error('Please pass a function to updateChecker');
|
|
610
|
+
this.updateChecker = updateCheckerFunction;
|
|
611
|
+
},
|
|
576
612
|
}
|
|
577
613
|
|
|
578
614
|
function codePushify(options = {}) {
|
|
@@ -596,6 +632,7 @@ function codePushify(options = {}) {
|
|
|
596
632
|
}
|
|
597
633
|
|
|
598
634
|
sharedCodePushOptions.setReleaseHistoryFetcher(options.releaseHistoryFetcher);
|
|
635
|
+
sharedCodePushOptions.setUpdateChecker(options.updateChecker);
|
|
599
636
|
|
|
600
637
|
const decorator = (RootComponent) => {
|
|
601
638
|
class CodePushComponent extends React.Component {
|
package/package.json
CHANGED
|
@@ -56,8 +56,18 @@ export interface CodePushOptions extends SyncOptions {
|
|
|
56
56
|
checkFrequency: CodePush.CheckFrequency;
|
|
57
57
|
/**
|
|
58
58
|
* Specifies a function to get the release history.
|
|
59
|
+
*
|
|
60
|
+
* (If you want to use `updateChecker`, pass no-op function.)
|
|
59
61
|
*/
|
|
60
62
|
releaseHistoryFetcher: (updateRequest: UpdateCheckRequest) => Promise<ReleaseHistoryInterface>;
|
|
63
|
+
/**
|
|
64
|
+
* Specify a function to perform the update check.
|
|
65
|
+
* It can be used for self-hosting.
|
|
66
|
+
* Defaults to AppCenter update_check REST API request.
|
|
67
|
+
*
|
|
68
|
+
* @deprecated It will be removed in the next major version. Please migrate to `releaseHistoryFetcher`.
|
|
69
|
+
*/
|
|
70
|
+
updateChecker?: (updateRequest: UpdateCheckRequest) => Promise<{ update_info: UpdateCheckResponse }>;
|
|
61
71
|
}
|
|
62
72
|
|
|
63
73
|
export interface DownloadProgress {
|