@bravemobile/react-native-code-push 9.0.0-beta.1 → 9.0.0-beta.3
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 +113 -71
- package/package.json +1 -1
- package/typings/react-native-code-push.d.ts +17 -0
package/CodePush.js
CHANGED
|
@@ -61,85 +61,78 @@ 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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
86
|
+
const versioning = new SemverVersioning(releaseHistory);
|
|
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
|
+
}
|
|
85
95
|
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
log(`An error has occurred at update checker
|
|
134
|
+
log(`An error has occurred at update checker :`);
|
|
135
|
+
console.error(error)
|
|
143
136
|
// update will not happen
|
|
144
137
|
return undefined;
|
|
145
138
|
}
|
|
@@ -182,6 +175,34 @@ async function checkForUpdate(deploymentKey = null, handleBinaryVersionMismatchC
|
|
|
182
175
|
}
|
|
183
176
|
}
|
|
184
177
|
|
|
178
|
+
/**
|
|
179
|
+
* @param updateInfo {UpdateCheckResponse}
|
|
180
|
+
* @param deploymentKey {string}
|
|
181
|
+
* @return {RemotePackage | null}
|
|
182
|
+
*/
|
|
183
|
+
function mapToRemotePackageMetadata(updateInfo, deploymentKey) {
|
|
184
|
+
if (!updateInfo) {
|
|
185
|
+
return null;
|
|
186
|
+
} else if (!updateInfo.download_url) {
|
|
187
|
+
log("download_url is missed in the release history.");
|
|
188
|
+
return null;
|
|
189
|
+
} else if (!updateInfo.is_available) {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// refer to `RemotePackage` type inside code-push SDK
|
|
194
|
+
return {
|
|
195
|
+
deploymentKey: deploymentKey,
|
|
196
|
+
description: updateInfo.description ?? '',
|
|
197
|
+
label: updateInfo.label ?? '',
|
|
198
|
+
appVersion: updateInfo.target_binary_range ?? '',
|
|
199
|
+
isMandatory: updateInfo.is_mandatory ?? false,
|
|
200
|
+
packageHash: updateInfo.package_hash ?? '',
|
|
201
|
+
packageSize: updateInfo.package_size ?? 0,
|
|
202
|
+
downloadUrl: updateInfo.download_url ?? '',
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
185
206
|
const getConfiguration = (() => {
|
|
186
207
|
let config;
|
|
187
208
|
return async function getConfiguration() {
|
|
@@ -560,19 +581,35 @@ let CodePush;
|
|
|
560
581
|
* @returns {Promise<ReleaseHistoryInterface>} The release history of the updates deployed for a specific binary version.
|
|
561
582
|
*/
|
|
562
583
|
|
|
584
|
+
/**
|
|
585
|
+
* @callback updateChecker
|
|
586
|
+
* @param {UpdateCheckRequest} updateRequest Current package information to check for updates.
|
|
587
|
+
* @returns {Promise<{update_info: UpdateCheckResponse}>} The result of the update check. Follows the AppCenter API response interface.
|
|
588
|
+
*
|
|
589
|
+
* @deprecated It will be removed in the next major version.
|
|
590
|
+
*/
|
|
591
|
+
|
|
563
592
|
/**
|
|
564
593
|
* If you pass options once when calling `codePushify`, they will be shared with related functions.
|
|
565
594
|
* @type {{
|
|
566
595
|
* releaseHistoryFetcher: releaseHistoryFetcher | undefined,
|
|
567
|
-
* setReleaseHistoryFetcher(releaseHistoryFetcherFunction: releaseHistoryFetcher): void,
|
|
596
|
+
* setReleaseHistoryFetcher(releaseHistoryFetcherFunction: releaseHistoryFetcher | undefined): void,
|
|
597
|
+
* updateChecker: updateChecker | undefined,
|
|
598
|
+
* setUpdateChecker(updateCheckerFunction: updateChecker | undefined): void,
|
|
568
599
|
* }}
|
|
569
600
|
*/
|
|
570
601
|
const sharedCodePushOptions = {
|
|
571
602
|
releaseHistoryFetcher: undefined,
|
|
572
603
|
setReleaseHistoryFetcher(releaseHistoryFetcherFunction) {
|
|
573
|
-
if (!releaseHistoryFetcherFunction || typeof releaseHistoryFetcherFunction !== 'function') throw new Error('
|
|
604
|
+
if (!releaseHistoryFetcherFunction || typeof releaseHistoryFetcherFunction !== 'function') throw new Error('Please implement the releaseHistoryFetcher function');
|
|
574
605
|
this.releaseHistoryFetcher = releaseHistoryFetcherFunction;
|
|
575
|
-
}
|
|
606
|
+
},
|
|
607
|
+
updateChecker: undefined,
|
|
608
|
+
setUpdateChecker(updateCheckerFunction) {
|
|
609
|
+
if (!updateCheckerFunction) return;
|
|
610
|
+
if (typeof updateCheckerFunction !== 'function') throw new Error('Please pass a function to updateChecker');
|
|
611
|
+
this.updateChecker = updateCheckerFunction;
|
|
612
|
+
},
|
|
576
613
|
}
|
|
577
614
|
|
|
578
615
|
function codePushify(options = {}) {
|
|
@@ -595,7 +632,12 @@ function codePushify(options = {}) {
|
|
|
595
632
|
);
|
|
596
633
|
}
|
|
597
634
|
|
|
635
|
+
if (options.updateChecker && !options.releaseHistoryFetcher) {
|
|
636
|
+
throw new Error('If you want to use `updateChecker`, pass a no-op function to releaseHistoryFetcher option. (e.g. `releaseHistoryFetcher: async () => ({})`)');
|
|
637
|
+
}
|
|
638
|
+
|
|
598
639
|
sharedCodePushOptions.setReleaseHistoryFetcher(options.releaseHistoryFetcher);
|
|
640
|
+
sharedCodePushOptions.setUpdateChecker(options.updateChecker);
|
|
599
641
|
|
|
600
642
|
const decorator = (RootComponent) => {
|
|
601
643
|
class CodePushComponent extends React.Component {
|
package/package.json
CHANGED
|
@@ -56,8 +56,25 @@ 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 like below.
|
|
61
|
+
* But it is deprecated and will be removed in the next major version.
|
|
62
|
+
*
|
|
63
|
+
* ```ts
|
|
64
|
+
* const codePushOptions: {
|
|
65
|
+
* releaseHistoryFetcher: async () => ({}), // This will not be called
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
59
68
|
*/
|
|
60
69
|
releaseHistoryFetcher: (updateRequest: UpdateCheckRequest) => Promise<ReleaseHistoryInterface>;
|
|
70
|
+
/**
|
|
71
|
+
* Specify a function to perform the update check.
|
|
72
|
+
* It can be used for self-hosting.
|
|
73
|
+
* Defaults to AppCenter update_check REST API request.
|
|
74
|
+
*
|
|
75
|
+
* @deprecated It will be removed in the next major version. Please migrate to `releaseHistoryFetcher`.
|
|
76
|
+
*/
|
|
77
|
+
updateChecker?: (updateRequest: UpdateCheckRequest) => Promise<{ update_info: UpdateCheckResponse }>;
|
|
61
78
|
}
|
|
62
79
|
|
|
63
80
|
export interface DownloadProgress {
|