@gfean/react-native-bundle-drop 0.3.9 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BundleDrop.podspec +9 -2
- package/README.md +19 -0
- package/android/build.gradle +43 -4
- package/android/src/main/cpp/CMakeLists.txt +45 -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 +98 -36
- 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 +82 -75
- 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 -68
- 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 +197 -43
- package/lib/scripts/download-bundle.js +18 -7
- package/package.json +44 -6
- 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/assetExtensions.d.ts +0 -4
- package/lib/assetExtensions.js +0 -35
- package/lib/scripts/upload-bundle.d.ts +0 -9
- package/lib/scripts/upload-bundle.js +0 -320
|
@@ -7,11 +7,34 @@ exports.patchImageResolverWithManifest = patchImageResolverWithManifest;
|
|
|
7
7
|
exports.injectBundleDropImageResolver = injectBundleDropImageResolver;
|
|
8
8
|
exports.injectBundleDropImageResolverAsync = injectBundleDropImageResolverAsync;
|
|
9
9
|
const react_native_1 = require("react-native");
|
|
10
|
-
const assetExtensions_1 = require("./assetExtensions");
|
|
11
10
|
const fs_1 = __importDefault(require("./native/fs"));
|
|
12
11
|
let hasPatched = false;
|
|
13
12
|
const { BundleDrop } = react_native_1.NativeModules;
|
|
14
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']);
|
|
15
38
|
function getPackagerAsset(source) {
|
|
16
39
|
if (typeof source === 'number') {
|
|
17
40
|
try {
|
|
@@ -38,9 +61,58 @@ function getAndroidResourceIdentifier(asset) {
|
|
|
38
61
|
.toLowerCase()
|
|
39
62
|
.replace(/\//g, '_')
|
|
40
63
|
.replace(/([^a-z0-9_])/g, '')
|
|
41
|
-
.replace(/^
|
|
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}`];
|
|
97
|
+
});
|
|
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
|
+
];
|
|
42
114
|
}
|
|
43
|
-
function getAssetMetadataCandidates(asset) {
|
|
115
|
+
function getAssetMetadataCandidates(asset, preferredScale) {
|
|
44
116
|
if (!asset?.name || !asset.type)
|
|
45
117
|
return [];
|
|
46
118
|
const extension = `.${asset.type.toLowerCase()}`;
|
|
@@ -51,34 +123,14 @@ function getAssetMetadataCandidates(asset) {
|
|
|
51
123
|
return unique([
|
|
52
124
|
pathWithExtension ?? '',
|
|
53
125
|
pathWithoutAssetsPrefix ?? '',
|
|
54
|
-
resourceIdentifier
|
|
55
|
-
resourceIdentifier ? `res/raw/${resourceIdentifier}${extension}` : '',
|
|
126
|
+
...getAndroidResourcePathCandidates(asset, resourceIdentifier, extension, preferredScale),
|
|
56
127
|
]);
|
|
57
128
|
}
|
|
58
|
-
// Build lookup maps: exact keys and basename aliases so we can resolve filename-only URIs.
|
|
59
|
-
function buildManifestMaps(manifest) {
|
|
60
|
-
const byKey = manifest;
|
|
61
|
-
const byBase = {};
|
|
62
|
-
Object.entries(manifest).forEach(([key, value]) => {
|
|
63
|
-
const addBase = (input) => {
|
|
64
|
-
if (!input)
|
|
65
|
-
return;
|
|
66
|
-
const base = input.split('/').pop()?.replace(/\.[^.]+$/, '');
|
|
67
|
-
if (base && !byBase[base]) {
|
|
68
|
-
byBase[base] = value;
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
addBase(key);
|
|
72
|
-
addBase(value);
|
|
73
|
-
});
|
|
74
|
-
return { byKey, byBase };
|
|
75
|
-
}
|
|
76
129
|
function patchImageResolverWithManifest(manifest) {
|
|
77
130
|
if (!manifest || Object.keys(manifest).length === 0) {
|
|
78
131
|
console.warn('🧩 Cannot patch image resolver — empty manifest');
|
|
79
132
|
return;
|
|
80
133
|
}
|
|
81
|
-
const { byKey, byBase } = buildManifestMaps(manifest);
|
|
82
134
|
const originalResolve = react_native_1.Image.resolveAssetSource;
|
|
83
135
|
react_native_1.Image.resolveAssetSource = (source) => {
|
|
84
136
|
const resolved = originalResolve(source);
|
|
@@ -104,64 +156,19 @@ function patchImageResolverWithManifest(manifest) {
|
|
|
104
156
|
.replace(/^assets\//, '')
|
|
105
157
|
.replace(/^res\//, '');
|
|
106
158
|
}
|
|
107
|
-
const cleanedKey = (0, assetExtensions_1.removeFileExtension)(cleanedKeyWithExtension);
|
|
108
|
-
const assetExtension = packagerAsset?.type ? `.${packagerAsset.type.toLowerCase()}` : undefined;
|
|
109
|
-
const requestedExtension = (0, assetExtensions_1.getFileExtension)(cleanedKeyWithExtension) ?? assetExtension;
|
|
110
|
-
const allowBasenameFallback = !requestedExtension || (0, assetExtensions_1.isImageAssetExtension)(requestedExtension);
|
|
111
|
-
const isCompatiblePath = (path, key) => {
|
|
112
|
-
if (!path)
|
|
113
|
-
return false;
|
|
114
|
-
const resolvedExtension = (0, assetExtensions_1.getFileExtension)(path);
|
|
115
|
-
if (!requestedExtension)
|
|
116
|
-
return true;
|
|
117
|
-
if (resolvedExtension)
|
|
118
|
-
return requestedExtension === resolvedExtension;
|
|
119
|
-
return (0, assetExtensions_1.isImageAssetExtension)(requestedExtension) || (0, assetExtensions_1.getFileExtension)(key) === requestedExtension;
|
|
120
|
-
};
|
|
121
|
-
const baseWithExtension = cleanedKeyWithExtension.split('/').pop() || cleanedKeyWithExtension;
|
|
122
|
-
const baseWithoutExtension = cleanedKey.split('/').pop() || cleanedKey;
|
|
123
|
-
const withoutAndroidPrefix = cleanedKey.replace(/^android\//, '');
|
|
124
159
|
const withExtensionWithoutAndroidPrefix = cleanedKeyWithExtension.replace(/^android\//, '');
|
|
125
|
-
const
|
|
160
|
+
const pathCandidates = [
|
|
126
161
|
cleanedKeyWithExtension,
|
|
127
162
|
`res/${cleanedKeyWithExtension}`,
|
|
128
163
|
withExtensionWithoutAndroidPrefix,
|
|
129
164
|
];
|
|
130
|
-
const extensionlessPathCandidates = allowBasenameFallback ? [
|
|
131
|
-
cleanedKey,
|
|
132
|
-
`res/${cleanedKey}`,
|
|
133
|
-
withoutAndroidPrefix,
|
|
134
|
-
] : [];
|
|
135
|
-
const basenameCandidates = allowBasenameFallback ? [baseWithExtension, baseWithoutExtension] : [];
|
|
136
165
|
const candidates = unique([
|
|
137
|
-
...getAssetMetadataCandidates(packagerAsset),
|
|
138
|
-
...
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
]);
|
|
142
|
-
let finalPath = candidates.reduce((match, candidate) => {
|
|
143
|
-
if (match)
|
|
144
|
-
return match;
|
|
145
|
-
const path = byKey[candidate];
|
|
146
|
-
return isCompatiblePath(path, candidate) ? path : undefined;
|
|
147
|
-
}, undefined);
|
|
148
|
-
if (!finalPath && allowBasenameFallback) {
|
|
149
|
-
const manifestKey = Object.keys(byKey).find(key => {
|
|
150
|
-
const keyBase = key.split('/').pop() || key;
|
|
151
|
-
const isBaseMatch = keyBase === baseWithExtension || keyBase === baseWithoutExtension;
|
|
152
|
-
return isBaseMatch && isCompatiblePath(byKey[key], key);
|
|
153
|
-
});
|
|
154
|
-
if (manifestKey) {
|
|
155
|
-
finalPath = byKey[manifestKey];
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
if (!finalPath && allowBasenameFallback && baseWithoutExtension) {
|
|
159
|
-
const basePath = byBase[baseWithoutExtension];
|
|
160
|
-
finalPath = isCompatiblePath(basePath) ? basePath : undefined;
|
|
161
|
-
}
|
|
166
|
+
...getAssetMetadataCandidates(packagerAsset, resolved?.scale),
|
|
167
|
+
...pathCandidates,
|
|
168
|
+
]).filter(hasFileExtension);
|
|
169
|
+
const finalPath = candidates.reduce((match, candidate) => match ?? manifest[candidate], undefined);
|
|
162
170
|
if (finalPath) {
|
|
163
|
-
const
|
|
164
|
-
const fullPath = `file://${fs_1.default.DocumentDirectoryPath}/${finalPath}${hasExtension ? '' : (requestedExtension ?? '')}`;
|
|
171
|
+
const fullPath = `file://${fs_1.default.DocumentDirectoryPath}/${finalPath}`;
|
|
165
172
|
return { ...resolved, uri: fullPath };
|
|
166
173
|
}
|
|
167
174
|
return resolved;
|
|
@@ -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 {};
|
|
@@ -5,23 +5,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.installFromZip = installFromZip;
|
|
7
7
|
const fs_1 = __importDefault(require("../native/fs"));
|
|
8
|
-
const assetExtensions_1 = require("../assetExtensions");
|
|
9
8
|
const context_1 = require("../context");
|
|
10
|
-
const image_manifest_1 = require("../image-manifest");
|
|
11
|
-
const injectImageResolver_1 = require("../injectImageResolver");
|
|
12
9
|
const fsUtils_1 = require("../fs/fsUtils");
|
|
13
10
|
const errors_1 = require("../errors");
|
|
11
|
+
const bundleManifest_1 = require("../manifest/bundleManifest");
|
|
12
|
+
const bundleVerification_1 = require("./bundleVerification");
|
|
13
|
+
const bundleInstallShared_1 = require("./bundleInstallShared");
|
|
14
14
|
async function installFromZip(params) {
|
|
15
15
|
const { downloadUrl, hash, statusCb, platform = context_1.platform } = params;
|
|
16
16
|
if (!hash) {
|
|
17
17
|
throw new Error('Missing bundle hash');
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const bundlePath = `${bundleDir}/main.jsbundle`;
|
|
19
|
+
(0, bundleInstallShared_1.assertCanonicalBundleHash)(hash);
|
|
20
|
+
const tempDir = `${context_1.BUNDLE_DROP_ROOT}/bundles/_tmp_${hash}`;
|
|
22
21
|
const tempZipPath = `${context_1.BUNDLE_DROP_ROOT}/bundles/_tmp_${hash}.zip`;
|
|
23
22
|
let fileNames;
|
|
23
|
+
let verifiedHash = hash;
|
|
24
24
|
try {
|
|
25
|
+
try {
|
|
26
|
+
await fs_1.default.unlink(tempDir);
|
|
27
|
+
}
|
|
28
|
+
catch { /* best-effort cleanup */ }
|
|
29
|
+
await (0, fsUtils_1.ensureDir)(tempDir);
|
|
25
30
|
try {
|
|
26
31
|
await fs_1.default.downloadFile(downloadUrl, tempZipPath);
|
|
27
32
|
}
|
|
@@ -29,18 +34,28 @@ async function installFromZip(params) {
|
|
|
29
34
|
throw new errors_1.InstallPhaseError('download', e);
|
|
30
35
|
}
|
|
31
36
|
try {
|
|
32
|
-
fileNames = await fs_1.default.unzip(tempZipPath,
|
|
37
|
+
fileNames = await fs_1.default.unzip(tempZipPath, tempDir);
|
|
33
38
|
}
|
|
34
39
|
catch (e) {
|
|
35
40
|
throw new errors_1.InstallPhaseError('install', e);
|
|
36
41
|
}
|
|
37
|
-
if (!(await fs_1.default.exists(
|
|
42
|
+
if (!(await fs_1.default.exists(`${tempDir}/main.jsbundle`))) {
|
|
38
43
|
throw new errors_1.InstallPhaseError('install', new Error('main.jsbundle missing after extraction'));
|
|
39
44
|
}
|
|
45
|
+
try {
|
|
46
|
+
const manifest = await (0, bundleVerification_1.verifyBundleDir)(tempDir, hash, platform);
|
|
47
|
+
if (!manifest) {
|
|
48
|
+
throw new Error('Bundle manifest is missing');
|
|
49
|
+
}
|
|
50
|
+
verifiedHash = manifest.bundleHash;
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
throw new errors_1.InstallPhaseError('install', e);
|
|
54
|
+
}
|
|
40
55
|
}
|
|
41
56
|
catch (e) {
|
|
42
57
|
try {
|
|
43
|
-
await fs_1.default.unlink(
|
|
58
|
+
await fs_1.default.unlink(tempDir);
|
|
44
59
|
}
|
|
45
60
|
catch { /* best-effort cleanup */ }
|
|
46
61
|
throw e;
|
|
@@ -51,67 +66,17 @@ async function installFromZip(params) {
|
|
|
51
66
|
}
|
|
52
67
|
catch { /* best-effort cleanup */ }
|
|
53
68
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
const raw = await fs_1.default.readFile(`${bundleDir}/${metadataFile}`, 'utf8');
|
|
61
|
-
const parsed = JSON.parse(raw);
|
|
62
|
-
metadataFromZip.bundleVersion = parsed.bundleVersion ?? metadataFromZip.bundleVersion;
|
|
63
|
-
metadataFromZip.version = parsed.version ?? metadataFromZip.version;
|
|
64
|
-
metadataFromZip.hash = parsed.hash ?? metadataFromZip.hash;
|
|
65
|
-
metadataFromZip.runtimeVersion = parsed.runtimeVersion ?? metadataFromZip.runtimeVersion;
|
|
66
|
-
}
|
|
67
|
-
catch (e) {
|
|
68
|
-
console.warn('⚠️ Failed to parse bundle metadata from zip', e);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
// Build runtime manifest from extracted filenames (assets only)
|
|
72
|
-
const runtimeManifest = {};
|
|
73
|
-
for (const filename of fileNames) {
|
|
74
|
-
if (filename.includes('drawable') ||
|
|
75
|
-
filename.startsWith('assets/') ||
|
|
76
|
-
filename.startsWith('res/') ||
|
|
77
|
-
filename.startsWith('raw/')) {
|
|
78
|
-
const noExt = filename.replace(/\.[^.]+$/, '');
|
|
79
|
-
const base = noExt.split('/').pop();
|
|
80
|
-
const withAssetsPrefix = filename.startsWith('assets/') ? filename : `assets/${filename}`;
|
|
81
|
-
const mappedPath = context_1.isIOS
|
|
82
|
-
? `${hash}/${filename}`
|
|
83
|
-
: `bundle-drop/bundles/${hash}/${filename}`;
|
|
84
|
-
runtimeManifest[filename.replace(/^assets\//, '')] = mappedPath;
|
|
85
|
-
runtimeManifest[noExt.replace(/^assets\//, '')] = mappedPath;
|
|
86
|
-
runtimeManifest[withAssetsPrefix] = mappedPath;
|
|
87
|
-
runtimeManifest[withAssetsPrefix.replace(/\.[^.]+$/, '')] = mappedPath;
|
|
88
|
-
if ((0, assetExtensions_1.isImageAssetPath)(filename) && base && !runtimeManifest[base]) {
|
|
89
|
-
runtimeManifest[base] = mappedPath;
|
|
90
|
-
}
|
|
91
|
-
const baseWithExt = filename.split('/').pop();
|
|
92
|
-
if ((0, assetExtensions_1.isImageAssetPath)(filename) && baseWithExt && !runtimeManifest[baseWithExt]) {
|
|
93
|
-
runtimeManifest[baseWithExt] = mappedPath;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
69
|
+
try {
|
|
70
|
+
const fileNamesWithManifest = fileNames.includes(bundleManifest_1.BUNDLE_MANIFEST)
|
|
71
|
+
? fileNames
|
|
72
|
+
: [...fileNames, bundleManifest_1.BUNDLE_MANIFEST];
|
|
73
|
+
return await (0, bundleInstallShared_1.finalizeInstall)(tempDir, fileNamesWithManifest, verifiedHash, platform, statusCb);
|
|
96
74
|
}
|
|
97
|
-
|
|
98
|
-
if (platform === 'android' && fileNames.includes('image-manifest.json')) {
|
|
75
|
+
catch (e) {
|
|
99
76
|
try {
|
|
100
|
-
|
|
101
|
-
const parsed = JSON.parse(raw);
|
|
102
|
-
Object.assign(image_manifest_1.imageManifest, parsed);
|
|
103
|
-
statusCb?.(`🧩 Image manifest injected: ${Object.keys(parsed).length} items`);
|
|
77
|
+
await fs_1.default.unlink(tempDir);
|
|
104
78
|
}
|
|
105
|
-
catch
|
|
106
|
-
|
|
107
|
-
statusCb?.('❌ Failed to parse image manifest');
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
if (platform === 'android' && Object.keys(runtimeManifest).length > 0) {
|
|
111
|
-
Object.assign(image_manifest_1.imageManifest, runtimeManifest);
|
|
112
|
-
}
|
|
113
|
-
if (platform === 'android') {
|
|
114
|
-
(0, injectImageResolver_1.injectBundleDropImageResolver)(image_manifest_1.imageManifest);
|
|
79
|
+
catch { /* best-effort cleanup */ }
|
|
80
|
+
throw e;
|
|
115
81
|
}
|
|
116
|
-
return { bundlePath, metadataFromZip };
|
|
117
82
|
}
|
package/lib/loadConfig.js
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.loadConfig = loadConfig;
|
|
4
4
|
const react_native_1 = require("react-native");
|
|
5
|
+
function resolveDebugLocalPort(serverUrl) {
|
|
6
|
+
try {
|
|
7
|
+
return new URL(serverUrl).port || '4000';
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return '4000';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
5
13
|
function loadConfig() {
|
|
6
14
|
try {
|
|
7
15
|
// ✅ Resolved via Metro alias in the host app (extraNodeModules)
|
|
@@ -11,9 +19,12 @@ function loadConfig() {
|
|
|
11
19
|
throw new Error('bundle.drop.config.js missing serverUrl, org.slug or project.slug');
|
|
12
20
|
}
|
|
13
21
|
if (cfg.debugLocal === true) {
|
|
22
|
+
const port = resolveDebugLocalPort(cfg.serverUrl);
|
|
14
23
|
return {
|
|
15
24
|
...cfg,
|
|
16
|
-
serverUrl: react_native_1.Platform.OS === 'android'
|
|
25
|
+
serverUrl: react_native_1.Platform.OS === 'android'
|
|
26
|
+
? `http://10.0.2.2:${port}`
|
|
27
|
+
: `http://localhost:${port}`,
|
|
17
28
|
debugLocal: true,
|
|
18
29
|
};
|
|
19
30
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { OtaPatchSet } from '../api/types';
|
|
1
2
|
export type DownloadUpdateResult = {
|
|
2
3
|
status: 'staged';
|
|
3
4
|
bundlePath: string;
|
|
@@ -23,6 +24,14 @@ type DownloadOptions = {
|
|
|
23
24
|
bundleVersion?: number;
|
|
24
25
|
version?: string;
|
|
25
26
|
runtimeVersion?: string;
|
|
27
|
+
manifestUrl?: string;
|
|
28
|
+
mode?: 'full' | 'patch';
|
|
29
|
+
baseHash?: string;
|
|
30
|
+
patchSet?: OtaPatchSet;
|
|
31
|
+
fallback?: {
|
|
32
|
+
mode: 'full';
|
|
33
|
+
downloadUrl: string;
|
|
34
|
+
};
|
|
26
35
|
};
|
|
27
36
|
};
|
|
28
37
|
export declare const downloadUpdate: (options?: DownloadOptions, onStatusUpdate?: (status: string) => void) => Promise<DownloadUpdateResult>;
|