@gfean/react-native-bundle-drop 0.3.8 → 0.4.1
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 +9 -2
- package/README.md +19 -0
- package/android/build.gradle +25 -4
- package/android/src/main/cpp/CMakeLists.txt +33 -0
- package/android/src/main/cpp/bundle_drop_xdelta_jni.c +55 -0
- package/android/src/main/java/com/bundledrop/BundleDropBundleVerifier.kt +73 -0
- package/android/src/main/java/com/bundledrop/BundleDropFileOps.kt +193 -8
- package/android/src/main/java/com/bundledrop/BundleDropModule.kt +60 -7
- package/android/src/main/java/com/bundledrop/BundleDropOtaPrefs.kt +2 -12
- package/android/src/main/java/com/bundledrop/BundleDropOtaResolver.kt +208 -3
- package/android/src/main/java/com/bundledrop/BundleDropXdeltaNative.kt +57 -0
- package/ios/BundleDropBridge.m +27 -0
- package/ios/BundleDropBundleVerifier.swift +106 -0
- package/ios/BundleDropFileOps.swift +149 -0
- package/ios/BundleDropModule.swift +100 -11
- package/ios/BundleDropOtaResolver.swift +149 -3
- package/ios/BundleDropZipExtractor.m +75 -3
- package/lib/CLI/cli.js +1 -8
- package/lib/CLI/scripts/upload-cli.d.ts +0 -1
- package/lib/CLI/scripts/upload-cli.js +26 -20
- package/lib/api/client.d.ts +11 -1
- package/lib/api/client.js +84 -17
- package/lib/api/clientApi.d.ts +2 -1
- package/lib/api/clientApi.js +9 -0
- package/lib/api/types.d.ts +65 -13
- package/lib/bundleInfo.d.ts +2 -0
- package/lib/fs/bundlePointer.d.ts +2 -1
- package/lib/fs/bundlePointer.js +34 -6
- package/lib/fs/fsUtils.js +4 -1
- package/lib/injectImageResolver.js +135 -45
- package/lib/install/bundleInstallShared.d.ts +8 -0
- package/lib/install/bundleInstallShared.js +97 -0
- package/lib/install/bundleVerification.d.ts +5 -0
- package/lib/install/bundleVerification.js +34 -0
- package/lib/install/installFromZip.d.ts +2 -5
- package/lib/install/installFromZip.js +33 -62
- package/lib/loadConfig.js +12 -1
- package/lib/manager/downloadAndInstall.d.ts +9 -0
- package/lib/manager/downloadAndInstall.js +84 -24
- package/lib/manager/reporting.js +26 -2
- package/lib/manager/rollbackState.js +21 -12
- package/lib/manager/updateCheck.js +89 -11
- package/lib/manager/updateState.js +3 -9
- package/lib/manifest/bundleManifest.d.ts +33 -0
- package/lib/manifest/bundleManifest.js +298 -0
- package/lib/native/bundleDropNative.js +1 -2
- package/lib/native/fs.d.ts +14 -0
- package/lib/native/fs.js +35 -0
- package/lib/patch-engine/installFromPatchSet.d.ts +16 -0
- package/lib/patch-engine/installFromPatchSet.js +143 -0
- package/lib/patch-engine/patchOperations.d.ts +33 -0
- package/lib/patch-engine/patchOperations.js +77 -0
- package/lib/patch-engine/patchTransport.d.ts +18 -0
- package/lib/patch-engine/patchTransport.js +81 -0
- package/lib/patchAlgorithms.d.ts +4 -0
- package/lib/patchAlgorithms.js +9 -0
- package/lib/runtime/service.js +43 -9
- package/lib/scripts/bundle.d.ts +3 -0
- package/lib/scripts/bundle.js +184 -36
- package/lib/scripts/download-bundle.js +18 -7
- package/lib/scripts/upload-bundle.js +25 -28
- package/package.json +44 -5
- package/third_party/xdelta/NOTICE +7 -0
- package/third_party/xdelta/PROVENANCE.md +10 -0
- package/third_party/xdelta/bundle_drop_xdelta.c +252 -0
- package/third_party/xdelta/bundle_drop_xdelta.h +26 -0
- package/third_party/xdelta/xdelta3/LICENSE +176 -0
- package/third_party/xdelta/xdelta3/config.h +34 -0
- package/third_party/xdelta/xdelta3/xdelta3-cfgs.h +171 -0
- package/third_party/xdelta/xdelta3/xdelta3-decode.h +1219 -0
- package/third_party/xdelta/xdelta3/xdelta3-hash.h +159 -0
- package/third_party/xdelta/xdelta3/xdelta3-internal.h +385 -0
- package/third_party/xdelta/xdelta3/xdelta3-list.h +127 -0
- package/third_party/xdelta/xdelta3/xdelta3.c +4819 -0
- package/third_party/xdelta/xdelta3/xdelta3.h +1476 -0
- package/lib/CLI/scripts/init-native-config.d.ts +0 -18
- package/lib/CLI/scripts/init-native-config.js +0 -539
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.applyPatchOperation = exports.resolvePatchOperation = exports.advertisedPatchAlgorithms = exports.isSupportedPatchAlgorithm = exports.XDELTA_PATCH_ALGORITHM = exports.ASSET_ONLY_PATCH_ALGORITHM = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("../native/fs"));
|
|
8
|
+
const bundleInstallShared_1 = require("../install/bundleInstallShared");
|
|
9
|
+
const bundleManifest_1 = require("../manifest/bundleManifest");
|
|
10
|
+
var patchAlgorithms_1 = require("../patchAlgorithms");
|
|
11
|
+
Object.defineProperty(exports, "ASSET_ONLY_PATCH_ALGORITHM", { enumerable: true, get: function () { return patchAlgorithms_1.ASSET_ONLY_PATCH_ALGORITHM; } });
|
|
12
|
+
Object.defineProperty(exports, "XDELTA_PATCH_ALGORITHM", { enumerable: true, get: function () { return patchAlgorithms_1.XDELTA_PATCH_ALGORITHM; } });
|
|
13
|
+
const patchAlgorithms_2 = require("../patchAlgorithms");
|
|
14
|
+
const xdeltaPatchDriver = {
|
|
15
|
+
id: patchAlgorithms_2.XDELTA_PATCH_ALGORITHM,
|
|
16
|
+
patchPath: (patchDir, filePath) => `${patchDir}/files/xdelta/${filePath}.vcdiff`,
|
|
17
|
+
apply: async ({ basePath, patchPath, outputPath }) => {
|
|
18
|
+
await (0, bundleInstallShared_1.ensureParentDir)(outputPath);
|
|
19
|
+
await fs_1.default.applyXdelta(basePath, patchPath, outputPath);
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
const isSupportedPatchAlgorithm = (algorithm) => patchAlgorithms_2.SUPPORTED_PATCH_ALGORITHMS.includes(algorithm);
|
|
23
|
+
exports.isSupportedPatchAlgorithm = isSupportedPatchAlgorithm;
|
|
24
|
+
const advertisedPatchAlgorithms = (supportsXdelta) => supportsXdelta
|
|
25
|
+
? [patchAlgorithms_2.XDELTA_PATCH_ALGORITHM, patchAlgorithms_2.ASSET_ONLY_PATCH_ALGORITHM]
|
|
26
|
+
: [patchAlgorithms_2.ASSET_ONLY_PATCH_ALGORITHM];
|
|
27
|
+
exports.advertisedPatchAlgorithms = advertisedPatchAlgorithms;
|
|
28
|
+
const fullFileCandidates = (patchDir, filePath) => [
|
|
29
|
+
`${patchDir}/files/full/${filePath}`,
|
|
30
|
+
`${patchDir}/missing-assets/${filePath}`,
|
|
31
|
+
];
|
|
32
|
+
const findExistingPath = async (paths) => {
|
|
33
|
+
for (const path of paths) {
|
|
34
|
+
if (await fs_1.default.exists(path)) {
|
|
35
|
+
return path;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
};
|
|
40
|
+
const resolvePatchOperation = async ({ baseDir, patchDir, targetDir, targetFile, baseFilesByPath, algorithm, }) => {
|
|
41
|
+
const filePath = (0, bundleManifest_1.normalizeManifestPath)(targetFile.path);
|
|
42
|
+
const outputPath = `${targetDir}/${filePath}`;
|
|
43
|
+
const fullFilePath = await findExistingPath(fullFileCandidates(patchDir, filePath));
|
|
44
|
+
if (fullFilePath) {
|
|
45
|
+
return { type: 'full-file', sourcePath: fullFilePath, outputPath };
|
|
46
|
+
}
|
|
47
|
+
if (algorithm === patchAlgorithms_2.XDELTA_PATCH_ALGORITHM) {
|
|
48
|
+
const deltaFilePath = await findExistingPath([xdeltaPatchDriver.patchPath(patchDir, filePath)]);
|
|
49
|
+
if (deltaFilePath) {
|
|
50
|
+
return {
|
|
51
|
+
type: 'xdelta',
|
|
52
|
+
basePath: `${baseDir}/${filePath}`,
|
|
53
|
+
patchPath: deltaFilePath,
|
|
54
|
+
outputPath,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const baseFile = baseFilesByPath.get(filePath);
|
|
59
|
+
if (baseFile && baseFile.sha256 === targetFile.sha256 && baseFile.size === targetFile.size) {
|
|
60
|
+
return {
|
|
61
|
+
type: 'copy-unchanged',
|
|
62
|
+
sourcePath: `${baseDir}/${filePath}`,
|
|
63
|
+
outputPath,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
throw new Error(`Patch set missing full content for changed file: ${filePath}`);
|
|
67
|
+
};
|
|
68
|
+
exports.resolvePatchOperation = resolvePatchOperation;
|
|
69
|
+
const applyPatchOperation = async (operation) => {
|
|
70
|
+
if (operation.type === 'xdelta') {
|
|
71
|
+
await xdeltaPatchDriver.apply(operation);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
await (0, bundleInstallShared_1.ensureParentDir)(operation.outputPath);
|
|
75
|
+
await fs_1.default.copyFile(operation.sourcePath, operation.outputPath);
|
|
76
|
+
};
|
|
77
|
+
exports.applyPatchOperation = applyPatchOperation;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { OtaPatchSet } from '../api/types';
|
|
2
|
+
import type { InstallResult } from '../install/bundleInstallShared';
|
|
3
|
+
export type PatchTransportTarget = {
|
|
4
|
+
mode?: 'full' | 'patch';
|
|
5
|
+
hash: string;
|
|
6
|
+
manifestUrl?: string;
|
|
7
|
+
baseHash?: string;
|
|
8
|
+
patchSet?: OtaPatchSet;
|
|
9
|
+
};
|
|
10
|
+
type TryInstallPatchTransportParams = {
|
|
11
|
+
target: PatchTransportTarget;
|
|
12
|
+
projectSlug: string;
|
|
13
|
+
platform: 'ios' | 'android';
|
|
14
|
+
runtimeVersionValue?: string;
|
|
15
|
+
statusCb?: (status: string) => void;
|
|
16
|
+
};
|
|
17
|
+
export declare const tryInstallPatchTransport: ({ target, projectSlug, platform, runtimeVersionValue, statusCb, }: TryInstallPatchTransportParams) => Promise<InstallResult | null>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tryInstallPatchTransport = void 0;
|
|
4
|
+
const context_1 = require("../context");
|
|
5
|
+
const installId_1 = require("../fs/installId");
|
|
6
|
+
const clientApi_1 = require("../api/clientApi");
|
|
7
|
+
const installFromPatchSet_1 = require("./installFromPatchSet");
|
|
8
|
+
const patchOperations_1 = require("./patchOperations");
|
|
9
|
+
const PATCH_FAILURE_REPORT_TIMEOUT_MS = 1500;
|
|
10
|
+
const reportPatchInstallFailure = async ({ projectSlug, platform, runtimeVersionValue, baseHash, targetHash, algorithm, error, }) => {
|
|
11
|
+
try {
|
|
12
|
+
const installId = await (0, installId_1.getOrCreateInstallId)();
|
|
13
|
+
await (0, clientApi_1.reportPatchApplyFailure)(projectSlug, {
|
|
14
|
+
platform,
|
|
15
|
+
runtimeVersion: runtimeVersionValue,
|
|
16
|
+
installId,
|
|
17
|
+
baseHash,
|
|
18
|
+
targetHash,
|
|
19
|
+
algorithm,
|
|
20
|
+
reason: error instanceof Error ? error.message : 'patch_install_failed',
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
// Telemetry must never block the full-bundle fallback path.
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const reportPatchInstallFailureBeforeFallback = async (params) => {
|
|
28
|
+
let timeout = null;
|
|
29
|
+
const timeoutPromise = new Promise(resolve => {
|
|
30
|
+
timeout = setTimeout(resolve, PATCH_FAILURE_REPORT_TIMEOUT_MS);
|
|
31
|
+
});
|
|
32
|
+
try {
|
|
33
|
+
await Promise.race([
|
|
34
|
+
reportPatchInstallFailure(params),
|
|
35
|
+
timeoutPromise,
|
|
36
|
+
]);
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
if (timeout)
|
|
40
|
+
clearTimeout(timeout);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const tryInstallPatchTransport = async ({ target, projectSlug, platform, runtimeVersionValue, statusCb, }) => {
|
|
44
|
+
if (target.mode !== 'patch' ||
|
|
45
|
+
!target.baseHash ||
|
|
46
|
+
!(0, patchOperations_1.isSupportedPatchAlgorithm)(target.patchSet?.algorithm) ||
|
|
47
|
+
!target.patchSet?.patchesUrl ||
|
|
48
|
+
!target.patchSet.patchSetHash) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
statusCb?.('🧩 Downloading patch set...');
|
|
53
|
+
return await (0, installFromPatchSet_1.installFromPatchSet)({
|
|
54
|
+
patchesUrl: target.patchSet.patchesUrl,
|
|
55
|
+
patchSetHash: target.patchSet.patchSetHash,
|
|
56
|
+
manifestUrl: target.manifestUrl,
|
|
57
|
+
missingAssetsUrl: target.patchSet.assets?.missingAssetsUrl,
|
|
58
|
+
missingAssetsHash: target.patchSet.assets?.missingAssetsHash,
|
|
59
|
+
baseHash: target.baseHash,
|
|
60
|
+
targetHash: target.hash,
|
|
61
|
+
algorithm: target.patchSet.algorithm,
|
|
62
|
+
platform,
|
|
63
|
+
statusCb,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
await reportPatchInstallFailureBeforeFallback({
|
|
68
|
+
projectSlug,
|
|
69
|
+
platform,
|
|
70
|
+
runtimeVersionValue: runtimeVersionValue ?? context_1.runtimeVersion ?? '',
|
|
71
|
+
baseHash: target.baseHash,
|
|
72
|
+
targetHash: target.hash,
|
|
73
|
+
algorithm: target.patchSet.algorithm,
|
|
74
|
+
error: e,
|
|
75
|
+
});
|
|
76
|
+
statusCb?.('↩️ Patch install failed; falling back to full bundle ZIP');
|
|
77
|
+
console.warn('⚠️ Patch install failed; falling back to full bundle ZIP:', e?.toString?.() || e);
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
exports.tryInstallPatchTransport = tryInstallPatchTransport;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const XDELTA_PATCH_ALGORITHM = "xdelta3-vcdiff";
|
|
2
|
+
export declare const ASSET_ONLY_PATCH_ALGORITHM = "asset-only-v1";
|
|
3
|
+
export declare const SUPPORTED_PATCH_ALGORITHMS: readonly ["xdelta3-vcdiff", "asset-only-v1"];
|
|
4
|
+
export type SupportedPatchAlgorithm = (typeof SUPPORTED_PATCH_ALGORITHMS)[number];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SUPPORTED_PATCH_ALGORITHMS = exports.ASSET_ONLY_PATCH_ALGORITHM = exports.XDELTA_PATCH_ALGORITHM = void 0;
|
|
4
|
+
exports.XDELTA_PATCH_ALGORITHM = 'xdelta3-vcdiff';
|
|
5
|
+
exports.ASSET_ONLY_PATCH_ALGORITHM = 'asset-only-v1';
|
|
6
|
+
exports.SUPPORTED_PATCH_ALGORITHMS = [
|
|
7
|
+
exports.XDELTA_PATCH_ALGORITHM,
|
|
8
|
+
exports.ASSET_ONLY_PATCH_ALGORITHM,
|
|
9
|
+
];
|
package/lib/runtime/service.js
CHANGED
|
@@ -42,6 +42,7 @@ let localStartupPromise = null;
|
|
|
42
42
|
let healthTimer = null;
|
|
43
43
|
let runtimeRestartRequested = false;
|
|
44
44
|
let activeBundleInfoForObservability = null;
|
|
45
|
+
let nativeOtaEnabledPromise = Promise.resolve();
|
|
45
46
|
let snapshot = {
|
|
46
47
|
status: DISABLED_STATUS,
|
|
47
48
|
isBusy: false,
|
|
@@ -252,7 +253,10 @@ async function runStartupFlow() {
|
|
|
252
253
|
const runtime = (0, initState_1.assertBundleDropInitialized)();
|
|
253
254
|
const statusCb = status => emitStatus(status);
|
|
254
255
|
void (0, fsUtils_1.cleanOrphanedTempZips)(`${context_1.BUNDLE_DROP_ROOT}/bundles`);
|
|
255
|
-
localStartupPromise =
|
|
256
|
+
localStartupPromise = (async () => {
|
|
257
|
+
await nativeOtaEnabledPromise;
|
|
258
|
+
return runLocalStartupFlow();
|
|
259
|
+
})();
|
|
256
260
|
const { bundlePath, currentPointer, rollbackState } = await localStartupPromise;
|
|
257
261
|
const rollbackPolicy = (0, rollbackState_1.getRollbackPolicy)();
|
|
258
262
|
const rollbackResult = await (0, rollbackState_1.rollbackToPreviousIfNeeded)(rollbackPolicy, {
|
|
@@ -301,16 +305,24 @@ async function runStartupFlow() {
|
|
|
301
305
|
if (decision.action === 'NOOP' || runtime.policy === 'manual' || runtime.checkOnly) {
|
|
302
306
|
return;
|
|
303
307
|
}
|
|
304
|
-
|
|
308
|
+
const downloadUrl = decision.mode === 'patch'
|
|
309
|
+
? decision.fallback?.downloadUrl
|
|
310
|
+
: decision.downloadUrl;
|
|
311
|
+
if (!downloadUrl || !decision.hash) {
|
|
305
312
|
emitStatus('⚠️ Update available but missing download URL');
|
|
306
313
|
return;
|
|
307
314
|
}
|
|
308
315
|
const resolvedTarget = {
|
|
309
316
|
hash: decision.hash,
|
|
310
|
-
downloadUrl
|
|
317
|
+
downloadUrl,
|
|
311
318
|
bundleVersion: decision.bundleVersion,
|
|
312
319
|
version: decision.version,
|
|
313
320
|
runtimeVersion: decision.runtimeVersion,
|
|
321
|
+
manifestUrl: decision.manifestUrl,
|
|
322
|
+
mode: decision.mode,
|
|
323
|
+
baseHash: decision.baseHash,
|
|
324
|
+
patchSet: decision.patchSet,
|
|
325
|
+
fallback: decision.fallback,
|
|
314
326
|
};
|
|
315
327
|
const downloadResult = await (0, downloadAndInstall_1.downloadUpdate)({
|
|
316
328
|
channelName: runtime.channelName,
|
|
@@ -361,8 +373,8 @@ function initBundleDrop(options) {
|
|
|
361
373
|
runtimeRestartRequested = false;
|
|
362
374
|
activeBundleInfoForObservability = null;
|
|
363
375
|
}
|
|
364
|
-
// Persist for the next cold start
|
|
365
|
-
|
|
376
|
+
// Persist for the next cold start and for native path reads in this process.
|
|
377
|
+
nativeOtaEnabledPromise = (0, bundleDropNative_1.setOtaEnabledNative)(config.enabled);
|
|
366
378
|
patchSnapshot({
|
|
367
379
|
channelName: config.channelName,
|
|
368
380
|
isEnabled: config.enabled,
|
|
@@ -457,6 +469,7 @@ async function applyDownloadedUpdate(extraStatusHandler) {
|
|
|
457
469
|
return { result: { status: 'disabled' }, status: DISABLED_STATUS };
|
|
458
470
|
}
|
|
459
471
|
await waitForStartupIfNeeded();
|
|
472
|
+
await nativeOtaEnabledPromise;
|
|
460
473
|
return withBusy(async () => {
|
|
461
474
|
const result = await (0, updateState_1.applyUpdate)(status => emitStatus(status, extraStatusHandler), () => {
|
|
462
475
|
runtimeRestartRequested = true;
|
|
@@ -535,10 +548,31 @@ async function installBundleFromListItem(bundle) {
|
|
|
535
548
|
return { result: { status: 'incompatible' }, status };
|
|
536
549
|
}
|
|
537
550
|
return withBusy(async () => {
|
|
538
|
-
const
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
551
|
+
const resolvedDecision = await (0, updateCheck_1.checkForUpdate)(runtime.channelName, emitStatus).catch(() => null);
|
|
552
|
+
const canUseResolvedTransport = resolvedDecision?.action === 'INSTALL' &&
|
|
553
|
+
(resolvedDecision.bundleHash ?? resolvedDecision.hash) === bundle.hash;
|
|
554
|
+
const result = canUseResolvedTransport
|
|
555
|
+
? await (0, downloadAndInstall_1.downloadUpdate)({
|
|
556
|
+
channelName: runtime.channelName,
|
|
557
|
+
resolvedTarget: {
|
|
558
|
+
hash: bundle.hash,
|
|
559
|
+
downloadUrl: resolvedDecision.mode === 'patch'
|
|
560
|
+
? resolvedDecision.fallback?.downloadUrl ?? downloadUrl
|
|
561
|
+
: resolvedDecision.downloadUrl ?? downloadUrl,
|
|
562
|
+
bundleVersion: resolvedDecision.bundleVersion ?? bundle.bundleVersion,
|
|
563
|
+
version: resolvedDecision.version ?? bundle.version,
|
|
564
|
+
runtimeVersion: resolvedDecision.runtimeVersion ?? bundle.runtimeVersion,
|
|
565
|
+
manifestUrl: resolvedDecision.manifestUrl,
|
|
566
|
+
mode: resolvedDecision.mode,
|
|
567
|
+
baseHash: resolvedDecision.baseHash,
|
|
568
|
+
patchSet: resolvedDecision.patchSet,
|
|
569
|
+
fallback: resolvedDecision.fallback,
|
|
570
|
+
},
|
|
571
|
+
}, emitStatus)
|
|
572
|
+
: await (0, downloadAndInstall_1.installBundle)(bundle.hash, downloadUrl, bundle.bundleVersion, bundle.version, bundle.runtimeVersion, {
|
|
573
|
+
channelName: runtime.channelName,
|
|
574
|
+
onStatusUpdate: emitStatus,
|
|
575
|
+
});
|
|
542
576
|
if (result.status === 'staged') {
|
|
543
577
|
const status = `✅ v${bundle.bundleVersion} downloaded. Will apply on next launch or when you call applyUpdate.`;
|
|
544
578
|
emitStatus(status);
|
package/lib/scripts/bundle.d.ts
CHANGED
package/lib/scripts/bundle.js
CHANGED
|
@@ -44,9 +44,131 @@ 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 bundleManifest_1 = require("../manifest/bundleManifest");
|
|
47
48
|
const projectRoot_1 = require("./projectRoot");
|
|
48
49
|
Object.defineProperty(exports, "findProjectRoot", { enumerable: true, get: function () { return projectRoot_1.findProjectRoot; } });
|
|
49
50
|
const getPackageRoot = () => process.env.BUNDLE_DROP_PACKAGE_ROOT_OVERRIDE || path.resolve(__dirname, '..', '..');
|
|
51
|
+
const sha256Buffer = (buffer) => (0, crypto_1.createHash)('sha256').update(buffer).digest('hex');
|
|
52
|
+
const manifestRoleForPath = (filePath) => {
|
|
53
|
+
if (filePath === 'main.jsbundle')
|
|
54
|
+
return 'jsbundle';
|
|
55
|
+
if (filePath.startsWith('metadata-'))
|
|
56
|
+
return 'metadata';
|
|
57
|
+
if (filePath === 'image-manifest.json')
|
|
58
|
+
return 'androidImageManifest';
|
|
59
|
+
return 'asset';
|
|
60
|
+
};
|
|
61
|
+
const createFileEntry = (filePath, buffer) => ({
|
|
62
|
+
path: (0, bundleManifest_1.normalizeManifestPath)(filePath),
|
|
63
|
+
size: buffer.length,
|
|
64
|
+
sha256: sha256Buffer(buffer),
|
|
65
|
+
role: manifestRoleForPath((0, bundleManifest_1.normalizeManifestPath)(filePath)),
|
|
66
|
+
});
|
|
67
|
+
const readTextIfExists = (filePath) => {
|
|
68
|
+
if (!fs.existsSync(filePath))
|
|
69
|
+
return null;
|
|
70
|
+
return fs.readFileSync(filePath, 'utf8');
|
|
71
|
+
};
|
|
72
|
+
const readPlatformSetting = (value, platform) => {
|
|
73
|
+
if (typeof value === 'boolean' || value === 'auto')
|
|
74
|
+
return value;
|
|
75
|
+
if (!value || typeof value !== 'object')
|
|
76
|
+
return undefined;
|
|
77
|
+
const platformValue = value[platform];
|
|
78
|
+
return typeof platformValue === 'boolean' || platformValue === 'auto'
|
|
79
|
+
? platformValue
|
|
80
|
+
: undefined;
|
|
81
|
+
};
|
|
82
|
+
const detectBoolean = (contents, truePatterns, falsePatterns) => {
|
|
83
|
+
const joined = contents.filter((content) => !!content).join('\n');
|
|
84
|
+
if (!joined)
|
|
85
|
+
return undefined;
|
|
86
|
+
if (falsePatterns.some(pattern => pattern.test(joined)))
|
|
87
|
+
return false;
|
|
88
|
+
if (truePatterns.some(pattern => pattern.test(joined)))
|
|
89
|
+
return true;
|
|
90
|
+
return undefined;
|
|
91
|
+
};
|
|
92
|
+
const readIosProjectSettings = (projectRoot) => {
|
|
93
|
+
const iosDir = path.join(projectRoot, 'ios');
|
|
94
|
+
if (!fs.existsSync(iosDir))
|
|
95
|
+
return null;
|
|
96
|
+
const projectFiles = fs
|
|
97
|
+
.readdirSync(iosDir)
|
|
98
|
+
.filter(fileName => fileName.endsWith('.xcodeproj'))
|
|
99
|
+
.map(fileName => path.join(iosDir, fileName, 'project.pbxproj'));
|
|
100
|
+
const contents = projectFiles
|
|
101
|
+
.map(readTextIfExists)
|
|
102
|
+
.filter((content) => Boolean(content));
|
|
103
|
+
return contents.length ? contents.join('\n') : null;
|
|
104
|
+
};
|
|
105
|
+
const readHermesHelp = (hermescPath) => {
|
|
106
|
+
try {
|
|
107
|
+
return String((0, child_process_1.execSync)(`"${hermescPath}" -help`, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }));
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return '';
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const hermesHelpIncludesFlag = (help, flag) => new RegExp(`(?:^|\\n)\\s*${flag.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?:\\s|=)`).test(help);
|
|
114
|
+
const buildHermesFlags = (hermescPath, generateSourceMap) => {
|
|
115
|
+
const help = readHermesHelp(hermescPath);
|
|
116
|
+
const flags = ['-emit-binary'];
|
|
117
|
+
if (hermesHelpIncludesFlag(help, '-O')) {
|
|
118
|
+
flags.push('-O');
|
|
119
|
+
}
|
|
120
|
+
if (hermesHelpIncludesFlag(help, '-g0')) {
|
|
121
|
+
flags.push('-g0');
|
|
122
|
+
}
|
|
123
|
+
if (generateSourceMap && hermesHelpIncludesFlag(help, '-output-source-map')) {
|
|
124
|
+
flags.push('-output-source-map');
|
|
125
|
+
}
|
|
126
|
+
return flags;
|
|
127
|
+
};
|
|
128
|
+
const detectHermesFromNativeProject = (projectRoot, platform) => {
|
|
129
|
+
if (platform === 'android') {
|
|
130
|
+
return detectBoolean([
|
|
131
|
+
readTextIfExists(path.join(projectRoot, 'android', 'gradle.properties')),
|
|
132
|
+
readTextIfExists(path.join(projectRoot, 'android', 'app', 'build.gradle')),
|
|
133
|
+
readTextIfExists(path.join(projectRoot, 'android', 'app', 'build.gradle.kts')),
|
|
134
|
+
], [
|
|
135
|
+
/(?:^|\n)\s*hermesEnabled\s*=\s*true\b/,
|
|
136
|
+
/\bhermesEnabled\s+(?:=|\()\s*true\b/,
|
|
137
|
+
/\benableHermes\s*[:=]\s*true\b/,
|
|
138
|
+
], [
|
|
139
|
+
/(?:^|\n)\s*hermesEnabled\s*=\s*false\b/,
|
|
140
|
+
/\bhermesEnabled\s+(?:=|\()\s*false\b/,
|
|
141
|
+
/\benableHermes\s*[:=]\s*false\b/,
|
|
142
|
+
]);
|
|
143
|
+
}
|
|
144
|
+
return detectBoolean([
|
|
145
|
+
readTextIfExists(path.join(projectRoot, 'ios', 'Podfile')),
|
|
146
|
+
readIosProjectSettings(projectRoot),
|
|
147
|
+
], [
|
|
148
|
+
/:hermes_enabled\s*=>\s*true\b/,
|
|
149
|
+
/\bhermes_enabled\s*:\s*true\b/,
|
|
150
|
+
/\bhermesEnabled\s*[:=]\s*true\b/,
|
|
151
|
+
/\bUSE_HERMES\s*=\s*true\s*;/,
|
|
152
|
+
], [
|
|
153
|
+
/:hermes_enabled\s*=>\s*false\b/,
|
|
154
|
+
/\bhermes_enabled\s*:\s*false\b/,
|
|
155
|
+
/\bhermesEnabled\s*[:=]\s*false\b/,
|
|
156
|
+
/\bUSE_HERMES\s*=\s*false\s*;/,
|
|
157
|
+
]);
|
|
158
|
+
};
|
|
159
|
+
const shouldCompileHermesBytecode = (cfg, platform, projectRoot) => {
|
|
160
|
+
const explicit = readPlatformSetting(cfg.hermesBytecode, platform) ??
|
|
161
|
+
readPlatformSetting(cfg.hermes, platform);
|
|
162
|
+
if (typeof explicit === 'boolean')
|
|
163
|
+
return explicit;
|
|
164
|
+
const detected = detectHermesFromNativeProject(projectRoot, platform);
|
|
165
|
+
if (detected !== undefined)
|
|
166
|
+
return detected;
|
|
167
|
+
if (explicit === 'auto') {
|
|
168
|
+
console.warn(`⚠️ Could not detect Hermes for ${platform}; set hermesBytecode.${platform} in bundle.drop.config.js to opt in explicitly.`);
|
|
169
|
+
}
|
|
170
|
+
return false;
|
|
171
|
+
};
|
|
50
172
|
function runBundleScript(options) {
|
|
51
173
|
const packageRoot = getPackageRoot();
|
|
52
174
|
const platform = options?.platform || process.argv[2] || 'ios';
|
|
@@ -60,25 +182,31 @@ function runBundleScript(options) {
|
|
|
60
182
|
const assetsDir = path.join(outputDir, 'assets');
|
|
61
183
|
const bundlePath = path.join(outputDir, 'main.jsbundle');
|
|
62
184
|
const metadataPath = path.join(outputDir, `metadata-${fileSuffix}.json`);
|
|
185
|
+
const manifestPath = path.join(outputDir, bundleManifest_1.BUNDLE_MANIFEST);
|
|
63
186
|
const sourceMapPath = path.join(outputDir, 'main.jsbundle.map');
|
|
64
187
|
const zipPath = path.join(outputDir, `bundle-${platform}.zip`);
|
|
65
188
|
const imageManifest = {};
|
|
66
189
|
const projectRoot = (0, projectRoot_1.findProjectRoot)(options?.cwd || process.cwd());
|
|
67
190
|
const generateSourceMap = options?.sourcemap ?? process.argv.includes('--sourcemap');
|
|
191
|
+
const appVersion = process.env.BUNDLE_DROP_APP_VERSION;
|
|
68
192
|
let runtimeVersion;
|
|
69
193
|
const configPath = path.resolve(projectRoot, 'bundle.drop.config.js');
|
|
70
|
-
if (fs.existsSync(configPath)) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
runtimeVersion = cfg?.runtimeVersion?.[platform];
|
|
74
|
-
if (!runtimeVersion) {
|
|
75
|
-
console.warn(`⚠️ No runtimeVersion found for ${platform} in bundle.drop.config.js. Example: runtimeVersion: { ios: "1.0.0", android: "1.0.0" }`);
|
|
76
|
-
}
|
|
194
|
+
if (!fs.existsSync(configPath)) {
|
|
195
|
+
console.error('❌ bundle.drop.config.js not found in project root');
|
|
196
|
+
process.exit(1);
|
|
77
197
|
}
|
|
78
|
-
|
|
79
|
-
|
|
198
|
+
//eslint-disable-next-line
|
|
199
|
+
const cfg = require(configPath);
|
|
200
|
+
runtimeVersion = cfg?.runtimeVersion?.[platform];
|
|
201
|
+
if (!runtimeVersion) {
|
|
202
|
+
console.error(`❌ Missing runtimeVersion.${platform} in bundle.drop.config.js. Example: runtimeVersion: { ios: "1.0.0", android: "1.0.0" }`);
|
|
203
|
+
process.exit(1);
|
|
204
|
+
}
|
|
205
|
+
if (!appVersion) {
|
|
206
|
+
console.error('❌ BUNDLE_DROP_APP_VERSION is required so bundle-manifest.json can include the app version');
|
|
207
|
+
process.exit(1);
|
|
80
208
|
}
|
|
81
|
-
[bundlePath, zipPath, metadataPath, sourceMapPath].forEach(file => {
|
|
209
|
+
[bundlePath, zipPath, metadataPath, manifestPath, sourceMapPath].forEach(file => {
|
|
82
210
|
if (fs.existsSync(file))
|
|
83
211
|
fs.unlinkSync(file);
|
|
84
212
|
});
|
|
@@ -102,15 +230,17 @@ function runBundleScript(options) {
|
|
|
102
230
|
: 'linux64-bin';
|
|
103
231
|
const hermesLocations = [
|
|
104
232
|
path.join(projectRoot, 'node_modules', 'react-native', 'sdks', 'hermesc', osBin, 'hermesc'),
|
|
233
|
+
path.join(projectRoot, 'node_modules', 'hermes-compiler', 'hermesc', osBin, 'hermesc'),
|
|
105
234
|
path.join(projectRoot, 'node_modules', 'hermes-engine', osBin, 'hermesc'),
|
|
106
235
|
];
|
|
107
236
|
const hermescPath = hermesLocations.find(p => fs.existsSync(p));
|
|
108
|
-
|
|
237
|
+
const hermesEnabled = shouldCompileHermesBytecode(cfg, platform, projectRoot);
|
|
238
|
+
if (hermesEnabled && hermescPath) {
|
|
109
239
|
const hbcPath = bundlePath + '.hbc';
|
|
110
|
-
const hermesMapFlag = generateSourceMap ? ` -output-source-map` : '';
|
|
111
240
|
try {
|
|
112
241
|
console.log(`🔥 Compiling to Hermes bytecode (${platform})...`);
|
|
113
|
-
(
|
|
242
|
+
const hermesFlags = buildHermesFlags(hermescPath, generateSourceMap).join(' ');
|
|
243
|
+
(0, child_process_1.execSync)(`"${hermescPath}" ${hermesFlags} -out "${hbcPath}" "${bundlePath}"`, { stdio: ['ignore', 'ignore', 'ignore'] });
|
|
114
244
|
fs.renameSync(hbcPath, bundlePath);
|
|
115
245
|
console.log('✅ Hermes bytecode compiled');
|
|
116
246
|
}
|
|
@@ -140,27 +270,29 @@ function runBundleScript(options) {
|
|
|
140
270
|
fs.unlinkSync(hermesMapPath);
|
|
141
271
|
}
|
|
142
272
|
}
|
|
273
|
+
else if (hermesEnabled) {
|
|
274
|
+
console.log('ℹ️ Hermes compiler not found — bundling plain JS');
|
|
275
|
+
}
|
|
143
276
|
else {
|
|
144
|
-
console.log(
|
|
277
|
+
console.log(`ℹ️ Hermes bytecode disabled for ${platform} — bundling plain JS`);
|
|
145
278
|
}
|
|
146
279
|
const bundleBuffer = fs.readFileSync(bundlePath);
|
|
147
|
-
const
|
|
280
|
+
const jsBundleHash = sha256Buffer(bundleBuffer);
|
|
148
281
|
const metadata = {
|
|
149
282
|
platform,
|
|
150
|
-
|
|
151
|
-
timestamp: new Date().toISOString(),
|
|
283
|
+
jsBundleHash,
|
|
152
284
|
bundlePath: 'main.jsbundle',
|
|
153
285
|
sizeInBytes: bundleBuffer.length,
|
|
154
286
|
};
|
|
155
287
|
if (runtimeVersion) {
|
|
156
288
|
metadata.runtimeVersion = runtimeVersion;
|
|
157
289
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
290
|
+
const stagedFiles = new Map();
|
|
291
|
+
stagedFiles.set('main.jsbundle', bundleBuffer);
|
|
292
|
+
const metadataFilePath = `metadata-${fileSuffix}.json`;
|
|
293
|
+
const metadataBuffer = Buffer.from(JSON.stringify(metadata, null, 2));
|
|
294
|
+
stagedFiles.set(metadataFilePath, metadataBuffer);
|
|
161
295
|
const zip = new adm_zip_1.default();
|
|
162
|
-
zip.addFile('main.jsbundle', bundleBuffer);
|
|
163
|
-
zip.addFile(`metadata-${fileSuffix}.json`, Buffer.from(JSON.stringify(metadata, null, 2)));
|
|
164
296
|
const addAssetsToZip = (dir) => {
|
|
165
297
|
const items = fs.readdirSync(dir);
|
|
166
298
|
for (const item of items) {
|
|
@@ -172,28 +304,40 @@ function runBundleScript(options) {
|
|
|
172
304
|
}
|
|
173
305
|
else {
|
|
174
306
|
const buffer = fs.readFileSync(fullPath);
|
|
175
|
-
|
|
307
|
+
stagedFiles.set((0, bundleManifest_1.normalizeManifestPath)(normalizedPath), buffer);
|
|
176
308
|
if (isAndroid) {
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
const manifestKeyNoPrefix = manifestKey.replace(/^assets\//, '');
|
|
180
|
-
const baseNameKey = manifestKey.split('/').pop() || manifestKey;
|
|
181
|
-
const baseWithExt = normalizedPath.split('/').pop() || normalizedPath;
|
|
182
|
-
imageManifest[manifestKey] = normalizedPath;
|
|
183
|
-
imageManifest[manifestKeyNoPrefix] = normalizedPath;
|
|
184
|
-
imageManifest[withAssetsPrefix.replace(/\.[^.]+$/, '')] = normalizedPath;
|
|
185
|
-
imageManifest[baseNameKey] = normalizedPath;
|
|
186
|
-
imageManifest[baseWithExt] = normalizedPath;
|
|
309
|
+
const manifestKey = (0, bundleManifest_1.normalizeManifestPath)(normalizedPath).replace(/^assets\//, '');
|
|
310
|
+
imageManifest[manifestKey] = (0, bundleManifest_1.normalizeManifestPath)(normalizedPath);
|
|
187
311
|
}
|
|
188
312
|
}
|
|
189
313
|
}
|
|
190
314
|
};
|
|
191
315
|
addAssetsToZip(assetsDir);
|
|
192
|
-
if (isAndroid
|
|
193
|
-
|
|
316
|
+
if (isAndroid) {
|
|
317
|
+
stagedFiles.set('image-manifest.json', Buffer.from(JSON.stringify(imageManifest, null, 2)));
|
|
194
318
|
console.log(`🧩 Injected image-manifest.json with ${Object.keys(imageManifest).length} entries`);
|
|
195
319
|
}
|
|
320
|
+
const files = [...stagedFiles.entries()].map(([filePath, buffer]) => createFileEntry(filePath, buffer));
|
|
321
|
+
fs.writeFileSync(metadataPath, metadataBuffer);
|
|
322
|
+
const bundleHash = (0, bundleManifest_1.calculateBundleHash)(files);
|
|
323
|
+
const manifest = (0, bundleManifest_1.createBundleManifest)({
|
|
324
|
+
bundleHash,
|
|
325
|
+
jsBundleHash,
|
|
326
|
+
platform,
|
|
327
|
+
runtimeVersion,
|
|
328
|
+
version: appVersion,
|
|
329
|
+
files,
|
|
330
|
+
});
|
|
331
|
+
const manifestBuffer = Buffer.from(JSON.stringify(manifest, null, 2));
|
|
332
|
+
stagedFiles.set(bundleManifest_1.BUNDLE_MANIFEST, manifestBuffer);
|
|
333
|
+
fs.writeFileSync(manifestPath, manifestBuffer);
|
|
334
|
+
console.log('🧠 Metadata saved');
|
|
335
|
+
console.log('📌 Bundle Hash:', bundleHash);
|
|
336
|
+
console.log('📌 JS Bundle Hash:', jsBundleHash);
|
|
196
337
|
console.log('📦 Zipping bundle...');
|
|
338
|
+
for (const [filePath, buffer] of stagedFiles.entries()) {
|
|
339
|
+
zip.addFile(filePath, buffer);
|
|
340
|
+
}
|
|
197
341
|
zip.writeZip(zipPath);
|
|
198
342
|
console.log('✅ OTA bundle zipped');
|
|
199
343
|
return {
|
|
@@ -204,9 +348,13 @@ function runBundleScript(options) {
|
|
|
204
348
|
metadataPath,
|
|
205
349
|
zipPath,
|
|
206
350
|
runtimeVersion,
|
|
207
|
-
hash,
|
|
351
|
+
hash: bundleHash,
|
|
352
|
+
bundleHash,
|
|
353
|
+
jsBundleHash,
|
|
354
|
+
manifestPath,
|
|
208
355
|
};
|
|
209
356
|
}
|
|
357
|
+
/* istanbul ignore next */
|
|
210
358
|
if (require.main === module) {
|
|
211
359
|
runBundleScript();
|
|
212
360
|
}
|
|
@@ -70,7 +70,7 @@ async function runDownloadBundle(options) {
|
|
|
70
70
|
const runtimeVersion = config?.runtimeVersion?.[platform] || config?.runtimeVersion?.[platform];
|
|
71
71
|
const channelName = argv[3] || config?.defaultChannel || 'General';
|
|
72
72
|
const resolveEndpoint = `${serverUrl}/projects/${encodeURIComponent(project.slug)}/ota/resolve`;
|
|
73
|
-
const outputPath = path.join(outputDir, `
|
|
73
|
+
const outputPath = path.join(outputDir, `bundle-${platform}.zip`);
|
|
74
74
|
if (!fs.existsSync(outputDir)) {
|
|
75
75
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
76
76
|
}
|
|
@@ -83,9 +83,16 @@ async function runDownloadBundle(options) {
|
|
|
83
83
|
channelName,
|
|
84
84
|
platform,
|
|
85
85
|
runtimeVersion: runtimeVersion ?? null,
|
|
86
|
+
environment: null,
|
|
86
87
|
currentHash: null,
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
rejectedHashes: [],
|
|
89
|
+
installId: 'cli-download',
|
|
90
|
+
currentUserProperties: {},
|
|
91
|
+
transport: {
|
|
92
|
+
manifestVersion: 1,
|
|
93
|
+
patchAlgorithms: [],
|
|
94
|
+
supportsContentAddressedAssets: true,
|
|
95
|
+
},
|
|
89
96
|
}, {
|
|
90
97
|
headers: {
|
|
91
98
|
Accept: 'application/json',
|
|
@@ -94,15 +101,19 @@ async function runDownloadBundle(options) {
|
|
|
94
101
|
timeout: 15000,
|
|
95
102
|
});
|
|
96
103
|
const decision = resolveResponse.data;
|
|
97
|
-
const bundleDownloadUrl = decision?.action === 'INSTALL'
|
|
104
|
+
const bundleDownloadUrl = decision?.action === 'INSTALL' && decision?.mode === 'patch'
|
|
105
|
+
? decision?.fallback?.downloadUrl
|
|
106
|
+
: decision?.action === 'INSTALL'
|
|
107
|
+
? decision?.target?.downloadUrl
|
|
108
|
+
: null;
|
|
98
109
|
if (!bundleDownloadUrl) {
|
|
99
|
-
console.error('❌ Resolve did not return an INSTALL decision with a downloadUrl');
|
|
110
|
+
console.error('❌ Resolve did not return an INSTALL decision with a full bundle downloadUrl');
|
|
100
111
|
process.exit(1);
|
|
101
112
|
}
|
|
102
|
-
console.log(`⬇️ Downloading latest ${platform} bundle from signed URL...`);
|
|
113
|
+
console.log(`⬇️ Downloading latest ${platform} full bundle ZIP from signed URL...`);
|
|
103
114
|
const bundleResponse = await axios_1.default.get(bundleDownloadUrl, { responseType: 'arraybuffer' });
|
|
104
115
|
await fs.promises.writeFile(outputPath, Buffer.from(bundleResponse.data));
|
|
105
|
-
console.log(`✅ Bundle downloaded and saved to: ${outputPath}`);
|
|
116
|
+
console.log(`✅ Bundle ZIP downloaded and saved to: ${outputPath}`);
|
|
106
117
|
return outputPath;
|
|
107
118
|
}
|
|
108
119
|
catch (err) {
|