@gfean/react-native-bundle-drop 0.2.2 → 0.3.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/CLIENT_README.md +47 -17
- package/README.md +45 -22
- package/lib/CLI/cli.d.ts +2 -1
- package/lib/CLI/cli.js +141 -130
- package/lib/CLI/scripts/init-native-config.d.ts +16 -0
- package/lib/CLI/scripts/init-native-config.js +11 -0
- package/lib/CLI/scripts/login-cli.d.ts +71 -0
- package/lib/CLI/scripts/login-cli.js +24 -13
- package/lib/CLI/scripts/upload-cli.js +2 -1
- package/lib/api/types.d.ts +29 -0
- package/lib/index.d.ts +16 -4
- package/lib/index.js +25 -15
- package/lib/manager/downloadAndInstall.d.ts +2 -0
- package/lib/manager/reporting.js +3 -0
- package/lib/manager/updateCheck.d.ts +13 -0
- package/lib/manager/updateCheck.js +6 -0
- package/lib/manager/updateState.d.ts +2 -0
- package/lib/manager/updateState.js +10 -4
- package/lib/runtime/initState.d.ts +48 -0
- package/lib/runtime/initState.js +131 -0
- package/lib/runtime/service.d.ts +111 -0
- package/lib/runtime/service.js +537 -0
- package/lib/scripts/bundle.d.ts +13 -1
- package/lib/scripts/bundle.js +126 -115
- package/lib/scripts/download-bundle.d.ts +4 -1
- package/lib/scripts/download-bundle.js +41 -33
- package/lib/scripts/upload-bundle.d.ts +7 -1
- package/lib/scripts/upload-bundle.js +183 -175
- package/lib/useBundleDrop.d.ts +19 -9
- package/lib/useBundleDrop.js +26 -172
- package/package.json +13 -2
- package/lib/manager/initUpdateManager.d.ts +0 -10
- package/lib/manager/initUpdateManager.js +0 -137
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initBundleDrop = initBundleDrop;
|
|
4
|
+
exports.setChannel = setChannel;
|
|
5
|
+
exports.getChannelName = getChannelName;
|
|
6
|
+
exports.subscribeBundleDropState = subscribeBundleDropState;
|
|
7
|
+
exports.getBundleDropSnapshot = getBundleDropSnapshot;
|
|
8
|
+
exports.isUpdateFlowActive = isUpdateFlowActive;
|
|
9
|
+
exports.checkLatest = checkLatest;
|
|
10
|
+
exports.downloadAndStage = downloadAndStage;
|
|
11
|
+
exports.applyDownloadedUpdate = applyDownloadedUpdate;
|
|
12
|
+
exports.fetchAvailableChannels = fetchAvailableChannels;
|
|
13
|
+
exports.fetchAvailableBundles = fetchAvailableBundles;
|
|
14
|
+
exports.installBundleFromListItem = installBundleFromListItem;
|
|
15
|
+
exports.getInstalledBundleInfo = getInstalledBundleInfo;
|
|
16
|
+
exports.getRuntimeUpdateState = getRuntimeUpdateState;
|
|
17
|
+
exports.checkForUpdate = checkForUpdate;
|
|
18
|
+
exports.downloadUpdate = downloadUpdate;
|
|
19
|
+
exports.applyUpdate = applyUpdate;
|
|
20
|
+
exports.getAvailableChannels = getAvailableChannels;
|
|
21
|
+
exports.getAvailableBundles = getAvailableBundles;
|
|
22
|
+
exports.installBundle = installBundle;
|
|
23
|
+
exports.resetBundleDropRuntimeServiceForTests = resetBundleDropRuntimeServiceForTests;
|
|
24
|
+
exports.waitForBundleDropStartupForTests = waitForBundleDropStartupForTests;
|
|
25
|
+
const bundleInfo_1 = require("../bundleInfo");
|
|
26
|
+
const context_1 = require("../context");
|
|
27
|
+
const bundleDropNative_1 = require("../native/bundleDropNative");
|
|
28
|
+
const bundlePointer_1 = require("../fs/bundlePointer");
|
|
29
|
+
const downloadAndInstall_1 = require("../manager/downloadAndInstall");
|
|
30
|
+
const updateCheck_1 = require("../manager/updateCheck");
|
|
31
|
+
const rollbackState_1 = require("../manager/rollbackState");
|
|
32
|
+
const updateState_1 = require("../manager/updateState");
|
|
33
|
+
const initState_1 = require("./initState");
|
|
34
|
+
const DEFAULT_STATUS = 'Click the button to check for updates';
|
|
35
|
+
const DISABLED_STATUS = 'BundleDrop is disabled';
|
|
36
|
+
let updateFlowActive = false;
|
|
37
|
+
let startupPromise = null;
|
|
38
|
+
let snapshot = {
|
|
39
|
+
status: DISABLED_STATUS,
|
|
40
|
+
isBusy: false,
|
|
41
|
+
isEnabled: false,
|
|
42
|
+
channelName: context_1.defaultChannel,
|
|
43
|
+
installedInfo: null,
|
|
44
|
+
pendingApply: false,
|
|
45
|
+
hasBundle: false,
|
|
46
|
+
availableChannels: [],
|
|
47
|
+
};
|
|
48
|
+
const listeners = new Set();
|
|
49
|
+
function emitChange() {
|
|
50
|
+
listeners.forEach(listener => listener());
|
|
51
|
+
}
|
|
52
|
+
function patchSnapshot(partial) {
|
|
53
|
+
snapshot = {
|
|
54
|
+
...snapshot,
|
|
55
|
+
...partial,
|
|
56
|
+
};
|
|
57
|
+
emitChange();
|
|
58
|
+
}
|
|
59
|
+
function setDisabledSnapshot(channelName = snapshot.channelName) {
|
|
60
|
+
patchSnapshot({
|
|
61
|
+
status: DISABLED_STATUS,
|
|
62
|
+
isBusy: false,
|
|
63
|
+
isEnabled: false,
|
|
64
|
+
channelName,
|
|
65
|
+
installedInfo: null,
|
|
66
|
+
pendingApply: false,
|
|
67
|
+
hasBundle: false,
|
|
68
|
+
availableChannels: [],
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function emitStatus(status, extraStatusHandler) {
|
|
72
|
+
patchSnapshot({ status });
|
|
73
|
+
(0, initState_1.getBundleDropRuntimeConfig)()?.onStatusUpdate?.(status);
|
|
74
|
+
extraStatusHandler?.(status);
|
|
75
|
+
}
|
|
76
|
+
function emitDisabledStatus(extraStatusHandler, channelName) {
|
|
77
|
+
setDisabledSnapshot(channelName);
|
|
78
|
+
(0, initState_1.getBundleDropRuntimeConfig)()?.onStatusUpdate?.(DISABLED_STATUS);
|
|
79
|
+
extraStatusHandler?.(DISABLED_STATUS);
|
|
80
|
+
return DISABLED_STATUS;
|
|
81
|
+
}
|
|
82
|
+
function getConfiguredRuntime(extraStatusHandler) {
|
|
83
|
+
const runtime = (0, initState_1.getBundleDropRuntimeConfigOrWarn)();
|
|
84
|
+
if (!runtime) {
|
|
85
|
+
emitDisabledStatus(extraStatusHandler);
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
return runtime;
|
|
89
|
+
}
|
|
90
|
+
function getEnabledRuntime(extraStatusHandler) {
|
|
91
|
+
const runtime = getConfiguredRuntime(extraStatusHandler);
|
|
92
|
+
if (!runtime?.enabled) {
|
|
93
|
+
emitDisabledStatus(extraStatusHandler, runtime?.channelName);
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
return runtime;
|
|
97
|
+
}
|
|
98
|
+
function isSameStatus(current, next) {
|
|
99
|
+
return !!current && current === next;
|
|
100
|
+
}
|
|
101
|
+
function getCheckStatus(response) {
|
|
102
|
+
if (!response)
|
|
103
|
+
return '⚠️ Unable to check for updates. Try again.';
|
|
104
|
+
if (response.action === 'ROLLBACK') {
|
|
105
|
+
if (!response.reason) {
|
|
106
|
+
return '↩️ Rollback requested';
|
|
107
|
+
}
|
|
108
|
+
return `↩️ Rollback requested: ${response.reason}`;
|
|
109
|
+
}
|
|
110
|
+
if (response.incompatible) {
|
|
111
|
+
return '⛔️ No compatible update for this binary';
|
|
112
|
+
}
|
|
113
|
+
if (response.action === 'NOOP') {
|
|
114
|
+
return '✅ You have the latest version';
|
|
115
|
+
}
|
|
116
|
+
return response.bundleVersion
|
|
117
|
+
? `⬇️ Update available (v${response.bundleVersion})`
|
|
118
|
+
: '⬇️ Update available';
|
|
119
|
+
}
|
|
120
|
+
function getDownloadStatus(result) {
|
|
121
|
+
if (result.status === 'upToDate')
|
|
122
|
+
return '✅ You have the latest version';
|
|
123
|
+
if (result.status === 'rollback') {
|
|
124
|
+
if (!result.reason) {
|
|
125
|
+
return '↩️ Rollback requested';
|
|
126
|
+
}
|
|
127
|
+
return `↩️ Rollback requested: ${result.reason}`;
|
|
128
|
+
}
|
|
129
|
+
if (result.status === 'incompatible')
|
|
130
|
+
return '⛔️ No compatible update for this binary';
|
|
131
|
+
return '✅ Update downloaded. Will apply on next launch or when you call applyUpdate.';
|
|
132
|
+
}
|
|
133
|
+
function getApplyStatus(result) {
|
|
134
|
+
return result.status === 'applied'
|
|
135
|
+
? '✅ Update applied, reloading...'
|
|
136
|
+
: result.status === 'noBundle'
|
|
137
|
+
? '⚠️ No downloaded bundle to apply'
|
|
138
|
+
: 'ℹ️ Bundle already applied';
|
|
139
|
+
}
|
|
140
|
+
async function refreshState(cached) {
|
|
141
|
+
const state = await (0, updateState_1.getUpdateState)(cached);
|
|
142
|
+
patchSnapshot({
|
|
143
|
+
installedInfo: state.info || null,
|
|
144
|
+
pendingApply: state.pendingApply,
|
|
145
|
+
hasBundle: state.hasBundle,
|
|
146
|
+
});
|
|
147
|
+
return state;
|
|
148
|
+
}
|
|
149
|
+
async function withBusy(fn) {
|
|
150
|
+
if (updateFlowActive) {
|
|
151
|
+
throw new Error('Another update flow is already in progress');
|
|
152
|
+
}
|
|
153
|
+
updateFlowActive = true;
|
|
154
|
+
patchSnapshot({ isBusy: true });
|
|
155
|
+
try {
|
|
156
|
+
const result = await fn();
|
|
157
|
+
await refreshState();
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
finally {
|
|
161
|
+
updateFlowActive = false;
|
|
162
|
+
patchSnapshot({ isBusy: false });
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
async function waitForStartupIfNeeded() {
|
|
166
|
+
await startupPromise;
|
|
167
|
+
}
|
|
168
|
+
async function runStartupFlow() {
|
|
169
|
+
const runtime = (0, initState_1.assertBundleDropInitialized)();
|
|
170
|
+
const statusCb = status => emitStatus(status);
|
|
171
|
+
const [bundleInfo, bundlePath, currentPointer, rollbackState] = await Promise.all([
|
|
172
|
+
(0, bundleInfo_1.readBundleInfo)(),
|
|
173
|
+
(0, bundleDropNative_1.getDownloadedBundlePathNative)(),
|
|
174
|
+
(0, bundlePointer_1.readCurrentBundlePointer)(),
|
|
175
|
+
(0, rollbackState_1.readRollbackState)(),
|
|
176
|
+
]);
|
|
177
|
+
await (0, updateState_1.reconcileAppliedBundleOnLaunch)({ bundleInfo, bundlePath });
|
|
178
|
+
await refreshState({ bundleInfo, bundlePath });
|
|
179
|
+
const rollbackPolicy = (0, rollbackState_1.getRollbackPolicy)();
|
|
180
|
+
const rollbackResult = await (0, rollbackState_1.rollbackToPreviousIfNeeded)(rollbackPolicy, {
|
|
181
|
+
currentPointer,
|
|
182
|
+
rollbackState,
|
|
183
|
+
});
|
|
184
|
+
if (rollbackResult.rolledBack) {
|
|
185
|
+
emitStatus('↩️ Rolled back to previous bundle');
|
|
186
|
+
(0, bundleDropNative_1.restartReactNativeNative)();
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
await (0, rollbackState_1.commitActiveBundle)({ currentPointer });
|
|
190
|
+
const pendingState = await refreshState({ bundlePath });
|
|
191
|
+
if (pendingState.pendingApply) {
|
|
192
|
+
if (runtime.policy === 'immediate') {
|
|
193
|
+
emitStatus('♻️ Applying previously downloaded update...');
|
|
194
|
+
const applied = await (0, updateState_1.applyUpdate)(statusCb);
|
|
195
|
+
if (applied.status === 'applied') {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (runtime.policy === 'on-next-launch') {
|
|
200
|
+
emitStatus('✅ Update downloaded; will apply on next launch.');
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (runtime.policy === 'manual' && !runtime.checkOnly) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const decision = await (0, updateCheck_1.checkForUpdate)(runtime.channelName, statusCb);
|
|
208
|
+
const finalStatus = getCheckStatus(decision);
|
|
209
|
+
if (!isSameStatus(snapshot.status, finalStatus)) {
|
|
210
|
+
emitStatus(finalStatus);
|
|
211
|
+
}
|
|
212
|
+
if (!decision)
|
|
213
|
+
return;
|
|
214
|
+
if (decision.action === 'ROLLBACK') {
|
|
215
|
+
emitStatus('↩️ Server requested rollback...');
|
|
216
|
+
await (0, rollbackState_1.rollbackToPreviousOrNative)();
|
|
217
|
+
(0, bundleDropNative_1.restartReactNativeNative)();
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (decision.action === 'NOOP' || runtime.policy === 'manual' || runtime.checkOnly) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (!decision.downloadUrl || !decision.hash) {
|
|
224
|
+
emitStatus('⚠️ Update available but missing download URL');
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const resolvedTarget = {
|
|
228
|
+
hash: decision.hash,
|
|
229
|
+
downloadUrl: decision.downloadUrl,
|
|
230
|
+
bundleVersion: decision.bundleVersion,
|
|
231
|
+
version: decision.version,
|
|
232
|
+
runtimeVersion: decision.runtimeVersion,
|
|
233
|
+
};
|
|
234
|
+
const downloadResult = await (0, downloadAndInstall_1.downloadUpdate)({
|
|
235
|
+
channelName: runtime.channelName,
|
|
236
|
+
resolvedTarget,
|
|
237
|
+
}, statusCb);
|
|
238
|
+
if (runtime.policy === 'on-next-launch') {
|
|
239
|
+
if (downloadResult.status === 'staged') {
|
|
240
|
+
emitStatus('✅ Update downloaded for next launch');
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const nextStatus = getDownloadStatus(downloadResult);
|
|
244
|
+
if (nextStatus)
|
|
245
|
+
emitStatus(nextStatus);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
if (downloadResult.status === 'staged') {
|
|
249
|
+
await (0, updateState_1.applyUpdate)(statusCb);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
const nextStatus = getDownloadStatus(downloadResult);
|
|
253
|
+
if (nextStatus)
|
|
254
|
+
emitStatus(nextStatus);
|
|
255
|
+
}
|
|
256
|
+
function ensureStartupFlow() {
|
|
257
|
+
startupPromise = withBusy(async () => {
|
|
258
|
+
await runStartupFlow();
|
|
259
|
+
})
|
|
260
|
+
.catch(error => {
|
|
261
|
+
console.error('❌ BundleDrop startup failed:', error);
|
|
262
|
+
emitStatus('⚠️ Failed to initialize BundleDrop');
|
|
263
|
+
})
|
|
264
|
+
.finally(() => {
|
|
265
|
+
startupPromise = null;
|
|
266
|
+
});
|
|
267
|
+
return startupPromise;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Initialize the singleton BundleDrop runtime for the current app process.
|
|
271
|
+
*
|
|
272
|
+
* Call this once during app startup, typically from `index.js`, before using
|
|
273
|
+
* `useBundleDrop()` or any OTA runtime APIs.
|
|
274
|
+
*/
|
|
275
|
+
function initBundleDrop(options) {
|
|
276
|
+
const { alreadyInitialized, config } = (0, initState_1.initializeBundleDropRuntime)(options);
|
|
277
|
+
patchSnapshot({
|
|
278
|
+
channelName: config.channelName,
|
|
279
|
+
isEnabled: config.enabled,
|
|
280
|
+
});
|
|
281
|
+
if (!config.enabled) {
|
|
282
|
+
setDisabledSnapshot(config.channelName);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
if (!alreadyInitialized) {
|
|
286
|
+
patchSnapshot({ status: DEFAULT_STATUS });
|
|
287
|
+
void ensureStartupFlow();
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Change the active runtime channel used by singleton OTA actions such as checks,
|
|
292
|
+
* downloads, and installs triggered through `useBundleDrop()` or named exports.
|
|
293
|
+
*/
|
|
294
|
+
function setChannel(channelName) {
|
|
295
|
+
const runtime = getConfiguredRuntime();
|
|
296
|
+
if (!runtime) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
if (updateFlowActive) {
|
|
300
|
+
throw new Error('Another update flow is already in progress');
|
|
301
|
+
}
|
|
302
|
+
const nextRuntime = (0, initState_1.setBundleDropChannel)(channelName);
|
|
303
|
+
patchSnapshot({
|
|
304
|
+
channelName: nextRuntime.channelName,
|
|
305
|
+
isEnabled: nextRuntime.enabled,
|
|
306
|
+
status: nextRuntime.enabled ? DEFAULT_STATUS : DISABLED_STATUS,
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Read the current active runtime channel.
|
|
311
|
+
*/
|
|
312
|
+
function getChannelName() {
|
|
313
|
+
return getConfiguredRuntime()?.channelName ?? snapshot.channelName;
|
|
314
|
+
}
|
|
315
|
+
function subscribeBundleDropState(listener) {
|
|
316
|
+
listeners.add(listener);
|
|
317
|
+
return () => {
|
|
318
|
+
listeners.delete(listener);
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
function getBundleDropSnapshot() {
|
|
322
|
+
return snapshot;
|
|
323
|
+
}
|
|
324
|
+
function isUpdateFlowActive() {
|
|
325
|
+
return updateFlowActive;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Resolve update metadata from the server without downloading anything.
|
|
329
|
+
*/
|
|
330
|
+
async function checkLatest(extraStatusHandler) {
|
|
331
|
+
const runtime = getEnabledRuntime(extraStatusHandler);
|
|
332
|
+
if (!runtime) {
|
|
333
|
+
return { response: null, status: DISABLED_STATUS };
|
|
334
|
+
}
|
|
335
|
+
await waitForStartupIfNeeded();
|
|
336
|
+
return withBusy(async () => {
|
|
337
|
+
const response = await (0, updateCheck_1.checkForUpdate)(runtime.channelName, status => emitStatus(status, extraStatusHandler));
|
|
338
|
+
const status = getCheckStatus(response);
|
|
339
|
+
if (!isSameStatus(snapshot.status, status)) {
|
|
340
|
+
emitStatus(status, extraStatusHandler);
|
|
341
|
+
}
|
|
342
|
+
return { response, status };
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Resolve, download, and stage the latest compatible update for the active runtime channel.
|
|
347
|
+
*/
|
|
348
|
+
async function downloadAndStage(extraStatusHandler) {
|
|
349
|
+
const runtime = getEnabledRuntime(extraStatusHandler);
|
|
350
|
+
if (!runtime) {
|
|
351
|
+
return { result: { status: 'disabled' }, status: DISABLED_STATUS };
|
|
352
|
+
}
|
|
353
|
+
await waitForStartupIfNeeded();
|
|
354
|
+
return withBusy(async () => {
|
|
355
|
+
const result = await (0, downloadAndInstall_1.downloadUpdate)({ channelName: runtime.channelName }, status => emitStatus(status, extraStatusHandler));
|
|
356
|
+
const status = getDownloadStatus(result);
|
|
357
|
+
if (status) {
|
|
358
|
+
emitStatus(status, extraStatusHandler);
|
|
359
|
+
}
|
|
360
|
+
return { result, status };
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Apply a previously staged bundle immediately by restarting the React Native bridge.
|
|
365
|
+
*/
|
|
366
|
+
async function applyDownloadedUpdate(extraStatusHandler) {
|
|
367
|
+
if (!getEnabledRuntime(extraStatusHandler)) {
|
|
368
|
+
return { result: { status: 'disabled' }, status: DISABLED_STATUS };
|
|
369
|
+
}
|
|
370
|
+
await waitForStartupIfNeeded();
|
|
371
|
+
return withBusy(async () => {
|
|
372
|
+
const result = await (0, updateState_1.applyUpdate)(status => emitStatus(status, extraStatusHandler));
|
|
373
|
+
const status = getApplyStatus(result);
|
|
374
|
+
if (status) {
|
|
375
|
+
emitStatus(status, extraStatusHandler);
|
|
376
|
+
}
|
|
377
|
+
return { result, status };
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Fetch the list of public channel names available for the configured project.
|
|
382
|
+
*/
|
|
383
|
+
async function fetchAvailableChannels() {
|
|
384
|
+
if (!getEnabledRuntime()) {
|
|
385
|
+
return [];
|
|
386
|
+
}
|
|
387
|
+
try {
|
|
388
|
+
const availableChannels = await (0, updateCheck_1.getAvailableChannels)();
|
|
389
|
+
patchSnapshot({ availableChannels });
|
|
390
|
+
return availableChannels;
|
|
391
|
+
}
|
|
392
|
+
catch (error) {
|
|
393
|
+
emitStatus('⚠️ Unable to fetch channels.');
|
|
394
|
+
return [];
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Fetch a paginated list of bundles for a channel. Defaults to the active runtime channel.
|
|
399
|
+
*/
|
|
400
|
+
async function fetchAvailableBundles(options) {
|
|
401
|
+
const runtime = getEnabledRuntime();
|
|
402
|
+
if (!runtime) {
|
|
403
|
+
return { items: [], nextCursor: null, hasMore: false };
|
|
404
|
+
}
|
|
405
|
+
try {
|
|
406
|
+
return await (0, updateCheck_1.getAvailableBundles)({
|
|
407
|
+
...options,
|
|
408
|
+
channelName: options?.channelName ?? runtime.channelName,
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
catch (error) {
|
|
412
|
+
emitStatus('⚠️ Unable to fetch bundles.');
|
|
413
|
+
return { items: [], nextCursor: null, hasMore: false };
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Download and stage a specific bundle returned by `fetchAvailableBundles()`.
|
|
418
|
+
*/
|
|
419
|
+
async function installBundleFromListItem(bundle) {
|
|
420
|
+
const runtime = getEnabledRuntime();
|
|
421
|
+
if (!runtime) {
|
|
422
|
+
return { result: { status: 'disabled' }, status: DISABLED_STATUS };
|
|
423
|
+
}
|
|
424
|
+
await waitForStartupIfNeeded();
|
|
425
|
+
if (!bundle.downloadUrl) {
|
|
426
|
+
const status = '⚠️ Bundle is not downloadable (expired or unavailable)';
|
|
427
|
+
emitStatus(status);
|
|
428
|
+
return { result: { status: 'incompatible' }, status };
|
|
429
|
+
}
|
|
430
|
+
return withBusy(async () => {
|
|
431
|
+
const result = await (0, downloadAndInstall_1.installBundle)(bundle.hash, bundle.downloadUrl, bundle.bundleVersion, bundle.version, bundle.runtimeVersion, {
|
|
432
|
+
channelName: runtime.channelName,
|
|
433
|
+
onStatusUpdate: emitStatus,
|
|
434
|
+
});
|
|
435
|
+
if (result.status === 'staged') {
|
|
436
|
+
const status = `✅ v${bundle.bundleVersion} downloaded. Will apply on next launch or when you call applyUpdate.`;
|
|
437
|
+
emitStatus(status);
|
|
438
|
+
return { result, status };
|
|
439
|
+
}
|
|
440
|
+
return { result, status: undefined };
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Read locally stored metadata for the currently downloaded or applied bundle.
|
|
445
|
+
*/
|
|
446
|
+
async function getInstalledBundleInfo() {
|
|
447
|
+
if (!getEnabledRuntime()) {
|
|
448
|
+
return null;
|
|
449
|
+
}
|
|
450
|
+
const state = await refreshState();
|
|
451
|
+
return state.info || null;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Read the current local update state from disk.
|
|
455
|
+
*/
|
|
456
|
+
async function getRuntimeUpdateState() {
|
|
457
|
+
if (!getEnabledRuntime()) {
|
|
458
|
+
return {
|
|
459
|
+
hasBundle: false,
|
|
460
|
+
info: null,
|
|
461
|
+
pendingApply: false,
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
return refreshState();
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Named-export variant of `useBundleDrop().checkLatest()`.
|
|
468
|
+
*/
|
|
469
|
+
async function checkForUpdate(onStatusUpdate) {
|
|
470
|
+
const { response } = await checkLatest(onStatusUpdate);
|
|
471
|
+
return response;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Named-export variant of `useBundleDrop().downloadUpdate()`.
|
|
475
|
+
*/
|
|
476
|
+
async function downloadUpdate(onStatusUpdate) {
|
|
477
|
+
const { result } = await downloadAndStage(onStatusUpdate);
|
|
478
|
+
return result;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Named-export variant of `useBundleDrop().applyUpdate()`.
|
|
482
|
+
*/
|
|
483
|
+
async function applyUpdate(onStatusUpdate) {
|
|
484
|
+
const { result } = await applyDownloadedUpdate(onStatusUpdate);
|
|
485
|
+
return result;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Named-export variant of `useBundleDrop().fetchAvailableChannels()`.
|
|
489
|
+
*/
|
|
490
|
+
async function getAvailableChannels() {
|
|
491
|
+
return fetchAvailableChannels();
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Named-export variant of `useBundleDrop().fetchBundles()`.
|
|
495
|
+
*/
|
|
496
|
+
async function getAvailableBundles(options) {
|
|
497
|
+
return fetchAvailableBundles(options);
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Download and stage a specific bundle by hash and URL instead of browsing through `fetchBundles()`.
|
|
501
|
+
*/
|
|
502
|
+
async function installBundle(hash, downloadUrl, bundleVersion, version, runtimeVersion, onStatusUpdate) {
|
|
503
|
+
const runtime = getEnabledRuntime(onStatusUpdate);
|
|
504
|
+
if (!runtime) {
|
|
505
|
+
return { status: 'disabled' };
|
|
506
|
+
}
|
|
507
|
+
await waitForStartupIfNeeded();
|
|
508
|
+
return withBusy(async () => {
|
|
509
|
+
const result = await (0, downloadAndInstall_1.installBundle)(hash, downloadUrl, bundleVersion, version, runtimeVersion, {
|
|
510
|
+
channelName: runtime.channelName,
|
|
511
|
+
onStatusUpdate: status => emitStatus(status, onStatusUpdate),
|
|
512
|
+
});
|
|
513
|
+
const status = getDownloadStatus(result);
|
|
514
|
+
if (status) {
|
|
515
|
+
emitStatus(status, onStatusUpdate);
|
|
516
|
+
}
|
|
517
|
+
return result;
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
function resetBundleDropRuntimeServiceForTests() {
|
|
521
|
+
updateFlowActive = false;
|
|
522
|
+
startupPromise = null;
|
|
523
|
+
snapshot = {
|
|
524
|
+
status: DISABLED_STATUS,
|
|
525
|
+
isBusy: false,
|
|
526
|
+
isEnabled: false,
|
|
527
|
+
channelName: context_1.defaultChannel,
|
|
528
|
+
installedInfo: null,
|
|
529
|
+
pendingApply: false,
|
|
530
|
+
hasBundle: false,
|
|
531
|
+
availableChannels: [],
|
|
532
|
+
};
|
|
533
|
+
listeners.clear();
|
|
534
|
+
}
|
|
535
|
+
async function waitForBundleDropStartupForTests() {
|
|
536
|
+
await startupPromise;
|
|
537
|
+
}
|
package/lib/scripts/bundle.d.ts
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
export
|
|
2
|
+
export declare function findProjectRoot(startDir: string): string;
|
|
3
|
+
export declare function runBundleScript(options?: {
|
|
4
|
+
platform?: string;
|
|
5
|
+
cwd?: string;
|
|
6
|
+
}): {
|
|
7
|
+
projectRoot: string;
|
|
8
|
+
outputDir: string;
|
|
9
|
+
bundlePath: string;
|
|
10
|
+
metadataPath: string;
|
|
11
|
+
zipPath: string;
|
|
12
|
+
runtimeVersion: string;
|
|
13
|
+
hash: string;
|
|
14
|
+
};
|