@gfean/react-native-bundle-drop 0.3.7 → 0.3.9

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.
@@ -5,6 +5,7 @@ NS_ASSUME_NONNULL_BEGIN
5
5
  @interface BundleDropLocator : NSObject
6
6
 
7
7
  + (nullable NSURL *)bundleURL;
8
+ + (unsigned long long)fileSizeAtURL:(NSURL *)url NS_SWIFT_NAME(fileSize(at:));
8
9
 
9
10
  @end
10
11
 
@@ -0,0 +1,21 @@
1
+ #import "BundleDropLocator.h"
2
+
3
+ #if __has_include(<BundleDrop/BundleDrop-Swift.h>)
4
+ #import <BundleDrop/BundleDrop-Swift.h>
5
+ #else
6
+ #import "BundleDrop-Swift.h"
7
+ #endif
8
+
9
+ @implementation BundleDropLocator
10
+
11
+ + (nullable NSURL *)bundleURL
12
+ {
13
+ return [BundleDropLocatorCore bundleURL];
14
+ }
15
+
16
+ + (unsigned long long)fileSizeAtURL:(NSURL *)url
17
+ {
18
+ return [BundleDropLocatorCore fileSizeAt:url];
19
+ }
20
+
21
+ @end
@@ -1,6 +1,6 @@
1
1
  import Foundation
2
2
 
3
- @objc(BundleDropLocator) public final class BundleDropLocator: NSObject {
3
+ @objc(BundleDropLocatorCore) public final class BundleDropLocatorCore: NSObject {
4
4
 
5
5
  static let binaryVersionKey = "BundleDropBinaryVersion"
6
6
 
@@ -14,7 +14,7 @@ final class BundleDropModule: NSObject {
14
14
  _ resolve: @escaping RCTPromiseResolveBlock,
15
15
  rejecter reject: @escaping RCTPromiseRejectBlock
16
16
  ) {
17
- if let url = BundleDropLocator.bundleURL() {
17
+ if let url = BundleDropLocatorCore.bundleURL() {
18
18
  print("📦 Found downloaded bundle at: \(url.path)")
19
19
  resolve(url.path)
20
20
  return
@@ -29,7 +29,7 @@ final class BundleDropModule: NSObject {
29
29
  resolve: @escaping RCTPromiseResolveBlock,
30
30
  reject: @escaping RCTPromiseRejectBlock
31
31
  ) {
32
- UserDefaults.standard.set(enabled, forKey: BundleDropLocator.otaEnabledKey)
32
+ UserDefaults.standard.set(enabled, forKey: BundleDropLocatorCore.otaEnabledKey)
33
33
  resolve(nil)
34
34
  }
35
35
 
@@ -41,12 +41,12 @@ final class BundleDropModule: NSObject {
41
41
  return
42
42
  }
43
43
 
44
- guard let url = BundleDropLocator.bundleURL() else {
44
+ guard let url = BundleDropLocatorCore.bundleURL() else {
45
45
  print("⚠️ No downloaded bundle found; skipping restart.")
46
46
  return
47
47
  }
48
48
 
49
- let size = BundleDropLocator.fileSize(at: url)
49
+ let size = BundleDropLocatorCore.fileSize(at: url)
50
50
  if size < 1024 {
51
51
  print("⚠️ Bundle exists but looks invalid (size=\(size)). Skipping restart.")
52
52
  return
@@ -0,0 +1,4 @@
1
+ export declare const getFileExtension: (value?: string) => string;
2
+ export declare const removeFileExtension: (value: string) => string;
3
+ export declare const isImageAssetExtension: (extension?: string) => boolean;
4
+ export declare const isImageAssetPath: (path: string) => boolean;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isImageAssetPath = exports.isImageAssetExtension = exports.removeFileExtension = exports.getFileExtension = void 0;
4
+ const IMAGE_ASSET_EXTENSIONS = new Set([
5
+ '.apng',
6
+ '.avif',
7
+ '.bmp',
8
+ '.gif',
9
+ '.heic',
10
+ '.heif',
11
+ '.ico',
12
+ '.jpeg',
13
+ '.jpg',
14
+ '.png',
15
+ '.psd',
16
+ '.svg',
17
+ '.tif',
18
+ '.tiff',
19
+ '.webp',
20
+ '.xml',
21
+ ]);
22
+ const getFileExtension = (value) => {
23
+ const fileName = value?.split(/[?#]/)[0]?.split('/').pop();
24
+ return fileName?.match(/(\.[a-zA-Z0-9]+)$/)?.[1]?.toLowerCase();
25
+ };
26
+ exports.getFileExtension = getFileExtension;
27
+ const removeFileExtension = (value) => {
28
+ const extension = (0, exports.getFileExtension)(value);
29
+ return extension ? value.slice(0, -extension.length) : value;
30
+ };
31
+ exports.removeFileExtension = removeFileExtension;
32
+ const isImageAssetExtension = (extension) => (Boolean(extension && IMAGE_ASSET_EXTENSIONS.has(extension)));
33
+ exports.isImageAssetExtension = isImageAssetExtension;
34
+ const isImageAssetPath = (path) => ((0, exports.isImageAssetExtension)((0, exports.getFileExtension)(path)));
35
+ exports.isImageAssetPath = isImageAssetPath;
@@ -7,9 +7,54 @@ 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");
10
11
  const fs_1 = __importDefault(require("./native/fs"));
11
12
  let hasPatched = false;
12
13
  const { BundleDrop } = react_native_1.NativeModules;
14
+ const unique = (values) => Array.from(new Set(values.filter(Boolean)));
15
+ function getPackagerAsset(source) {
16
+ if (typeof source === 'number') {
17
+ try {
18
+ const registry = require('react-native/Libraries/Image/AssetRegistry');
19
+ return registry.getAssetByID?.(source);
20
+ }
21
+ catch {
22
+ return undefined;
23
+ }
24
+ }
25
+ return source?.__packager_asset ? source : undefined;
26
+ }
27
+ function getAssetBasePath(asset) {
28
+ const basePath = asset.httpServerLocation;
29
+ if (!basePath)
30
+ return undefined;
31
+ return basePath.replace(/^\//, '');
32
+ }
33
+ function getAndroidResourceIdentifier(asset) {
34
+ const basePath = getAssetBasePath(asset);
35
+ if (!basePath || !asset.name)
36
+ return undefined;
37
+ return `${basePath}/${asset.name}`
38
+ .toLowerCase()
39
+ .replace(/\//g, '_')
40
+ .replace(/([^a-z0-9_])/g, '')
41
+ .replace(/^assets_/, '');
42
+ }
43
+ function getAssetMetadataCandidates(asset) {
44
+ if (!asset?.name || !asset.type)
45
+ return [];
46
+ const extension = `.${asset.type.toLowerCase()}`;
47
+ const basePath = getAssetBasePath(asset);
48
+ const resourceIdentifier = getAndroidResourceIdentifier(asset);
49
+ const pathWithExtension = basePath ? `${basePath}/${asset.name}${extension}` : undefined;
50
+ const pathWithoutAssetsPrefix = pathWithExtension?.replace(/^assets\//, '');
51
+ return unique([
52
+ pathWithExtension ?? '',
53
+ pathWithoutAssetsPrefix ?? '',
54
+ resourceIdentifier ? `raw/${resourceIdentifier}${extension}` : '',
55
+ resourceIdentifier ? `res/raw/${resourceIdentifier}${extension}` : '',
56
+ ]);
57
+ }
13
58
  // Build lookup maps: exact keys and basename aliases so we can resolve filename-only URIs.
14
59
  function buildManifestMaps(manifest) {
15
60
  const byKey = manifest;
@@ -37,6 +82,7 @@ function patchImageResolverWithManifest(manifest) {
37
82
  const originalResolve = react_native_1.Image.resolveAssetSource;
38
83
  react_native_1.Image.resolveAssetSource = (source) => {
39
84
  const resolved = originalResolve(source);
85
+ const packagerAsset = getPackagerAsset(source);
40
86
  if (typeof source !== 'number' && !source?.__packager_asset) {
41
87
  return resolved;
42
88
  }
@@ -46,42 +92,76 @@ function patchImageResolverWithManifest(manifest) {
46
92
  if (/^(https?|data|content):/.test(uri)) {
47
93
  return resolved;
48
94
  }
49
- let cleanedKey = uri;
95
+ let cleanedKeyWithExtension = uri;
50
96
  if (uri.startsWith('file://')) {
51
97
  const parts = uri.split('/files/')[1];
52
- cleanedKey = parts?.replace(/\.[^.]+$/, '') ?? uri;
98
+ cleanedKeyWithExtension = parts ?? uri;
53
99
  }
54
100
  else {
55
- cleanedKey = uri
101
+ cleanedKeyWithExtension = uri
56
102
  .replace(/^asset:\/\//, '')
57
103
  .replace(/^asset:\//, '')
58
104
  .replace(/^assets\//, '')
59
- .replace(/^res\//, '')
60
- .replace(/\.[^.]+$/, '');
105
+ .replace(/^res\//, '');
61
106
  }
62
- const candidates = [
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
+ const withExtensionWithoutAndroidPrefix = cleanedKeyWithExtension.replace(/^android\//, '');
125
+ const extensionSpecificPathCandidates = [
126
+ cleanedKeyWithExtension,
127
+ `res/${cleanedKeyWithExtension}`,
128
+ withExtensionWithoutAndroidPrefix,
129
+ ];
130
+ const extensionlessPathCandidates = allowBasenameFallback ? [
63
131
  cleanedKey,
64
132
  `res/${cleanedKey}`,
65
- cleanedKey.replace(/^android\//, ''),
66
- cleanedKey.split('/').pop() || cleanedKey,
67
- ];
68
- let manifestKey = candidates.find(k => byKey[k]);
69
- if (!manifestKey) {
70
- const base = cleanedKey.split('/').pop();
71
- if (base) {
72
- manifestKey = Object.keys(byKey).find(k => (k.split('/').pop() || k) === base);
133
+ withoutAndroidPrefix,
134
+ ] : [];
135
+ const basenameCandidates = allowBasenameFallback ? [baseWithExtension, baseWithoutExtension] : [];
136
+ const candidates = unique([
137
+ ...getAssetMetadataCandidates(packagerAsset),
138
+ ...extensionSpecificPathCandidates,
139
+ ...extensionlessPathCandidates,
140
+ ...basenameCandidates,
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];
73
156
  }
74
157
  }
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
- }
158
+ if (!finalPath && allowBasenameFallback && baseWithoutExtension) {
159
+ const basePath = byBase[baseWithoutExtension];
160
+ finalPath = isCompatiblePath(basePath) ? basePath : undefined;
81
161
  }
82
162
  if (finalPath) {
83
163
  const hasExtension = /\.[a-zA-Z0-9]+$/.test(finalPath);
84
- const fullPath = `file://${fs_1.default.DocumentDirectoryPath}/${finalPath}${hasExtension ? '' : (uri.match(/\.[^.]+$/)?.[0] ?? '')}`;
164
+ const fullPath = `file://${fs_1.default.DocumentDirectoryPath}/${finalPath}${hasExtension ? '' : (requestedExtension ?? '')}`;
85
165
  return { ...resolved, uri: fullPath };
86
166
  }
87
167
  return resolved;
@@ -93,8 +173,11 @@ function injectBundleDropImageResolver(manifestOverride) {
93
173
  if (hasPatched && !manifestOverride)
94
174
  return;
95
175
  try {
96
- let manifest = manifestOverride;
97
- if (!manifest) {
176
+ let manifest;
177
+ if (manifestOverride) {
178
+ manifest = manifestOverride;
179
+ }
180
+ else {
98
181
  const raw = BundleDrop.getImageManifestSync?.();
99
182
  if (!raw)
100
183
  return;
@@ -5,6 +5,7 @@ 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");
8
9
  const context_1 = require("../context");
9
10
  const image_manifest_1 = require("../image-manifest");
10
11
  const injectImageResolver_1 = require("../injectImageResolver");
@@ -70,20 +71,25 @@ async function installFromZip(params) {
70
71
  // Build runtime manifest from extracted filenames (assets only)
71
72
  const runtimeManifest = {};
72
73
  for (const filename of fileNames) {
73
- if (filename.includes('drawable') || filename.startsWith('assets/') || filename.startsWith('res/')) {
74
+ if (filename.includes('drawable') ||
75
+ filename.startsWith('assets/') ||
76
+ filename.startsWith('res/') ||
77
+ filename.startsWith('raw/')) {
74
78
  const noExt = filename.replace(/\.[^.]+$/, '');
75
79
  const base = noExt.split('/').pop();
76
80
  const withAssetsPrefix = filename.startsWith('assets/') ? filename : `assets/${filename}`;
77
81
  const mappedPath = context_1.isIOS
78
82
  ? `${hash}/${filename}`
79
83
  : `bundle-drop/bundles/${hash}/${filename}`;
84
+ runtimeManifest[filename.replace(/^assets\//, '')] = mappedPath;
80
85
  runtimeManifest[noExt.replace(/^assets\//, '')] = mappedPath;
86
+ runtimeManifest[withAssetsPrefix] = mappedPath;
81
87
  runtimeManifest[withAssetsPrefix.replace(/\.[^.]+$/, '')] = mappedPath;
82
- if (base && !runtimeManifest[base]) {
88
+ if ((0, assetExtensions_1.isImageAssetPath)(filename) && base && !runtimeManifest[base]) {
83
89
  runtimeManifest[base] = mappedPath;
84
90
  }
85
91
  const baseWithExt = filename.split('/').pop();
86
- if (baseWithExt && !runtimeManifest[baseWithExt]) {
92
+ if ((0, assetExtensions_1.isImageAssetPath)(filename) && baseWithExt && !runtimeManifest[baseWithExt]) {
87
93
  runtimeManifest[baseWithExt] = mappedPath;
88
94
  }
89
95
  }
@@ -44,6 +44,7 @@ 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 assetExtensions_1 = require("../assetExtensions");
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, '..', '..');
@@ -179,11 +180,15 @@ function runBundleScript(options) {
179
180
  const manifestKeyNoPrefix = manifestKey.replace(/^assets\//, '');
180
181
  const baseNameKey = manifestKey.split('/').pop() || manifestKey;
181
182
  const baseWithExt = normalizedPath.split('/').pop() || normalizedPath;
183
+ imageManifest[normalizedPath] = normalizedPath;
182
184
  imageManifest[manifestKey] = normalizedPath;
183
185
  imageManifest[manifestKeyNoPrefix] = normalizedPath;
186
+ imageManifest[withAssetsPrefix] = normalizedPath;
184
187
  imageManifest[withAssetsPrefix.replace(/\.[^.]+$/, '')] = normalizedPath;
185
- imageManifest[baseNameKey] = normalizedPath;
186
- imageManifest[baseWithExt] = normalizedPath;
188
+ if ((0, assetExtensions_1.isImageAssetPath)(normalizedPath)) {
189
+ imageManifest[baseNameKey] = normalizedPath;
190
+ imageManifest[baseWithExt] = normalizedPath;
191
+ }
187
192
  }
188
193
  }
189
194
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gfean/react-native-bundle-drop",
3
- "version": "0.3.7",
4
- "nativeVersion": "0.3.7",
3
+ "version": "0.3.9",
4
+ "nativeVersion": "0.3.8",
5
5
  "description": "Over-the-air (OTA) updates for React Native — ship fixes instantly, no App Store or Play Store delays",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -54,6 +54,7 @@
54
54
  "version": "0.49.6"
55
55
  },
56
56
  "devDependencies": {
57
+ "@types/adm-zip": "^0.5.8",
57
58
  "@types/jest": "^29.5.14",
58
59
  "@types/node": "^24.10.1",
59
60
  "@types/react": "^18.2.66",