@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
package/lib/api/clientApi.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { AxiosResponse } from 'axios';
|
|
2
|
-
import { OtaResolveRequest, OtaResolveResponse, PublicChannelsParams, ReportInstalledPayload, ReportLocalRollbackPayload, BundleListParams, BundleListResponse } from './types';
|
|
2
|
+
import { OtaResolveRequest, OtaResolveResponse, PublicChannelsParams, ReportInstalledPayload, ReportPatchApplyFailurePayload, ReportLocalRollbackPayload, BundleListParams, BundleListResponse } from './types';
|
|
3
3
|
export declare function postOtaResolve(projectSlug: string, payload: OtaResolveRequest): Promise<AxiosResponse<OtaResolveResponse>>;
|
|
4
4
|
export declare function getPublicChannels(params: PublicChannelsParams): Promise<AxiosResponse<string[]>>;
|
|
5
5
|
export declare function reportInstalled(projectSlug: string, hash: string, payload: ReportInstalledPayload): Promise<AxiosResponse<void>>;
|
|
6
|
+
export declare function reportPatchApplyFailure(projectSlug: string, payload: ReportPatchApplyFailurePayload): Promise<AxiosResponse<void>>;
|
|
6
7
|
export declare function reportLocalRollback(projectSlug: string, hash: string, payload: ReportLocalRollbackPayload): Promise<AxiosResponse<void>>;
|
|
7
8
|
export declare function getBundleList(projectSlug: string, params: BundleListParams): Promise<AxiosResponse<BundleListResponse>>;
|
package/lib/api/clientApi.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.postOtaResolve = postOtaResolve;
|
|
4
4
|
exports.getPublicChannels = getPublicChannels;
|
|
5
5
|
exports.reportInstalled = reportInstalled;
|
|
6
|
+
exports.reportPatchApplyFailure = reportPatchApplyFailure;
|
|
6
7
|
exports.reportLocalRollback = reportLocalRollback;
|
|
7
8
|
exports.getBundleList = getBundleList;
|
|
8
9
|
const client_1 = require("./client");
|
|
@@ -31,6 +32,14 @@ function reportInstalled(projectSlug, hash, payload) {
|
|
|
31
32
|
timeout: 3000,
|
|
32
33
|
});
|
|
33
34
|
}
|
|
35
|
+
function reportPatchApplyFailure(projectSlug, payload) {
|
|
36
|
+
return client_1.apiClient.post(`/projects/${encodeURIComponent(projectSlug)}/ota/patch/apply-failure`, payload, {
|
|
37
|
+
headers: {
|
|
38
|
+
Accept: 'application/json',
|
|
39
|
+
},
|
|
40
|
+
timeout: 3000,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
34
43
|
function reportLocalRollback(projectSlug, hash, payload) {
|
|
35
44
|
return client_1.apiClient.post(`/projects/${encodeURIComponent(projectSlug)}/bundle/${encodeURIComponent(hash)}/local-rollback-report`, payload, {
|
|
36
45
|
headers: {
|
package/lib/api/types.d.ts
CHANGED
|
@@ -1,15 +1,36 @@
|
|
|
1
1
|
import type { UserProperties } from '../fs/userProperties';
|
|
2
|
+
import type { SupportedPatchAlgorithm } from '../patchAlgorithms';
|
|
2
3
|
export type OtaResolveRequest = {
|
|
3
4
|
channelName: string;
|
|
4
5
|
platform: string;
|
|
5
|
-
runtimeVersion
|
|
6
|
-
environment
|
|
7
|
-
currentHash
|
|
8
|
-
currentUserProperties
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
runtimeVersion: string | null;
|
|
7
|
+
environment: string | null;
|
|
8
|
+
currentHash: string | null;
|
|
9
|
+
currentUserProperties: UserProperties;
|
|
10
|
+
rejectedHashes: string[];
|
|
11
|
+
installId: string;
|
|
12
|
+
transport: {
|
|
13
|
+
manifestVersion: 1;
|
|
14
|
+
patchAlgorithms: string[];
|
|
15
|
+
supportsContentAddressedAssets: boolean;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export type OtaInstallTarget = {
|
|
19
|
+
bundleHash: string;
|
|
20
|
+
downloadUrl?: string;
|
|
21
|
+
manifestUrl: string;
|
|
22
|
+
bundleVersion?: number;
|
|
23
|
+
version?: string;
|
|
24
|
+
runtimeVersion: string;
|
|
25
|
+
};
|
|
26
|
+
export type OtaPatchSet = {
|
|
27
|
+
algorithm: string;
|
|
28
|
+
patchSetHash: string;
|
|
29
|
+
patchesUrl: string;
|
|
30
|
+
assets?: {
|
|
31
|
+
missingAssetsUrl?: string | null;
|
|
32
|
+
missingAssetsHash?: string | null;
|
|
33
|
+
};
|
|
13
34
|
};
|
|
14
35
|
export type OtaResolveResponse = {
|
|
15
36
|
action: 'NOOP';
|
|
@@ -21,12 +42,19 @@ export type OtaResolveResponse = {
|
|
|
21
42
|
reason?: string;
|
|
22
43
|
} | {
|
|
23
44
|
action: 'INSTALL';
|
|
24
|
-
|
|
25
|
-
|
|
45
|
+
mode: 'full';
|
|
46
|
+
target: OtaInstallTarget & {
|
|
47
|
+
downloadUrl: string;
|
|
48
|
+
};
|
|
49
|
+
} | {
|
|
50
|
+
action: 'INSTALL';
|
|
51
|
+
mode: 'patch';
|
|
52
|
+
baseHash: string;
|
|
53
|
+
target: OtaInstallTarget;
|
|
54
|
+
patchSet: OtaPatchSet;
|
|
55
|
+
fallback: {
|
|
56
|
+
mode: 'full';
|
|
26
57
|
downloadUrl: string;
|
|
27
|
-
bundleVersion?: number;
|
|
28
|
-
version?: string;
|
|
29
|
-
runtimeVersion?: string;
|
|
30
58
|
};
|
|
31
59
|
};
|
|
32
60
|
/**
|
|
@@ -44,6 +72,21 @@ export type UpdateCheckResponse = {
|
|
|
44
72
|
version?: string;
|
|
45
73
|
/** Target bundle hash when an install is available. */
|
|
46
74
|
hash?: string;
|
|
75
|
+
/** Canonical full-tree bundle hash when an install is available. */
|
|
76
|
+
bundleHash?: string;
|
|
77
|
+
/** Response transport selected by the server. */
|
|
78
|
+
mode?: 'full' | 'patch';
|
|
79
|
+
/** Base bundle hash required when mode is patch. */
|
|
80
|
+
baseHash?: string;
|
|
81
|
+
/** Patch-set transport metadata when mode is patch. */
|
|
82
|
+
patchSet?: OtaPatchSet;
|
|
83
|
+
/** Full bundle fallback for patch responses. */
|
|
84
|
+
fallback?: {
|
|
85
|
+
mode: 'full';
|
|
86
|
+
downloadUrl: string;
|
|
87
|
+
};
|
|
88
|
+
/** Target manifest URL, when provided by the server. */
|
|
89
|
+
manifestUrl?: string;
|
|
47
90
|
/** Signed or public download URL for the target bundle. */
|
|
48
91
|
downloadUrl?: string;
|
|
49
92
|
/** Channel used for this resolve decision. */
|
|
@@ -63,6 +106,15 @@ export type UpdateCheckResponse = {
|
|
|
63
106
|
/** Latest runtime version available on the channel when the current runtime is incompatible. */
|
|
64
107
|
latestRuntimeVersionOnChannel?: string;
|
|
65
108
|
};
|
|
109
|
+
export type ReportPatchApplyFailurePayload = {
|
|
110
|
+
platform: string;
|
|
111
|
+
runtimeVersion: string;
|
|
112
|
+
installId?: string;
|
|
113
|
+
baseHash?: string;
|
|
114
|
+
targetHash: string;
|
|
115
|
+
algorithm?: SupportedPatchAlgorithm;
|
|
116
|
+
reason?: string;
|
|
117
|
+
};
|
|
66
118
|
export type PublicChannelsParams = {
|
|
67
119
|
projectSlug: string;
|
|
68
120
|
};
|
package/lib/bundleInfo.d.ts
CHANGED
|
@@ -18,6 +18,8 @@ export type BundleInfo = {
|
|
|
18
18
|
pendingApply?: boolean;
|
|
19
19
|
/** Last bundle hash successfully reported to the backend as installed. */
|
|
20
20
|
lastInstalledReportedHash?: string;
|
|
21
|
+
/** Bundle hashes already reported as installed for this app install. */
|
|
22
|
+
installedReportedHashes?: string[];
|
|
21
23
|
/** Runtime version the bundle is compatible with. */
|
|
22
24
|
runtimeVersion?: string;
|
|
23
25
|
};
|
|
@@ -7,7 +7,8 @@ export declare function readCurrentBundlePointer(): Promise<BundlePointer | null
|
|
|
7
7
|
export declare function readPreviousBundlePointer(): Promise<BundlePointer | null>;
|
|
8
8
|
export declare function writeCurrentBundlePointer(pointer: BundlePointer): Promise<void>;
|
|
9
9
|
export declare function writePreviousBundlePointer(pointer: BundlePointer): Promise<void>;
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function restorePreviousBundlePointer(pointer: BundlePointer | null): Promise<void>;
|
|
11
|
+
export declare function setCurrentBundlePointer(_bundlePath: string, hash: string, options?: {
|
|
11
12
|
setPrevious?: boolean;
|
|
12
13
|
}): Promise<void>;
|
|
13
14
|
export declare function rollbackToPreviousPointer(): Promise<BundlePointer | null>;
|
package/lib/fs/bundlePointer.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.readCurrentBundlePointer = readCurrentBundlePointer;
|
|
|
7
7
|
exports.readPreviousBundlePointer = readPreviousBundlePointer;
|
|
8
8
|
exports.writeCurrentBundlePointer = writeCurrentBundlePointer;
|
|
9
9
|
exports.writePreviousBundlePointer = writePreviousBundlePointer;
|
|
10
|
+
exports.restorePreviousBundlePointer = restorePreviousBundlePointer;
|
|
10
11
|
exports.setCurrentBundlePointer = setCurrentBundlePointer;
|
|
11
12
|
exports.rollbackToPreviousPointer = rollbackToPreviousPointer;
|
|
12
13
|
exports.deleteCurrentBundlePointer = deleteCurrentBundlePointer;
|
|
@@ -17,15 +18,21 @@ const context_1 = require("../context");
|
|
|
17
18
|
const fsUtils_1 = require("./fsUtils");
|
|
18
19
|
const CURRENT_POINTER_PATH = `${context_1.BUNDLE_DROP_ROOT}/current.json`;
|
|
19
20
|
const PREVIOUS_POINTER_PATH = `${context_1.BUNDLE_DROP_ROOT}/previous.json`;
|
|
21
|
+
const BUNDLE_HASH_PATTERN = /^[a-f0-9]{64}$/;
|
|
22
|
+
const bundlePathForHash = (hash) => `${context_1.BUNDLE_DROP_ROOT}/bundles/${hash}/main.jsbundle`;
|
|
20
23
|
async function readPointer(path) {
|
|
21
24
|
try {
|
|
22
25
|
if (!(await fs_1.default.exists(path)))
|
|
23
26
|
return null;
|
|
24
27
|
const raw = await fs_1.default.readFile(path, 'utf8');
|
|
25
28
|
const parsed = JSON.parse(raw);
|
|
26
|
-
if (!parsed?.hash
|
|
29
|
+
if (!BUNDLE_HASH_PATTERN.test(parsed?.hash ?? ''))
|
|
27
30
|
return null;
|
|
28
|
-
return
|
|
31
|
+
return {
|
|
32
|
+
hash: parsed.hash,
|
|
33
|
+
bundlePath: bundlePathForHash(parsed.hash),
|
|
34
|
+
updatedAt: typeof parsed.updatedAt === 'string' ? parsed.updatedAt : '',
|
|
35
|
+
};
|
|
29
36
|
}
|
|
30
37
|
catch {
|
|
31
38
|
return null;
|
|
@@ -38,16 +45,26 @@ async function readPreviousBundlePointer() {
|
|
|
38
45
|
return readPointer(PREVIOUS_POINTER_PATH);
|
|
39
46
|
}
|
|
40
47
|
async function writeCurrentBundlePointer(pointer) {
|
|
48
|
+
assertCanonicalPointerHash(pointer.hash);
|
|
41
49
|
const root = context_1.BUNDLE_DROP_ROOT;
|
|
42
50
|
await (0, fsUtils_1.ensureDir)(root);
|
|
43
|
-
await (0, fsUtils_1.atomicWriteJson)(CURRENT_POINTER_PATH, pointer);
|
|
51
|
+
await (0, fsUtils_1.atomicWriteJson)(CURRENT_POINTER_PATH, pointerJson(pointer));
|
|
44
52
|
}
|
|
45
53
|
async function writePreviousBundlePointer(pointer) {
|
|
54
|
+
assertCanonicalPointerHash(pointer.hash);
|
|
46
55
|
const root = context_1.BUNDLE_DROP_ROOT;
|
|
47
56
|
await (0, fsUtils_1.ensureDir)(root);
|
|
48
|
-
await (0, fsUtils_1.atomicWriteJson)(PREVIOUS_POINTER_PATH, pointer);
|
|
57
|
+
await (0, fsUtils_1.atomicWriteJson)(PREVIOUS_POINTER_PATH, pointerJson(pointer));
|
|
49
58
|
}
|
|
50
|
-
async function
|
|
59
|
+
async function restorePreviousBundlePointer(pointer) {
|
|
60
|
+
if (pointer) {
|
|
61
|
+
await writePreviousBundlePointer({ ...pointer, updatedAt: new Date().toISOString() });
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
await deletePreviousBundlePointer();
|
|
65
|
+
}
|
|
66
|
+
async function setCurrentBundlePointer(_bundlePath, hash, options) {
|
|
67
|
+
assertCanonicalPointerHash(hash);
|
|
51
68
|
const root = context_1.BUNDLE_DROP_ROOT;
|
|
52
69
|
await (0, fsUtils_1.ensureDir)(root);
|
|
53
70
|
const current = await readCurrentBundlePointer();
|
|
@@ -56,10 +73,21 @@ async function setCurrentBundlePointer(bundlePath, hash, options) {
|
|
|
56
73
|
}
|
|
57
74
|
await writeCurrentBundlePointer({
|
|
58
75
|
hash,
|
|
59
|
-
bundlePath,
|
|
76
|
+
bundlePath: bundlePathForHash(hash),
|
|
60
77
|
updatedAt: new Date().toISOString(),
|
|
61
78
|
});
|
|
62
79
|
}
|
|
80
|
+
function pointerJson(pointer) {
|
|
81
|
+
return {
|
|
82
|
+
hash: pointer.hash,
|
|
83
|
+
updatedAt: pointer.updatedAt,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function assertCanonicalPointerHash(hash) {
|
|
87
|
+
if (!BUNDLE_HASH_PATTERN.test(hash)) {
|
|
88
|
+
throw new Error('Bundle pointer hash must be a canonical 64-character lowercase SHA-256 hash');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
63
91
|
async function rollbackToPreviousPointer() {
|
|
64
92
|
const previous = await readPreviousBundlePointer();
|
|
65
93
|
if (!previous)
|
package/lib/fs/fsUtils.js
CHANGED
|
@@ -10,7 +10,10 @@ const fs_1 = __importDefault(require("../native/fs"));
|
|
|
10
10
|
async function cleanOrphanedTempZips(bundlesDir) {
|
|
11
11
|
try {
|
|
12
12
|
const entries = await fs_1.default.readDir(bundlesDir);
|
|
13
|
-
const temps = entries.filter(n => n.startsWith('_tmp_')
|
|
13
|
+
const temps = entries.filter(n => n.startsWith('_tmp_') ||
|
|
14
|
+
n.startsWith('_patch_') ||
|
|
15
|
+
n.startsWith('_patch_target_') ||
|
|
16
|
+
n.startsWith('_patch_assets_'));
|
|
14
17
|
await Promise.all(temps.map(name => fs_1.default.unlink(`${bundlesDir}/${name}`)));
|
|
15
18
|
return temps.length;
|
|
16
19
|
}
|
|
@@ -10,33 +10,131 @@ const react_native_1 = require("react-native");
|
|
|
10
10
|
const fs_1 = __importDefault(require("./native/fs"));
|
|
11
11
|
let hasPatched = false;
|
|
12
12
|
const { BundleDrop } = react_native_1.NativeModules;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
13
|
+
const unique = (values) => Array.from(new Set(values.filter(Boolean)));
|
|
14
|
+
const hasFileExtension = (value) => /\/?[^/.]+\.[^/.]+$/.test(value);
|
|
15
|
+
const ANDROID_BASE_DENSITY = 160;
|
|
16
|
+
const ANDROID_SCALE_SUFFIXES = {
|
|
17
|
+
'0.75': 'ldpi',
|
|
18
|
+
'1': 'mdpi',
|
|
19
|
+
'1.5': 'hdpi',
|
|
20
|
+
'2': 'xhdpi',
|
|
21
|
+
'3': 'xxhdpi',
|
|
22
|
+
'4': 'xxxhdpi',
|
|
23
|
+
};
|
|
24
|
+
const ANDROID_DRAWABLE_FILE_TYPES = new Set([
|
|
25
|
+
'gif',
|
|
26
|
+
'heic',
|
|
27
|
+
'heif',
|
|
28
|
+
'jpeg',
|
|
29
|
+
'jpg',
|
|
30
|
+
'ktx',
|
|
31
|
+
'png',
|
|
32
|
+
'svg',
|
|
33
|
+
'webp',
|
|
34
|
+
'xml',
|
|
35
|
+
]);
|
|
36
|
+
// React Native has moved these between drawable-* and raw output across versions.
|
|
37
|
+
const ANDROID_RESOURCE_LOCATION_DRIFT_FILE_TYPES = new Set(['heic', 'heif', 'svg']);
|
|
38
|
+
function getPackagerAsset(source) {
|
|
39
|
+
if (typeof source === 'number') {
|
|
40
|
+
try {
|
|
41
|
+
const registry = require('react-native/Libraries/Image/AssetRegistry');
|
|
42
|
+
return registry.getAssetByID?.(source);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return source?.__packager_asset ? source : undefined;
|
|
49
|
+
}
|
|
50
|
+
function getAssetBasePath(asset) {
|
|
51
|
+
const basePath = asset.httpServerLocation;
|
|
52
|
+
if (!basePath)
|
|
53
|
+
return undefined;
|
|
54
|
+
return basePath.replace(/^\//, '');
|
|
55
|
+
}
|
|
56
|
+
function getAndroidResourceIdentifier(asset) {
|
|
57
|
+
const basePath = getAssetBasePath(asset);
|
|
58
|
+
if (!basePath || !asset.name)
|
|
59
|
+
return undefined;
|
|
60
|
+
return `${basePath}/${asset.name}`
|
|
61
|
+
.toLowerCase()
|
|
62
|
+
.replace(/\//g, '_')
|
|
63
|
+
.replace(/([^a-z0-9_])/g, '')
|
|
64
|
+
.replace(/^(?:assets|assetsunstable_path)_/, '');
|
|
65
|
+
}
|
|
66
|
+
function getAndroidScaleSuffix(scale) {
|
|
67
|
+
const knownSuffix = ANDROID_SCALE_SUFFIXES[scale.toString()];
|
|
68
|
+
if (knownSuffix)
|
|
69
|
+
return knownSuffix;
|
|
70
|
+
return `${Math.round(scale * ANDROID_BASE_DENSITY)}dpi`;
|
|
71
|
+
}
|
|
72
|
+
function getAssetScaleCandidates(asset, preferredScale) {
|
|
73
|
+
const scales = Array.isArray(asset.scales)
|
|
74
|
+
? asset.scales.filter(scale => Number.isFinite(scale) && scale > 0)
|
|
75
|
+
: [];
|
|
76
|
+
const canUsePreferredScale = typeof preferredScale === 'number'
|
|
77
|
+
&& Number.isFinite(preferredScale)
|
|
78
|
+
&& preferredScale > 0
|
|
79
|
+
&& (scales.length === 0 || scales.includes(preferredScale));
|
|
80
|
+
const preferredScales = canUsePreferredScale
|
|
81
|
+
? [preferredScale]
|
|
82
|
+
: [];
|
|
83
|
+
const candidates = [...preferredScales, ...scales];
|
|
84
|
+
return Array.from(new Set(candidates.length > 0 ? candidates : [1]));
|
|
85
|
+
}
|
|
86
|
+
function getAndroidRawPathCandidates(resourceIdentifier, extension) {
|
|
87
|
+
return [
|
|
88
|
+
`raw/${resourceIdentifier}${extension}`,
|
|
89
|
+
`res/raw/${resourceIdentifier}${extension}`,
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
function getAndroidDrawablePathCandidates(asset, resourceIdentifier, extension, preferredScale) {
|
|
93
|
+
return getAssetScaleCandidates(asset, preferredScale).flatMap(scale => {
|
|
94
|
+
const suffix = getAndroidScaleSuffix(scale);
|
|
95
|
+
const drawablePath = `drawable-${suffix}/${resourceIdentifier}${extension}`;
|
|
96
|
+
return [drawablePath, `res/${drawablePath}`];
|
|
28
97
|
});
|
|
29
|
-
|
|
98
|
+
}
|
|
99
|
+
function getAndroidResourcePathCandidates(asset, resourceIdentifier, extension, preferredScale) {
|
|
100
|
+
if (!resourceIdentifier)
|
|
101
|
+
return [];
|
|
102
|
+
const assetType = asset.type?.toLowerCase();
|
|
103
|
+
if (!assetType)
|
|
104
|
+
return [];
|
|
105
|
+
const hasLocationDrift = ANDROID_RESOURCE_LOCATION_DRIFT_FILE_TYPES.has(assetType);
|
|
106
|
+
const shouldTryDrawable = ANDROID_DRAWABLE_FILE_TYPES.has(assetType) || hasLocationDrift;
|
|
107
|
+
const shouldTryRaw = !ANDROID_DRAWABLE_FILE_TYPES.has(assetType) || hasLocationDrift;
|
|
108
|
+
return [
|
|
109
|
+
...(shouldTryDrawable
|
|
110
|
+
? getAndroidDrawablePathCandidates(asset, resourceIdentifier, extension, preferredScale)
|
|
111
|
+
: []),
|
|
112
|
+
...(shouldTryRaw ? getAndroidRawPathCandidates(resourceIdentifier, extension) : []),
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
function getAssetMetadataCandidates(asset, preferredScale) {
|
|
116
|
+
if (!asset?.name || !asset.type)
|
|
117
|
+
return [];
|
|
118
|
+
const extension = `.${asset.type.toLowerCase()}`;
|
|
119
|
+
const basePath = getAssetBasePath(asset);
|
|
120
|
+
const resourceIdentifier = getAndroidResourceIdentifier(asset);
|
|
121
|
+
const pathWithExtension = basePath ? `${basePath}/${asset.name}${extension}` : undefined;
|
|
122
|
+
const pathWithoutAssetsPrefix = pathWithExtension?.replace(/^assets\//, '');
|
|
123
|
+
return unique([
|
|
124
|
+
pathWithExtension ?? '',
|
|
125
|
+
pathWithoutAssetsPrefix ?? '',
|
|
126
|
+
...getAndroidResourcePathCandidates(asset, resourceIdentifier, extension, preferredScale),
|
|
127
|
+
]);
|
|
30
128
|
}
|
|
31
129
|
function patchImageResolverWithManifest(manifest) {
|
|
32
130
|
if (!manifest || Object.keys(manifest).length === 0) {
|
|
33
131
|
console.warn('🧩 Cannot patch image resolver — empty manifest');
|
|
34
132
|
return;
|
|
35
133
|
}
|
|
36
|
-
const { byKey, byBase } = buildManifestMaps(manifest);
|
|
37
134
|
const originalResolve = react_native_1.Image.resolveAssetSource;
|
|
38
135
|
react_native_1.Image.resolveAssetSource = (source) => {
|
|
39
136
|
const resolved = originalResolve(source);
|
|
137
|
+
const packagerAsset = getPackagerAsset(source);
|
|
40
138
|
if (typeof source !== 'number' && !source?.__packager_asset) {
|
|
41
139
|
return resolved;
|
|
42
140
|
}
|
|
@@ -46,42 +144,31 @@ function patchImageResolverWithManifest(manifest) {
|
|
|
46
144
|
if (/^(https?|data|content):/.test(uri)) {
|
|
47
145
|
return resolved;
|
|
48
146
|
}
|
|
49
|
-
let
|
|
147
|
+
let cleanedKeyWithExtension = uri;
|
|
50
148
|
if (uri.startsWith('file://')) {
|
|
51
149
|
const parts = uri.split('/files/')[1];
|
|
52
|
-
|
|
150
|
+
cleanedKeyWithExtension = parts ?? uri;
|
|
53
151
|
}
|
|
54
152
|
else {
|
|
55
|
-
|
|
153
|
+
cleanedKeyWithExtension = uri
|
|
56
154
|
.replace(/^asset:\/\//, '')
|
|
57
155
|
.replace(/^asset:\//, '')
|
|
58
156
|
.replace(/^assets\//, '')
|
|
59
|
-
.replace(/^res\//, '')
|
|
60
|
-
.replace(/\.[^.]+$/, '');
|
|
157
|
+
.replace(/^res\//, '');
|
|
61
158
|
}
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
159
|
+
const withExtensionWithoutAndroidPrefix = cleanedKeyWithExtension.replace(/^android\//, '');
|
|
160
|
+
const pathCandidates = [
|
|
161
|
+
cleanedKeyWithExtension,
|
|
162
|
+
`res/${cleanedKeyWithExtension}`,
|
|
163
|
+
withExtensionWithoutAndroidPrefix,
|
|
67
164
|
];
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
let finalPath = manifestKey ? byKey[manifestKey] : undefined;
|
|
76
|
-
if (!finalPath) {
|
|
77
|
-
const base = cleanedKey.split('/').pop()?.replace(/\.[^.]+$/, '');
|
|
78
|
-
if (base) {
|
|
79
|
-
finalPath = byBase[base];
|
|
80
|
-
}
|
|
81
|
-
}
|
|
165
|
+
const candidates = unique([
|
|
166
|
+
...getAssetMetadataCandidates(packagerAsset, resolved?.scale),
|
|
167
|
+
...pathCandidates,
|
|
168
|
+
]).filter(hasFileExtension);
|
|
169
|
+
const finalPath = candidates.reduce((match, candidate) => match ?? manifest[candidate], undefined);
|
|
82
170
|
if (finalPath) {
|
|
83
|
-
const
|
|
84
|
-
const fullPath = `file://${fs_1.default.DocumentDirectoryPath}/${finalPath}${hasExtension ? '' : (uri.match(/\.[^.]+$/)?.[0] ?? '')}`;
|
|
171
|
+
const fullPath = `file://${fs_1.default.DocumentDirectoryPath}/${finalPath}`;
|
|
85
172
|
return { ...resolved, uri: fullPath };
|
|
86
173
|
}
|
|
87
174
|
return resolved;
|
|
@@ -93,8 +180,11 @@ function injectBundleDropImageResolver(manifestOverride) {
|
|
|
93
180
|
if (hasPatched && !manifestOverride)
|
|
94
181
|
return;
|
|
95
182
|
try {
|
|
96
|
-
let manifest
|
|
97
|
-
if (
|
|
183
|
+
let manifest;
|
|
184
|
+
if (manifestOverride) {
|
|
185
|
+
manifest = manifestOverride;
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
98
188
|
const raw = BundleDrop.getImageManifestSync?.();
|
|
99
189
|
if (!raw)
|
|
100
190
|
return;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BundleInfo } from '../bundleInfo';
|
|
2
|
+
export declare const assertCanonicalBundleHash: (hash: string, label?: string) => void;
|
|
3
|
+
export type InstallResult = {
|
|
4
|
+
bundlePath: string;
|
|
5
|
+
metadataFromZip: Partial<BundleInfo>;
|
|
6
|
+
};
|
|
7
|
+
export declare const ensureParentDir: (path: string) => Promise<void>;
|
|
8
|
+
export declare const finalizeInstall: (verifiedTempDir: string, fileNames: string[], hash: string, platform: "ios" | "android", statusCb?: (status: string) => void) => Promise<InstallResult>;
|
|
@@ -0,0 +1,97 @@
|
|
|
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.finalizeInstall = exports.ensureParentDir = exports.assertCanonicalBundleHash = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("../native/fs"));
|
|
8
|
+
const context_1 = require("../context");
|
|
9
|
+
const bundlePointer_1 = require("../fs/bundlePointer");
|
|
10
|
+
const fsUtils_1 = require("../fs/fsUtils");
|
|
11
|
+
const errors_1 = require("../errors");
|
|
12
|
+
const bundleManifest_1 = require("../manifest/bundleManifest");
|
|
13
|
+
const bundleVerification_1 = require("./bundleVerification");
|
|
14
|
+
const assertCanonicalBundleHash = (hash, label = 'bundle hash') => {
|
|
15
|
+
if (!/^[a-f0-9]{64}$/.test(hash)) {
|
|
16
|
+
throw new Error(`Invalid ${label}: expected 64 lowercase hex characters`);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
exports.assertCanonicalBundleHash = assertCanonicalBundleHash;
|
|
20
|
+
const ensureParentDir = async (path) => {
|
|
21
|
+
const lastSlash = path.lastIndexOf('/');
|
|
22
|
+
/* istanbul ignore if -- patch reconstruction writes absolute bundle paths. */
|
|
23
|
+
if (lastSlash <= 0)
|
|
24
|
+
return;
|
|
25
|
+
await (0, fsUtils_1.ensureDir)(path.slice(0, lastSlash));
|
|
26
|
+
};
|
|
27
|
+
exports.ensureParentDir = ensureParentDir;
|
|
28
|
+
const ensureMainBundleExists = async (dir) => {
|
|
29
|
+
if (!(await fs_1.default.exists(`${dir}/main.jsbundle`))) {
|
|
30
|
+
throw new errors_1.InstallPhaseError('install', new Error('main.jsbundle missing after promotion'));
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const metadataFileForPlatform = (platform) => platform === 'android' ? 'metadata-android.json' : 'metadata-ios.json';
|
|
34
|
+
const parseMetadataFromDir = async (bundleDir, fileNames, platform) => {
|
|
35
|
+
const metadataFromZip = {};
|
|
36
|
+
const metadataFile = metadataFileForPlatform(platform);
|
|
37
|
+
if (fileNames.includes(bundleManifest_1.BUNDLE_MANIFEST)) {
|
|
38
|
+
const manifest = await (0, bundleVerification_1.readJsonFile)(`${bundleDir}/${bundleManifest_1.BUNDLE_MANIFEST}`);
|
|
39
|
+
metadataFromZip.hash = manifest.bundleHash;
|
|
40
|
+
metadataFromZip.runtimeVersion = manifest.runtimeVersion;
|
|
41
|
+
metadataFromZip.version = manifest.version;
|
|
42
|
+
}
|
|
43
|
+
if (fileNames.includes(metadataFile)) {
|
|
44
|
+
try {
|
|
45
|
+
const parsed = await (0, bundleVerification_1.readJsonFile)(`${bundleDir}/${metadataFile}`);
|
|
46
|
+
if (typeof parsed.bundleVersion === 'number') {
|
|
47
|
+
metadataFromZip.bundleVersion = parsed.bundleVersion;
|
|
48
|
+
}
|
|
49
|
+
if (typeof parsed.version === 'string') {
|
|
50
|
+
metadataFromZip.version = parsed.version;
|
|
51
|
+
}
|
|
52
|
+
if (typeof parsed.runtimeVersion === 'string') {
|
|
53
|
+
metadataFromZip.runtimeVersion = parsed.runtimeVersion;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
console.warn('⚠️ Failed to parse bundle metadata from zip', e);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return metadataFromZip;
|
|
61
|
+
};
|
|
62
|
+
const finalizeInstall = async (verifiedTempDir, fileNames, hash, platform, statusCb) => {
|
|
63
|
+
const bundleDir = `${context_1.BUNDLE_DROP_ROOT}/bundles/${hash}`;
|
|
64
|
+
const bundlePath = `${bundleDir}/main.jsbundle`;
|
|
65
|
+
if (await fs_1.default.exists(bundleDir)) {
|
|
66
|
+
let existingManifest = null;
|
|
67
|
+
try {
|
|
68
|
+
existingManifest = await (0, bundleVerification_1.verifyBundleDir)(bundleDir, hash, platform);
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
const currentPointer = await (0, bundlePointer_1.readCurrentBundlePointer)();
|
|
72
|
+
if (currentPointer?.hash === hash) {
|
|
73
|
+
throw new Error('Active bundle folder failed verification');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (existingManifest) {
|
|
77
|
+
await ensureMainBundleExists(bundleDir);
|
|
78
|
+
const metadataFromZip = await parseMetadataFromDir(bundleDir, fileNames, platform);
|
|
79
|
+
try {
|
|
80
|
+
await fs_1.default.unlink(verifiedTempDir);
|
|
81
|
+
}
|
|
82
|
+
catch { /* best-effort cleanup */ }
|
|
83
|
+
return { bundlePath, metadataFromZip };
|
|
84
|
+
}
|
|
85
|
+
const currentPointer = await (0, bundlePointer_1.readCurrentBundlePointer)();
|
|
86
|
+
if (currentPointer?.hash === hash) {
|
|
87
|
+
throw new Error('Active bundle folder failed verification');
|
|
88
|
+
}
|
|
89
|
+
await fs_1.default.unlink(bundleDir);
|
|
90
|
+
}
|
|
91
|
+
await fs_1.default.moveFile(verifiedTempDir, bundleDir);
|
|
92
|
+
await ensureMainBundleExists(bundleDir);
|
|
93
|
+
statusCb?.(`📁 ${fileNames.length} files extracted`);
|
|
94
|
+
const metadataFromZip = await parseMetadataFromDir(bundleDir, fileNames, platform);
|
|
95
|
+
return { bundlePath, metadataFromZip };
|
|
96
|
+
};
|
|
97
|
+
exports.finalizeInstall = finalizeInstall;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { BundleManifest } from '../manifest/bundleManifest';
|
|
2
|
+
export declare const readJsonFile: <T>(path: string) => Promise<T>;
|
|
3
|
+
export declare const bundleManifestPath: (dir: string) => string;
|
|
4
|
+
export declare const readValidatedBundleManifestFromDir: (dir: string, expectedHash?: string, expectedPlatform?: "ios" | "android") => Promise<BundleManifest | null>;
|
|
5
|
+
export declare const verifyBundleDir: (dir: string, expectedHash?: string, expectedPlatform?: "ios" | "android") => Promise<BundleManifest | null>;
|
|
@@ -0,0 +1,34 @@
|
|
|
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.verifyBundleDir = exports.readValidatedBundleManifestFromDir = exports.bundleManifestPath = exports.readJsonFile = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("../native/fs"));
|
|
8
|
+
const bundleManifest_1 = require("../manifest/bundleManifest");
|
|
9
|
+
const readJsonFile = async (path) => {
|
|
10
|
+
const raw = await fs_1.default.readFile(path, 'utf8');
|
|
11
|
+
return JSON.parse(raw);
|
|
12
|
+
};
|
|
13
|
+
exports.readJsonFile = readJsonFile;
|
|
14
|
+
const bundleManifestPath = (dir) => `${dir}/${bundleManifest_1.BUNDLE_MANIFEST}`;
|
|
15
|
+
exports.bundleManifestPath = bundleManifestPath;
|
|
16
|
+
const readValidatedBundleManifestFromDir = async (dir, expectedHash, expectedPlatform) => {
|
|
17
|
+
const manifestPath = (0, exports.bundleManifestPath)(dir);
|
|
18
|
+
if (!(await fs_1.default.exists(manifestPath))) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const manifest = await (0, exports.readJsonFile)(manifestPath);
|
|
22
|
+
(0, bundleManifest_1.assertValidBundleManifest)(manifest, expectedHash, expectedPlatform);
|
|
23
|
+
return manifest;
|
|
24
|
+
};
|
|
25
|
+
exports.readValidatedBundleManifestFromDir = readValidatedBundleManifestFromDir;
|
|
26
|
+
const verifyBundleDir = async (dir, expectedHash, expectedPlatform) => {
|
|
27
|
+
const manifest = await (0, exports.readValidatedBundleManifestFromDir)(dir, expectedHash, expectedPlatform);
|
|
28
|
+
if (!manifest) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
await fs_1.default.verifyBundleFiles(dir, (0, exports.bundleManifestPath)(dir));
|
|
32
|
+
return manifest;
|
|
33
|
+
};
|
|
34
|
+
exports.verifyBundleDir = verifyBundleDir;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InstallResult } from './bundleInstallShared';
|
|
2
2
|
type InstallFromZipParams = {
|
|
3
3
|
downloadUrl: string;
|
|
4
4
|
hash?: string;
|
|
5
5
|
platform?: 'ios' | 'android';
|
|
6
6
|
statusCb?: (status: string) => void;
|
|
7
7
|
};
|
|
8
|
-
export declare function installFromZip(params: InstallFromZipParams): Promise<
|
|
9
|
-
bundlePath: string;
|
|
10
|
-
metadataFromZip: Partial<BundleInfo>;
|
|
11
|
-
}>;
|
|
8
|
+
export declare function installFromZip(params: InstallFromZipParams): Promise<InstallResult>;
|
|
12
9
|
export {};
|