@hot-updater/react-native 0.36.5 → 0.36.7

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.
@@ -791,7 +791,7 @@ class BundleFileStorageService: BundleStorageService {
791
791
  }
792
792
 
793
793
  private func createInitialMetadata() -> BundleMetadata {
794
- let currentBundleId = getCachedBundleURL()?.deletingLastPathComponent().lastPathComponent
794
+ let currentBundleId = getCachedBundleId()
795
795
  return BundleMetadata(
796
796
  isolationKey: isolationKey,
797
797
  stableBundleId: nil,
@@ -808,7 +808,7 @@ class BundleFileStorageService: BundleStorageService {
808
808
  }
809
809
 
810
810
  private func getActiveBundleId() -> String? {
811
- if let cachedBundleId = getCachedBundleURL()?.deletingLastPathComponent().lastPathComponent {
811
+ if let cachedBundleId = getCachedBundleId() {
812
812
  return cachedBundleId
813
813
  }
814
814
 
@@ -870,12 +870,11 @@ class BundleFileStorageService: BundleStorageService {
870
870
  }
871
871
 
872
872
  func canUseManifestDrivenInstall() -> Bool {
873
- guard let currentBundleURL = getCachedBundleURL(),
873
+ guard let currentBundleId = getCachedBundleId(),
874
874
  case .success(let storeDir) = bundleStoreDir() else {
875
875
  return false
876
876
  }
877
877
 
878
- let currentBundleId = currentBundleURL.deletingLastPathComponent().lastPathComponent
879
878
  let currentBundleDir = (storeDir as NSString).appendingPathComponent(currentBundleId)
880
879
  guard fileSystem.fileExists(atPath: currentBundleDir),
881
880
  let snapshot = getActiveBundleMetadataSnapshot(),
@@ -1457,6 +1456,58 @@ class BundleFileStorageService: BundleStorageService {
1457
1456
  return .failure(error)
1458
1457
  }
1459
1458
  }
1459
+
1460
+ private func bundleId(for bundleURL: URL, storeDir: String) -> String? {
1461
+ let storeURL = URL(fileURLWithPath: storeDir, isDirectory: true).standardizedFileURL
1462
+ let bundleURL = bundleURL.standardizedFileURL
1463
+ let storePrefix = storeURL.path + "/"
1464
+
1465
+ guard bundleURL.path.hasPrefix(storePrefix) else {
1466
+ return nil
1467
+ }
1468
+
1469
+ return bundleURL.path
1470
+ .dropFirst(storePrefix.count)
1471
+ .split(separator: "/")
1472
+ .first
1473
+ .map(String.init)
1474
+ }
1475
+
1476
+ private func getCachedBundleId() -> String? {
1477
+ guard let bundleURL = getCachedBundleURL(),
1478
+ case .success(let storeDir) = bundleStoreDir() else {
1479
+ return nil
1480
+ }
1481
+
1482
+ return bundleId(for: bundleURL, storeDir: storeDir)
1483
+ }
1484
+
1485
+ func resolveBundlePathAfterMove(
1486
+ _ bundlePath: String,
1487
+ from sourceDirectory: String,
1488
+ to destinationDirectory: String
1489
+ ) throws -> String {
1490
+ let sourceURL = URL(
1491
+ fileURLWithPath: sourceDirectory,
1492
+ isDirectory: true
1493
+ ).standardizedFileURL
1494
+ let bundleURL = URL(fileURLWithPath: bundlePath).standardizedFileURL
1495
+ let sourcePrefix = sourceURL.path + "/"
1496
+
1497
+ guard bundleURL.path.hasPrefix(sourcePrefix) else {
1498
+ throw BundleStorageError.invalidBundle
1499
+ }
1500
+
1501
+ let relativePath = String(bundleURL.path.dropFirst(sourcePrefix.count))
1502
+ guard ArchiveExtractionUtilities.normalizedRelativePath(from: relativePath) == relativePath else {
1503
+ throw BundleStorageError.invalidBundle
1504
+ }
1505
+
1506
+ return try ArchiveExtractionUtilities.extractionURL(
1507
+ for: relativePath,
1508
+ destinationRoot: destinationDirectory
1509
+ ).path
1510
+ }
1460
1511
 
1461
1512
  /**
1462
1513
  * Gets the URL to the cached bundle file if it exists.
@@ -1478,13 +1529,7 @@ class BundleFileStorageService: BundleStorageService {
1478
1529
  }
1479
1530
 
1480
1531
  let storeURL = URL(fileURLWithPath: storeDir, isDirectory: true).standardizedFileURL
1481
- let storePrefix = storeURL.path + "/"
1482
- guard bundleURL.path.hasPrefix(storePrefix),
1483
- let bundleId = bundleURL.path
1484
- .dropFirst(storePrefix.count)
1485
- .split(separator: "/")
1486
- .first
1487
- .map(String.init) else {
1532
+ guard let bundleId = bundleId(for: bundleURL, storeDir: storeDir) else {
1488
1533
  return nil
1489
1534
  }
1490
1535
 
@@ -1515,7 +1560,7 @@ class BundleFileStorageService: BundleStorageService {
1515
1560
  guard let metadata = loadMetadataOrNull() else {
1516
1561
  return LaunchSelection(
1517
1562
  bundleURL: getCachedBundleURL() ?? getFallbackBundleURL(bundle: bundle),
1518
- launchedBundleId: getCachedBundleURL()?.deletingLastPathComponent().lastPathComponent,
1563
+ launchedBundleId: getCachedBundleId(),
1519
1564
  shouldRollbackOnCrash: false
1520
1565
  )
1521
1566
  }
@@ -1587,7 +1632,7 @@ class BundleFileStorageService: BundleStorageService {
1587
1632
  }
1588
1633
 
1589
1634
  // Get the current bundle ID from the cached bundle URL (exclude fallback bundles)
1590
- let currentBundleId = self.getCachedBundleURL()?.deletingLastPathComponent().lastPathComponent
1635
+ let currentBundleId = self.getCachedBundleId()
1591
1636
 
1592
1637
  guard let validFileUrl = fileUrl else {
1593
1638
  NSLog("[BundleStorage] fileUrl is nil, resetting bundle URL.")
@@ -1748,7 +1793,7 @@ class BundleFileStorageService: BundleStorageService {
1748
1793
  return
1749
1794
  }
1750
1795
 
1751
- let currentBundleId = self.getCachedBundleURL()?.deletingLastPathComponent().lastPathComponent
1796
+ let currentBundleId = self.getCachedBundleId()
1752
1797
  let currentBundleDir = currentBundleId.map {
1753
1798
  (storeDir as NSString).appendingPathComponent($0)
1754
1799
  }
@@ -2063,8 +2108,10 @@ class BundleFileStorageService: BundleStorageService {
2063
2108
  throw BundleStorageError.moveOperationFailed(error)
2064
2109
  }
2065
2110
 
2066
- let finalBundlePath = (realDir as NSString).appendingPathComponent(
2067
- (bundlePathInTmp as NSString).lastPathComponent
2111
+ let finalBundlePath = try resolveBundlePathAfterMove(
2112
+ bundlePathInTmp,
2113
+ from: tmpDir,
2114
+ to: realDir
2068
2115
  )
2069
2116
  switch self.setBundleURL(localPath: finalBundlePath) {
2070
2117
  case .success:
@@ -2277,7 +2324,7 @@ class BundleFileStorageService: BundleStorageService {
2277
2324
  progressHandler: @escaping (UpdateProgressPayload) -> Void,
2278
2325
  completion: @escaping (Result<Bool, Error>) -> Void
2279
2326
  ) {
2280
- let currentBundleId = self.getCachedBundleURL()?.deletingLastPathComponent().lastPathComponent
2327
+ let currentBundleId = self.getCachedBundleId()
2281
2328
  NSLog("[BundleStorage] Processing downloaded file atPath: \(location.path)")
2282
2329
 
2283
2330
  // 1) Ensure the bundle file exists
@@ -2393,7 +2440,11 @@ class BundleFileStorageService: BundleStorageService {
2393
2440
  }
2394
2441
 
2395
2442
  // 11) Construct final bundlePath for preferences
2396
- let finalBundlePath = (realDir as NSString).appendingPathComponent((bundlePathInTmp as NSString).lastPathComponent)
2443
+ let finalBundlePath = try resolveBundlePathAfterMove(
2444
+ bundlePathInTmp,
2445
+ from: tmpDir,
2446
+ to: realDir
2447
+ )
2397
2448
 
2398
2449
  // 12) Set the bundle URL in preferences (for backwards compatibility)
2399
2450
  let setResult = self.setBundleURL(localPath: finalBundlePath)
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.HOT_UPDATER_SDK_VERSION = void 0;
7
- const HOT_UPDATER_SDK_VERSION = exports.HOT_UPDATER_SDK_VERSION = "0.36.5";
7
+ const HOT_UPDATER_SDK_VERSION = exports.HOT_UPDATER_SDK_VERSION = "0.36.7";
8
8
  //# sourceMappingURL=sdkVersion.js.map
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
 
3
- export const HOT_UPDATER_SDK_VERSION = "0.36.5";
3
+ export const HOT_UPDATER_SDK_VERSION = "0.36.7";
4
4
  //# sourceMappingURL=sdkVersion.js.map
@@ -1,2 +1,2 @@
1
- export declare const HOT_UPDATER_SDK_VERSION = "0.36.5";
1
+ export declare const HOT_UPDATER_SDK_VERSION = "0.36.7";
2
2
  //# sourceMappingURL=sdkVersion.d.ts.map
@@ -1,2 +1,2 @@
1
- export declare const HOT_UPDATER_SDK_VERSION = "0.36.5";
1
+ export declare const HOT_UPDATER_SDK_VERSION = "0.36.7";
2
2
  //# sourceMappingURL=sdkVersion.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/react-native",
3
- "version": "0.36.5",
3
+ "version": "0.36.7",
4
4
  "description": "React Native OTA solution for self-hosted",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./lib/commonjs/index.js",
@@ -131,14 +131,14 @@
131
131
  "react-native-builder-bob": "0.41.0",
132
132
  "@typescript/native": "npm:typescript@^7.0.2",
133
133
  "typescript": "npm:@typescript/typescript6@^6.0.2",
134
- "hot-updater": "0.36.5"
134
+ "hot-updater": "0.36.7"
135
135
  },
136
136
  "dependencies": {
137
137
  "use-sync-external-store": "1.5.0",
138
- "@hot-updater/cli-tools": "0.36.5",
139
- "@hot-updater/js": "0.36.5",
140
- "@hot-updater/core": "0.36.5",
141
- "@hot-updater/plugin-core": "0.36.5"
138
+ "@hot-updater/core": "0.36.7",
139
+ "@hot-updater/js": "0.36.7",
140
+ "@hot-updater/plugin-core": "0.36.7",
141
+ "@hot-updater/cli-tools": "0.36.7"
142
142
  },
143
143
  "scripts": {
144
144
  "build": "node ./scripts/sync-sdk-version.mjs run -- bob build && tsc -p plugin/tsconfig.build.json",
package/src/sdkVersion.ts CHANGED
@@ -1 +1 @@
1
- export const HOT_UPDATER_SDK_VERSION = "0.36.5";
1
+ export const HOT_UPDATER_SDK_VERSION = "0.36.7";