Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit dfc2222

Browse files
committed
Merge pull request #243 from Microsoft/ios_debug
Simplify JS bundle discovery strategy
2 parents 841ff90 + e27968e commit dfc2222

File tree

7 files changed

+20
-16
lines changed

7 files changed

+20
-16
lines changed

android/app/src/main/java/com/microsoft/codepush/react/CodePush.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ protected Void doInBackground(Object... params) {
365365
try {
366366
WritableMap mutableUpdatePackage = CodePushUtils.convertReadableMapToWritableMap(updatePackage);
367367
mutableUpdatePackage.putString(BINARY_MODIFIED_TIME_KEY, "" + getBinaryResourcesModifiedTime());
368-
codePushPackage.downloadPackage(applicationContext, mutableUpdatePackage, new DownloadProgressCallback() {
368+
codePushPackage.downloadPackage(applicationContext, mutableUpdatePackage, CodePush.this.assetsBundleFileName, new DownloadProgressCallback() {
369369
@Override
370370
public void call(DownloadProgress downloadProgress) {
371371
getReactApplicationContext()

android/app/src/main/java/com/microsoft/codepush/react/CodePushPackage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public WritableMap getPackage(String packageHash) {
151151
}
152152
}
153153

154-
public void downloadPackage(Context applicationContext, ReadableMap updatePackage,
154+
public void downloadPackage(Context applicationContext, ReadableMap updatePackage, String expectedBundleFileName,
155155
DownloadProgressCallback progressCallback) throws IOException {
156156
String newUpdateHash = CodePushUtils.tryGetString(updatePackage, PACKAGE_HASH_KEY);
157157
String newUpdateFolderPath = getPackageFolderPath(newUpdateHash);
@@ -243,7 +243,7 @@ public void downloadPackage(Context applicationContext, ReadableMap updatePackag
243243

244244
// For zip updates, we need to find the relative path to the jsBundle and save it in the
245245
// metadata so that we can find and run it easily the next time.
246-
String relativeBundlePath = CodePushUpdateUtils.findJSBundleInUpdateContents(newUpdateFolderPath);
246+
String relativeBundlePath = CodePushUpdateUtils.findJSBundleInUpdateContents(newUpdateFolderPath, expectedBundleFileName);
247247

248248
if (relativeBundlePath == null) {
249249
throw new CodePushInvalidUpdateException("Update is invalid - no files with extension .bundle, .js or .jsbundle were found in the update package.");

android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,20 @@ public static void copyNecessaryFilesFromCurrentPackage(String diffManifestFileP
7979
}
8080
}
8181

82-
public static String findJSBundleInUpdateContents(String folderPath) {
82+
public static String findJSBundleInUpdateContents(String folderPath, String expectedFileName) {
8383
File folder = new File(folderPath);
8484
File[] folderFiles = folder.listFiles();
8585
for (File file : folderFiles) {
8686
String fullFilePath = CodePushUtils.appendPathComponent(folderPath, file.getName());
8787
if (file.isDirectory()) {
88-
String mainBundlePathInSubFolder = findJSBundleInUpdateContents(fullFilePath);
88+
String mainBundlePathInSubFolder = findJSBundleInUpdateContents(fullFilePath, expectedFileName);
8989
if (mainBundlePathInSubFolder != null) {
9090
return CodePushUtils.appendPathComponent(file.getName(), mainBundlePathInSubFolder);
9191
}
9292
} else {
9393
String fileName = file.getName();
94-
int dotIndex = fileName.lastIndexOf(".");
95-
if (dotIndex >= 0) {
96-
String fileExtension = fileName.substring(dotIndex + 1);
97-
if (fileExtension.equals("bundle") || fileExtension.equals("js") || fileExtension.equals("jsbundle")) {
98-
return fileName;
99-
}
94+
if (fileName.equals(expectedFileName)) {
95+
return fileName;
10096
}
10197
}
10298
}

ios/CodePush/CodePush.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ failCallback:(void (^)(NSError *err))failCallback;
7070
@interface CodePushPackage : NSObject
7171

7272
+ (void)downloadPackage:(NSDictionary *)updatePackage
73+
expectedBundleFileName:(NSString *)expectedBundleFileName
7374
progressCallback:(void (^)(long long, long long))progressCallback
7475
doneCallback:(void (^)())doneCallback
7576
failCallback:(void (^)(NSError *err))failCallback;
@@ -113,6 +114,7 @@ failCallback:(void (^)(NSError *err))failCallback;
113114
error:(NSError **)error;
114115

115116
+ (NSString *)findMainBundleInFolder:(NSString *)folderPath
117+
expectedFileName:(NSString *)expectedFileName
116118
error:(NSError **)error;
117119

118120
+ (NSString *)assetsFolderName;

ios/CodePush/CodePush.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,9 @@ - (void)applicationWillResignActive
419419
forKey:BinaryBundleDateKey];
420420
}
421421

422-
[CodePushPackage downloadPackage:mutableUpdatePackage
422+
[CodePushPackage
423+
downloadPackage:mutableUpdatePackage
424+
expectedBundleFileName:[bundleResourceName stringByAppendingPathExtension:bundleResourceExtension]
423425
// The download is progressing forward
424426
progressCallback:^(long long expectedContentLength, long long receivedContentLength) {
425427
dispatch_async(_methodQueue, ^{

ios/CodePush/CodePushPackage.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ + (BOOL)isCodePushError:(NSError *)err
205205
}
206206

207207
+ (void)downloadPackage:(NSDictionary *)updatePackage
208+
expectedBundleFileName:(NSString *)expectedBundleFileName
208209
progressCallback:(void (^)(long long, long long))progressCallback
209210
doneCallback:(void (^)())doneCallback
210211
failCallback:(void (^)(NSError *err))failCallback
@@ -360,7 +361,9 @@ + (void)downloadPackage:(NSDictionary *)updatePackage
360361
}
361362

362363
NSString *relativeBundlePath = [CodePushUpdateUtils findMainBundleInFolder:newUpdateFolderPath
364+
expectedFileName:expectedBundleFileName
363365
error:&error];
366+
364367
if (error) {
365368
failCallback(error);
366369
return;

ios/CodePush/CodePushUpdateUtils.m

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ + (void)copyEntriesInFolder:(NSString *)sourceFolder
118118
}
119119

120120
+ (NSString *)findMainBundleInFolder:(NSString *)folderPath
121+
expectedFileName:(NSString *)expectedFileName
121122
error:(NSError **)error
122123
{
123124
NSArray* folderFiles = [[NSFileManager defaultManager]
@@ -132,17 +133,17 @@ + (NSString *)findMainBundleInFolder:(NSString *)folderPath
132133
BOOL isDir = NO;
133134
if ([[NSFileManager defaultManager] fileExistsAtPath:fullFilePath
134135
isDirectory:&isDir] && isDir) {
135-
NSString *mainBundlePathInFolder = [self findMainBundleInFolder:fullFilePath error:error];
136+
NSString *mainBundlePathInFolder = [self findMainBundleInFolder:fullFilePath
137+
expectedFileName:expectedFileName
138+
error:error];
136139
if (*error) {
137140
return nil;
138141
}
139142

140143
if (mainBundlePathInFolder) {
141144
return [fileName stringByAppendingPathComponent:mainBundlePathInFolder];
142145
}
143-
} else if ([[fileName pathExtension] isEqualToString:@"bundle"] ||
144-
[[fileName pathExtension] isEqualToString:@"jsbundle"] ||
145-
[[fileName pathExtension] isEqualToString:@"js"]) {
146+
} else if ([fileName isEqualToString:expectedFileName]) {
146147
return fileName;
147148
}
148149
}

0 commit comments

Comments
 (0)