@gfean/react-native-bundle-drop 0.3.3 → 0.3.6
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/BundleDrop.podspec +2 -0
- package/README.md +8 -2
- package/android/build.gradle +91 -1
- package/android/gradle.properties +1 -0
- package/android/src/main/java/com/bundledrop/BundleDropFileOps.kt +131 -0
- package/android/src/main/java/com/bundledrop/BundleDropModule.kt +65 -89
- package/android/src/main/java/com/bundledrop/BundleDropOtaResolver.kt +93 -0
- package/ios/BundleDropBridge.m +14 -0
- package/ios/BundleDropFileOps.swift +220 -0
- package/ios/BundleDropLocator.h +11 -0
- package/ios/BundleDropLocator.swift +34 -45
- package/ios/BundleDropModule.swift +65 -15
- package/ios/BundleDropOtaResolver.swift +112 -0
- package/ios/BundleDropZipExtractor.h +13 -0
- package/ios/BundleDropZipExtractor.m +226 -0
- package/lib/CLI/cli.js +56 -6
- package/lib/CLI/scripts/aipowered/apply-plan.d.ts +10 -0
- package/lib/CLI/scripts/aipowered/apply-plan.js +50 -0
- package/lib/CLI/scripts/aipowered/backend-client.d.ts +6 -0
- package/lib/CLI/scripts/aipowered/backend-client.js +34 -0
- package/lib/CLI/scripts/aipowered/diff-preview.d.ts +7 -0
- package/lib/CLI/scripts/aipowered/diff-preview.js +33 -0
- package/lib/CLI/scripts/aipowered/init-native-config.d.ts +2 -0
- package/lib/CLI/scripts/aipowered/init-native-config.js +131 -0
- package/lib/CLI/scripts/aipowered/scanner.d.ts +5 -0
- package/lib/CLI/scripts/aipowered/scanner.js +349 -0
- package/lib/CLI/scripts/aipowered/types.d.ts +53 -0
- package/lib/CLI/scripts/aipowered/types.js +2 -0
- package/lib/CLI/scripts/aipowered/validate-plan.d.ts +8 -0
- package/lib/CLI/scripts/aipowered/validate-plan.js +164 -0
- package/lib/CLI/scripts/init-config.js +10 -5
- package/lib/CLI/scripts/init-native-config.js +1 -1
- package/lib/CLI/scripts/post-init.js +7 -18
- package/lib/CLI/scripts/upload-cli.d.ts +2 -0
- package/lib/CLI/scripts/upload-cli.js +67 -28
- package/lib/CLI/utils/ui.d.ts +3 -0
- package/lib/CLI/utils/ui.js +26 -0
- package/lib/api/clientApi.d.ts +2 -1
- package/lib/api/clientApi.js +9 -0
- package/lib/api/types.d.ts +21 -3
- package/lib/bundleInfo.d.ts +12 -0
- package/lib/context.d.ts +19 -2
- package/lib/context.js +5 -2
- package/lib/errors.d.ts +25 -0
- package/lib/errors.js +26 -1
- package/lib/fs/bundlePointer.d.ts +2 -0
- package/lib/fs/bundlePointer.js +14 -4
- package/lib/fs/fsUtils.d.ts +1 -2
- package/lib/fs/fsUtils.js +12 -27
- package/lib/fs/userProperties.d.ts +25 -4
- package/lib/fs/userProperties.js +51 -7
- package/lib/index.d.ts +7 -3
- package/lib/index.js +5 -1
- package/lib/injectImageResolver.js +6 -15
- package/lib/install/installFromZip.d.ts +1 -1
- package/lib/install/installFromZip.js +47 -42
- package/lib/loadConfig.d.ts +21 -2
- package/lib/loadConfig.js +11 -7
- package/lib/manager/downloadAndInstall.d.ts +3 -0
- package/lib/manager/downloadAndInstall.js +30 -28
- package/lib/manager/reporting.d.ts +2 -0
- package/lib/manager/reporting.js +27 -2
- package/lib/manager/rollbackState.d.ts +28 -11
- package/lib/manager/rollbackState.js +90 -38
- package/lib/manager/updateCheck.js +17 -3
- package/lib/manager/updateState.d.ts +5 -1
- package/lib/manager/updateState.js +20 -11
- package/lib/native/fs.d.ts +6 -0
- package/lib/native/fs.js +27 -0
- package/lib/runtime/initState.d.ts +2 -2
- package/lib/runtime/service.d.ts +28 -0
- package/lib/runtime/service.js +136 -10
- package/lib/scripts/bundle.d.ts +4 -1
- package/lib/scripts/bundle.js +42 -29
- package/lib/scripts/projectRoot.d.ts +1 -0
- package/lib/scripts/projectRoot.js +54 -0
- package/lib/scripts/resolve-ios-version.d.ts +2 -0
- package/lib/scripts/resolve-ios-version.js +74 -0
- package/lib/scripts/upload-bundle.d.ts +2 -1
- package/lib/scripts/upload-bundle.js +56 -41
- package/lib/types.d.ts +3 -0
- package/lib/useBundleDrop.d.ts +2 -0
- package/lib/useBundleDrop.js +1 -0
- package/package.json +9 -11
package/lib/runtime/service.js
CHANGED
|
@@ -9,10 +9,12 @@ exports.isUpdateFlowActive = isUpdateFlowActive;
|
|
|
9
9
|
exports.checkLatest = checkLatest;
|
|
10
10
|
exports.downloadAndStage = downloadAndStage;
|
|
11
11
|
exports.applyDownloadedUpdate = applyDownloadedUpdate;
|
|
12
|
+
exports.reportHealthy = reportHealthy;
|
|
12
13
|
exports.fetchAvailableChannels = fetchAvailableChannels;
|
|
13
14
|
exports.fetchAvailableBundles = fetchAvailableBundles;
|
|
14
15
|
exports.installBundleFromListItem = installBundleFromListItem;
|
|
15
16
|
exports.getInstalledBundleInfo = getInstalledBundleInfo;
|
|
17
|
+
exports.getObservabilityContext = getObservabilityContext;
|
|
16
18
|
exports.getRuntimeUpdateState = getRuntimeUpdateState;
|
|
17
19
|
exports.checkForUpdate = checkForUpdate;
|
|
18
20
|
exports.downloadUpdate = downloadUpdate;
|
|
@@ -24,6 +26,7 @@ exports.resetBundleDropRuntimeServiceForTests = resetBundleDropRuntimeServiceFor
|
|
|
24
26
|
exports.waitForBundleDropStartupForTests = waitForBundleDropStartupForTests;
|
|
25
27
|
const bundleInfo_1 = require("../bundleInfo");
|
|
26
28
|
const context_1 = require("../context");
|
|
29
|
+
const fsUtils_1 = require("../fs/fsUtils");
|
|
27
30
|
const bundleDropNative_1 = require("../native/bundleDropNative");
|
|
28
31
|
const bundlePointer_1 = require("../fs/bundlePointer");
|
|
29
32
|
const downloadAndInstall_1 = require("../manager/downloadAndInstall");
|
|
@@ -35,6 +38,8 @@ const DEFAULT_STATUS = 'Click the button to check for updates';
|
|
|
35
38
|
const DISABLED_STATUS = 'BundleDrop is disabled';
|
|
36
39
|
let updateFlowActive = false;
|
|
37
40
|
let startupPromise = null;
|
|
41
|
+
let healthTimer = null;
|
|
42
|
+
let runtimeRestartRequested = false;
|
|
38
43
|
let snapshot = {
|
|
39
44
|
status: DISABLED_STATUS,
|
|
40
45
|
isBusy: false,
|
|
@@ -101,6 +106,9 @@ function isSameStatus(current, next) {
|
|
|
101
106
|
function getCheckStatus(response) {
|
|
102
107
|
if (!response)
|
|
103
108
|
return '⚠️ Unable to check for updates. Try again.';
|
|
109
|
+
if (response.skippedFailedBundle) {
|
|
110
|
+
return '✅ Current bundle retained; requested update previously failed on this device';
|
|
111
|
+
}
|
|
104
112
|
if (response.action === 'ROLLBACK') {
|
|
105
113
|
if (!response.reason) {
|
|
106
114
|
return '↩️ Rollback requested';
|
|
@@ -118,8 +126,11 @@ function getCheckStatus(response) {
|
|
|
118
126
|
: '⬇️ Update available';
|
|
119
127
|
}
|
|
120
128
|
function getDownloadStatus(result) {
|
|
121
|
-
if (result.status === 'upToDate')
|
|
122
|
-
return
|
|
129
|
+
if (result.status === 'upToDate') {
|
|
130
|
+
return result.skippedFailedBundle
|
|
131
|
+
? '✅ Current bundle retained; requested update previously failed on this device'
|
|
132
|
+
: '✅ You have the latest version';
|
|
133
|
+
}
|
|
123
134
|
if (result.status === 'rollback') {
|
|
124
135
|
if (!result.reason) {
|
|
125
136
|
return '↩️ Rollback requested';
|
|
@@ -135,7 +146,52 @@ function getApplyStatus(result) {
|
|
|
135
146
|
? '✅ Update applied, reloading...'
|
|
136
147
|
: result.status === 'noBundle'
|
|
137
148
|
? '⚠️ No downloaded bundle to apply'
|
|
138
|
-
:
|
|
149
|
+
: result.status === 'blocked'
|
|
150
|
+
? '⚠️ Update previously failed on this device'
|
|
151
|
+
: 'ℹ️ Bundle already applied';
|
|
152
|
+
}
|
|
153
|
+
function clearHealthTimer() {
|
|
154
|
+
if (!healthTimer)
|
|
155
|
+
return;
|
|
156
|
+
clearTimeout(healthTimer);
|
|
157
|
+
healthTimer = null;
|
|
158
|
+
}
|
|
159
|
+
function requestRuntimeRestart() {
|
|
160
|
+
runtimeRestartRequested = true;
|
|
161
|
+
(0, bundleDropNative_1.restartReactNativeNative)();
|
|
162
|
+
}
|
|
163
|
+
async function markActiveCandidateHealthy(expectedHash) {
|
|
164
|
+
if (runtimeRestartRequested) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
const state = await (0, updateState_1.getUpdateState)();
|
|
168
|
+
if (runtimeRestartRequested) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
if (state.pendingApply) {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
const markedHealthy = await (0, rollbackState_1.reportActiveBundleHealthy)(undefined, expectedHash);
|
|
175
|
+
if (markedHealthy) {
|
|
176
|
+
await refreshState();
|
|
177
|
+
}
|
|
178
|
+
return markedHealthy;
|
|
179
|
+
}
|
|
180
|
+
function scheduleCandidateHealthMark(currentPointer, rollbackState) {
|
|
181
|
+
clearHealthTimer();
|
|
182
|
+
const hash = currentPointer?.hash;
|
|
183
|
+
const rollbackPolicy = (0, rollbackState_1.getRollbackPolicy)();
|
|
184
|
+
if (!hash || rollbackPolicy.healthCheckMode === 'manual')
|
|
185
|
+
return;
|
|
186
|
+
if (rollbackState?.candidateHash !== hash || rollbackState.candidateCommitted === true)
|
|
187
|
+
return;
|
|
188
|
+
const delayMs = Math.max(0, rollbackPolicy.healthyAfterSec || 0) * 1000;
|
|
189
|
+
healthTimer = setTimeout(() => {
|
|
190
|
+
healthTimer = null;
|
|
191
|
+
markActiveCandidateHealthy(hash).catch(error => {
|
|
192
|
+
console.warn('⚠️ Failed to mark BundleDrop candidate healthy:', error);
|
|
193
|
+
});
|
|
194
|
+
}, delayMs);
|
|
139
195
|
}
|
|
140
196
|
async function refreshState(cached) {
|
|
141
197
|
const state = await (0, updateState_1.getUpdateState)(cached);
|
|
@@ -168,6 +224,7 @@ async function waitForStartupIfNeeded() {
|
|
|
168
224
|
async function runStartupFlow() {
|
|
169
225
|
const runtime = (0, initState_1.assertBundleDropInitialized)();
|
|
170
226
|
const statusCb = status => emitStatus(status);
|
|
227
|
+
void (0, fsUtils_1.cleanOrphanedTempZips)(`${context_1.BUNDLE_DROP_ROOT}/bundles`);
|
|
171
228
|
const [bundleInfo, bundlePath, currentPointer, rollbackState] = await Promise.all([
|
|
172
229
|
(0, bundleInfo_1.readBundleInfo)(),
|
|
173
230
|
(0, bundleDropNative_1.getDownloadedBundlePathNative)(),
|
|
@@ -182,16 +239,19 @@ async function runStartupFlow() {
|
|
|
182
239
|
rollbackState,
|
|
183
240
|
});
|
|
184
241
|
if (rollbackResult.rolledBack) {
|
|
242
|
+
clearHealthTimer();
|
|
185
243
|
emitStatus('↩️ Rolled back to previous bundle');
|
|
186
|
-
(
|
|
244
|
+
requestRuntimeRestart();
|
|
187
245
|
return;
|
|
188
246
|
}
|
|
189
|
-
await (0, rollbackState_1.
|
|
247
|
+
scheduleCandidateHealthMark(currentPointer, await (0, rollbackState_1.readRollbackState)());
|
|
190
248
|
const pendingState = await refreshState({ bundlePath });
|
|
191
249
|
if (pendingState.pendingApply) {
|
|
192
250
|
if (runtime.policy === 'immediate') {
|
|
193
251
|
emitStatus('♻️ Applying previously downloaded update...');
|
|
194
|
-
const applied = await (0, updateState_1.applyUpdate)(statusCb)
|
|
252
|
+
const applied = await (0, updateState_1.applyUpdate)(statusCb, () => {
|
|
253
|
+
runtimeRestartRequested = true;
|
|
254
|
+
});
|
|
195
255
|
if (applied.status === 'applied') {
|
|
196
256
|
return;
|
|
197
257
|
}
|
|
@@ -214,7 +274,7 @@ async function runStartupFlow() {
|
|
|
214
274
|
if (decision.action === 'ROLLBACK') {
|
|
215
275
|
emitStatus('↩️ Server requested rollback...');
|
|
216
276
|
await (0, rollbackState_1.rollbackToPreviousOrNative)();
|
|
217
|
-
(
|
|
277
|
+
requestRuntimeRestart();
|
|
218
278
|
return;
|
|
219
279
|
}
|
|
220
280
|
if (decision.action === 'NOOP' || runtime.policy === 'manual' || runtime.checkOnly) {
|
|
@@ -246,7 +306,9 @@ async function runStartupFlow() {
|
|
|
246
306
|
return;
|
|
247
307
|
}
|
|
248
308
|
if (downloadResult.status === 'staged') {
|
|
249
|
-
await (0, updateState_1.applyUpdate)(statusCb)
|
|
309
|
+
await (0, updateState_1.applyUpdate)(statusCb, () => {
|
|
310
|
+
runtimeRestartRequested = true;
|
|
311
|
+
});
|
|
250
312
|
return;
|
|
251
313
|
}
|
|
252
314
|
const nextStatus = getDownloadStatus(downloadResult);
|
|
@@ -274,6 +336,9 @@ function ensureStartupFlow() {
|
|
|
274
336
|
*/
|
|
275
337
|
function initBundleDrop(options) {
|
|
276
338
|
const { alreadyInitialized, config } = (0, initState_1.initializeBundleDropRuntime)(options);
|
|
339
|
+
if (!alreadyInitialized) {
|
|
340
|
+
runtimeRestartRequested = false;
|
|
341
|
+
}
|
|
277
342
|
patchSnapshot({
|
|
278
343
|
channelName: config.channelName,
|
|
279
344
|
isEnabled: config.enabled,
|
|
@@ -369,7 +434,9 @@ async function applyDownloadedUpdate(extraStatusHandler) {
|
|
|
369
434
|
}
|
|
370
435
|
await waitForStartupIfNeeded();
|
|
371
436
|
return withBusy(async () => {
|
|
372
|
-
const result = await (0, updateState_1.applyUpdate)(status => emitStatus(status, extraStatusHandler))
|
|
437
|
+
const result = await (0, updateState_1.applyUpdate)(status => emitStatus(status, extraStatusHandler), () => {
|
|
438
|
+
runtimeRestartRequested = true;
|
|
439
|
+
});
|
|
373
440
|
const status = getApplyStatus(result);
|
|
374
441
|
if (status) {
|
|
375
442
|
emitStatus(status, extraStatusHandler);
|
|
@@ -377,6 +444,21 @@ async function applyDownloadedUpdate(extraStatusHandler) {
|
|
|
377
444
|
return { result, status };
|
|
378
445
|
});
|
|
379
446
|
}
|
|
447
|
+
/**
|
|
448
|
+
* Mark the currently running OTA candidate healthy for this device.
|
|
449
|
+
*/
|
|
450
|
+
async function reportHealthy() {
|
|
451
|
+
const runtime = getEnabledRuntime();
|
|
452
|
+
if (!runtime) {
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
await waitForStartupIfNeeded();
|
|
456
|
+
if (runtimeRestartRequested || updateFlowActive) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
clearHealthTimer();
|
|
460
|
+
await markActiveCandidateHealthy();
|
|
461
|
+
}
|
|
380
462
|
/**
|
|
381
463
|
* Fetch the list of public channel names available for the configured project.
|
|
382
464
|
*/
|
|
@@ -437,7 +519,10 @@ async function installBundleFromListItem(bundle) {
|
|
|
437
519
|
emitStatus(status);
|
|
438
520
|
return { result, status };
|
|
439
521
|
}
|
|
440
|
-
|
|
522
|
+
const status = getDownloadStatus(result);
|
|
523
|
+
if (status)
|
|
524
|
+
emitStatus(status);
|
|
525
|
+
return { result, status };
|
|
441
526
|
});
|
|
442
527
|
}
|
|
443
528
|
/**
|
|
@@ -450,6 +535,46 @@ async function getInstalledBundleInfo() {
|
|
|
450
535
|
const state = await refreshState();
|
|
451
536
|
return state.info || null;
|
|
452
537
|
}
|
|
538
|
+
/**
|
|
539
|
+
* Pre-formatted context for error tracking integrations.
|
|
540
|
+
*
|
|
541
|
+
* Returns `dist`, `tags`, and `context` shaped for direct use with
|
|
542
|
+
* Sentry, Bugsnag, Datadog, or any provider. Handles the embedded
|
|
543
|
+
* fallback automatically: when no OTA bundle is active, `source`
|
|
544
|
+
* is `'embedded'` and `dist` is `'embedded'`.
|
|
545
|
+
*
|
|
546
|
+
* If the installed bundle has `pendingApply: true` it is not yet
|
|
547
|
+
* executing, so the context falls back to `'embedded'`.
|
|
548
|
+
*/
|
|
549
|
+
async function getObservabilityContext() {
|
|
550
|
+
const info = await getInstalledBundleInfo();
|
|
551
|
+
if (!info || info.pendingApply || !info.hash) {
|
|
552
|
+
return {
|
|
553
|
+
source: 'embedded',
|
|
554
|
+
dist: 'embedded',
|
|
555
|
+
tags: {
|
|
556
|
+
bundle_drop_hash: null,
|
|
557
|
+
bundle_drop_channel: null,
|
|
558
|
+
bundle_drop_version: null,
|
|
559
|
+
bundle_drop_runtime_version: null,
|
|
560
|
+
bundle_drop_platform: null,
|
|
561
|
+
},
|
|
562
|
+
context: null,
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
return {
|
|
566
|
+
source: 'ota',
|
|
567
|
+
dist: info.hash ?? 'embedded',
|
|
568
|
+
tags: {
|
|
569
|
+
bundle_drop_hash: info.hash ?? null,
|
|
570
|
+
bundle_drop_channel: info.channelName ?? null,
|
|
571
|
+
bundle_drop_version: info.bundleVersion != null ? `${info.bundleVersion}` : null,
|
|
572
|
+
bundle_drop_runtime_version: info.runtimeVersion ?? null,
|
|
573
|
+
bundle_drop_platform: info.platform ?? null,
|
|
574
|
+
},
|
|
575
|
+
context: info,
|
|
576
|
+
};
|
|
577
|
+
}
|
|
453
578
|
/**
|
|
454
579
|
* Read the current local update state from disk.
|
|
455
580
|
*/
|
|
@@ -518,6 +643,7 @@ async function installBundle(hash, downloadUrl, bundleVersion, version, runtimeV
|
|
|
518
643
|
});
|
|
519
644
|
}
|
|
520
645
|
function resetBundleDropRuntimeServiceForTests() {
|
|
646
|
+
clearHealthTimer();
|
|
521
647
|
updateFlowActive = false;
|
|
522
648
|
startupPromise = null;
|
|
523
649
|
snapshot = {
|
package/lib/scripts/bundle.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
import { findProjectRoot } from './projectRoot';
|
|
3
|
+
export { findProjectRoot };
|
|
3
4
|
export declare function runBundleScript(options?: {
|
|
4
5
|
platform?: string;
|
|
5
6
|
cwd?: string;
|
|
7
|
+
sourcemap?: boolean;
|
|
6
8
|
}): {
|
|
7
9
|
projectRoot: string;
|
|
8
10
|
outputDir: string;
|
|
9
11
|
bundlePath: string;
|
|
12
|
+
sourceMapPath: string;
|
|
10
13
|
metadataPath: string;
|
|
11
14
|
zipPath: string;
|
|
12
15
|
runtimeVersion: string;
|
package/lib/scripts/bundle.js
CHANGED
|
@@ -37,30 +37,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
38
|
};
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
exports.findProjectRoot =
|
|
40
|
+
exports.findProjectRoot = void 0;
|
|
41
41
|
exports.runBundleScript = runBundleScript;
|
|
42
42
|
const adm_zip_1 = __importDefault(require("adm-zip"));
|
|
43
43
|
const child_process_1 = require("child_process");
|
|
44
44
|
const crypto_1 = require("crypto");
|
|
45
45
|
const fs = __importStar(require("fs"));
|
|
46
46
|
const path = __importStar(require("path"));
|
|
47
|
+
const projectRoot_1 = require("./projectRoot");
|
|
48
|
+
Object.defineProperty(exports, "findProjectRoot", { enumerable: true, get: function () { return projectRoot_1.findProjectRoot; } });
|
|
47
49
|
const getPackageRoot = () => process.env.BUNDLE_DROP_PACKAGE_ROOT_OVERRIDE || path.resolve(__dirname, '..', '..');
|
|
48
|
-
function findProjectRoot(startDir) {
|
|
49
|
-
let dir = path.resolve(startDir);
|
|
50
|
-
const MAX_UP = 12;
|
|
51
|
-
for (let i = 0; i < MAX_UP; i++) {
|
|
52
|
-
const iosDir = path.join(dir, 'ios');
|
|
53
|
-
const androidDir = path.join(dir, 'android');
|
|
54
|
-
if (fs.existsSync(iosDir) && fs.existsSync(androidDir)) {
|
|
55
|
-
return dir;
|
|
56
|
-
}
|
|
57
|
-
const parent = path.dirname(dir);
|
|
58
|
-
if (parent === dir)
|
|
59
|
-
break;
|
|
60
|
-
dir = parent;
|
|
61
|
-
}
|
|
62
|
-
return startDir;
|
|
63
|
-
}
|
|
64
50
|
function runBundleScript(options) {
|
|
65
51
|
const packageRoot = getPackageRoot();
|
|
66
52
|
const platform = options?.platform || process.argv[2] || 'ios';
|
|
@@ -74,9 +60,11 @@ function runBundleScript(options) {
|
|
|
74
60
|
const assetsDir = path.join(outputDir, 'assets');
|
|
75
61
|
const bundlePath = path.join(outputDir, 'main.jsbundle');
|
|
76
62
|
const metadataPath = path.join(outputDir, `metadata-${fileSuffix}.json`);
|
|
63
|
+
const sourceMapPath = path.join(outputDir, 'main.jsbundle.map');
|
|
77
64
|
const zipPath = path.join(outputDir, `bundle-${platform}.zip`);
|
|
78
65
|
const imageManifest = {};
|
|
79
|
-
const projectRoot = findProjectRoot(options?.cwd || process.cwd());
|
|
66
|
+
const projectRoot = (0, projectRoot_1.findProjectRoot)(options?.cwd || process.cwd());
|
|
67
|
+
const generateSourceMap = options?.sourcemap ?? process.argv.includes('--sourcemap');
|
|
80
68
|
let runtimeVersion;
|
|
81
69
|
const configPath = path.resolve(projectRoot, 'bundle.drop.config.js');
|
|
82
70
|
if (fs.existsSync(configPath)) {
|
|
@@ -90,7 +78,7 @@ function runBundleScript(options) {
|
|
|
90
78
|
else {
|
|
91
79
|
console.warn('⚠️ bundle.drop.config.js not found in project root; runtimeVersion will be omitted.');
|
|
92
80
|
}
|
|
93
|
-
[bundlePath, zipPath, metadataPath].forEach(file => {
|
|
81
|
+
[bundlePath, zipPath, metadataPath, sourceMapPath].forEach(file => {
|
|
94
82
|
if (fs.existsSync(file))
|
|
95
83
|
fs.unlinkSync(file);
|
|
96
84
|
});
|
|
@@ -99,13 +87,14 @@ function runBundleScript(options) {
|
|
|
99
87
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
100
88
|
fs.mkdirSync(assetsDir, { recursive: true });
|
|
101
89
|
console.log(`📦 Bundling React Native code for platform: ${platform}...`);
|
|
90
|
+
const sourcemapFlag = generateSourceMap ? ` \\\n --sourcemap-output "${sourceMapPath}"` : '';
|
|
102
91
|
(0, child_process_1.execSync)(`npx react-native bundle \
|
|
103
92
|
--platform ${platform} \
|
|
104
93
|
--dev false \
|
|
105
94
|
--entry-file index.js \
|
|
106
|
-
--bundle-output ${bundlePath} \
|
|
107
|
-
--assets-dest ${assetsDir}`, { stdio: 'inherit' });
|
|
108
|
-
console.log('✅ Bundle created
|
|
95
|
+
--bundle-output "${bundlePath}" \
|
|
96
|
+
--assets-dest "${assetsDir}"${sourcemapFlag}`, { stdio: 'inherit' });
|
|
97
|
+
console.log('✅ Bundle created');
|
|
109
98
|
const osBin = process.platform === 'darwin'
|
|
110
99
|
? 'osx-bin'
|
|
111
100
|
: process.platform === 'win32'
|
|
@@ -117,19 +106,42 @@ function runBundleScript(options) {
|
|
|
117
106
|
];
|
|
118
107
|
const hermescPath = hermesLocations.find(p => fs.existsSync(p));
|
|
119
108
|
if (hermescPath) {
|
|
120
|
-
console.log(`🔥 Compiling to Hermes bytecode (${platform})...`);
|
|
121
109
|
const hbcPath = bundlePath + '.hbc';
|
|
110
|
+
const hermesMapFlag = generateSourceMap ? ` -output-source-map` : '';
|
|
122
111
|
try {
|
|
123
|
-
|
|
112
|
+
console.log(`🔥 Compiling to Hermes bytecode (${platform})...`);
|
|
113
|
+
(0, child_process_1.execSync)(`"${hermescPath}" -emit-binary -out "${hbcPath}" "${bundlePath}"${hermesMapFlag}`, { stdio: ['ignore', 'ignore', 'ignore'] });
|
|
124
114
|
fs.renameSync(hbcPath, bundlePath);
|
|
125
|
-
console.log('✅ Hermes bytecode compiled
|
|
115
|
+
console.log('✅ Hermes bytecode compiled');
|
|
126
116
|
}
|
|
127
117
|
catch (e) {
|
|
128
118
|
console.warn('⚠️ Hermes compilation failed, falling back to plain JS bundle:', e.message);
|
|
129
119
|
}
|
|
120
|
+
if (generateSourceMap) {
|
|
121
|
+
const hermesMapPath = bundlePath + '.hbc.map';
|
|
122
|
+
if (fs.existsSync(hermesMapPath) && fs.existsSync(sourceMapPath)) {
|
|
123
|
+
const composeScript = path.join(projectRoot, 'node_modules', 'react-native', 'scripts', 'compose-source-maps.js');
|
|
124
|
+
if (fs.existsSync(composeScript)) {
|
|
125
|
+
try {
|
|
126
|
+
const composedPath = sourceMapPath + '.composed';
|
|
127
|
+
(0, child_process_1.execSync)(`node "${composeScript}" "${sourceMapPath}" "${hermesMapPath}" -o "${composedPath}"`, { stdio: ['ignore', 'ignore', 'ignore'] });
|
|
128
|
+
fs.renameSync(composedPath, sourceMapPath);
|
|
129
|
+
console.log('✅ Source maps composed');
|
|
130
|
+
}
|
|
131
|
+
catch (composeErr) {
|
|
132
|
+
console.warn('⚠️ Source map composition failed; keeping Metro source map:', composeErr.message);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
console.warn('⚠️ compose-source-maps.js not found; keeping Metro source map as-is');
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (fs.existsSync(hermesMapPath))
|
|
140
|
+
fs.unlinkSync(hermesMapPath);
|
|
141
|
+
}
|
|
130
142
|
}
|
|
131
143
|
else {
|
|
132
|
-
console.log('ℹ️
|
|
144
|
+
console.log('ℹ️ Hermes not found — bundling plain JS');
|
|
133
145
|
}
|
|
134
146
|
const bundleBuffer = fs.readFileSync(bundlePath);
|
|
135
147
|
const hash = (0, crypto_1.createHash)('sha256').update(bundleBuffer).digest('hex');
|
|
@@ -144,9 +156,8 @@ function runBundleScript(options) {
|
|
|
144
156
|
metadata.runtimeVersion = runtimeVersion;
|
|
145
157
|
}
|
|
146
158
|
fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2));
|
|
147
|
-
console.log('🧠 Metadata saved
|
|
159
|
+
console.log('🧠 Metadata saved');
|
|
148
160
|
console.log('📌 Hash:', hash);
|
|
149
|
-
console.log('📦 Zipping bundle...');
|
|
150
161
|
const zip = new adm_zip_1.default();
|
|
151
162
|
zip.addFile('main.jsbundle', bundleBuffer);
|
|
152
163
|
zip.addFile(`metadata-${fileSuffix}.json`, Buffer.from(JSON.stringify(metadata, null, 2)));
|
|
@@ -182,12 +193,14 @@ function runBundleScript(options) {
|
|
|
182
193
|
zip.addFile('image-manifest.json', Buffer.from(JSON.stringify(imageManifest, null, 2)));
|
|
183
194
|
console.log(`🧩 Injected image-manifest.json with ${Object.keys(imageManifest).length} entries`);
|
|
184
195
|
}
|
|
196
|
+
console.log('📦 Zipping bundle...');
|
|
185
197
|
zip.writeZip(zipPath);
|
|
186
|
-
console.log(
|
|
198
|
+
console.log('✅ OTA bundle zipped');
|
|
187
199
|
return {
|
|
188
200
|
projectRoot,
|
|
189
201
|
outputDir,
|
|
190
202
|
bundlePath,
|
|
203
|
+
sourceMapPath: generateSourceMap ? sourceMapPath : undefined,
|
|
191
204
|
metadataPath,
|
|
192
205
|
zipPath,
|
|
193
206
|
runtimeVersion,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function findProjectRoot(startDir: string): string;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.findProjectRoot = findProjectRoot;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
function findProjectRoot(startDir) {
|
|
40
|
+
let dir = path.resolve(startDir);
|
|
41
|
+
const MAX_UP = 12;
|
|
42
|
+
for (let i = 0; i < MAX_UP; i++) {
|
|
43
|
+
const iosDir = path.join(dir, 'ios');
|
|
44
|
+
const androidDir = path.join(dir, 'android');
|
|
45
|
+
if (fs.existsSync(iosDir) && fs.existsSync(androidDir)) {
|
|
46
|
+
return dir;
|
|
47
|
+
}
|
|
48
|
+
const parent = path.dirname(dir);
|
|
49
|
+
if (parent === dir)
|
|
50
|
+
break;
|
|
51
|
+
dir = parent;
|
|
52
|
+
}
|
|
53
|
+
return startDir;
|
|
54
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.resolveXcodeBuildSetting = resolveXcodeBuildSetting;
|
|
37
|
+
exports.resolveIosPlistVersion = resolveIosPlistVersion;
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
const XCODE_VAR_RE = /\$\(([^)]+)\)/;
|
|
41
|
+
function resolveXcodeBuildSetting(projectRoot, variableName) {
|
|
42
|
+
const iosDir = path.join(projectRoot, 'ios');
|
|
43
|
+
if (!fs.existsSync(iosDir))
|
|
44
|
+
return null;
|
|
45
|
+
const xcodeproj = fs.readdirSync(iosDir).find(f => f.endsWith('.xcodeproj'));
|
|
46
|
+
if (!xcodeproj)
|
|
47
|
+
return null;
|
|
48
|
+
const pbxprojPath = path.join(iosDir, xcodeproj, 'project.pbxproj');
|
|
49
|
+
if (!fs.existsSync(pbxprojPath))
|
|
50
|
+
return null;
|
|
51
|
+
const content = fs.readFileSync(pbxprojPath, 'utf-8');
|
|
52
|
+
const pattern = new RegExp(`${variableName}\\s*=\\s*([^;]+);`);
|
|
53
|
+
const match = content.match(pattern);
|
|
54
|
+
if (!match)
|
|
55
|
+
return null;
|
|
56
|
+
const value = match[1].trim().replace(/^["']|["']$/g, '');
|
|
57
|
+
if (!value || XCODE_VAR_RE.test(value))
|
|
58
|
+
return null;
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
function resolveIosPlistVersion(rawVersion, projectRoot) {
|
|
62
|
+
const xcodeVarMatch = rawVersion.match(XCODE_VAR_RE);
|
|
63
|
+
if (!xcodeVarMatch)
|
|
64
|
+
return rawVersion;
|
|
65
|
+
const variableName = xcodeVarMatch[1];
|
|
66
|
+
const resolved = resolveXcodeBuildSetting(projectRoot, variableName);
|
|
67
|
+
if (resolved) {
|
|
68
|
+
console.warn(`⚠️ Info.plist contains $(${variableName}); resolved to "${resolved}" from .pbxproj`);
|
|
69
|
+
return resolved;
|
|
70
|
+
}
|
|
71
|
+
console.error(`❌ Info.plist contains $(${variableName}) which could not be resolved.\n` +
|
|
72
|
+
` Pass --version=x.y.z explicitly, or ensure MARKETING_VERSION is set in your .pbxproj.`);
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
import { findProjectRoot } from './projectRoot';
|
|
3
|
+
export { findProjectRoot };
|
|
3
4
|
export declare function parseAndroidVersionFromGradle(filePath: string): string;
|
|
4
5
|
export declare const cleanupArtifacts: (platform: string, zipPath: string) => void;
|
|
5
6
|
export declare function runUploadBundle(options?: {
|