Skip to content

Commit 2b02ce9

Browse files
sergey-akhalkovRichard Hua
authored and
Richard Hua
committed
Flow type checking fix: use "CodePushHash" file name instead of "CodePushHash.json" (#763)
`CodePushHash.json` file name breaks flow type checking. To fix the issue we need to delete `CodePushHash.json` file and use `CodePushHash` file name instead to store the hash value. Relates to #577
1 parent 8021005 commit 2b02ce9

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ public class CodePushConstants {
44
public static final String ASSETS_BUNDLE_PREFIX = "assets://";
55
public static final String BINARY_MODIFIED_TIME_KEY = "binaryModifiedTime";
66
public static final String CODE_PUSH_FOLDER_PREFIX = "CodePush";
7-
public static final String CODE_PUSH_HASH_FILE_NAME = "CodePushHash.json";
7+
public static final String CODE_PUSH_HASH_FILE_NAME = "CodePushHash";
8+
public static final String CODE_PUSH_OLD_HASH_FILE_NAME = "CodePushHash.json";
89
public static final String CODE_PUSH_PREFERENCES = "CodePush";
910
public static final String CURRENT_PACKAGE_KEY = "currentPackage";
1011
public static final String DEFAULT_JS_BUNDLE_NAME = "index.android.bundle";

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,15 @@ public static String getHashForBinaryContents(Context context, boolean isDebugMo
109109
try {
110110
return CodePushUtils.getStringFromInputStream(context.getAssets().open(CodePushConstants.CODE_PUSH_HASH_FILE_NAME));
111111
} catch (IOException e) {
112-
if (!isDebugMode) {
113-
// Only print this message in "Release" mode. In "Debug", we may not have the
114-
// hash if the build skips bundling the files.
115-
CodePushUtils.log("Unable to get the hash of the binary's bundled resources - \"codepush.gradle\" may have not been added to the build definition.");
112+
try {
113+
return CodePushUtils.getStringFromInputStream(context.getAssets().open(CodePushConstants.CODE_PUSH_OLD_HASH_FILE_NAME));
114+
} catch (IOException ex) {
115+
if (!isDebugMode) {
116+
// Only print this message in "Release" mode. In "Debug", we may not have the
117+
// hash if the build skips bundling the files.
118+
CodePushUtils.log("Unable to get the hash of the binary's bundled resources - \"codepush.gradle\" may have not been added to the build definition.");
119+
}
116120
}
117-
118121
return null;
119122
}
120123
}

scripts/generateBundledResourcesHash.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ var path = require("path");
1818
var getFilesInFolder = require("./getFilesInFolder");
1919

2020
var CODE_PUSH_FOLDER_PREFIX = "CodePush";
21-
var CODE_PUSH_HASH_FILE_NAME = "CodePushHash.json";
21+
var CODE_PUSH_HASH_FILE_NAME = "CodePushHash";
22+
var CODE_PUSH_HASH_OLD_FILE_NAME = "CodePushHash.json";
2223
var HASH_ALGORITHM = "sha256";
2324
var TEMP_FILE_PATH = path.join(require("os").tmpdir(), "CodePushResourcesMap.json");
2425

@@ -72,6 +73,15 @@ function addJsBundleAndMetaToManifest() {
7273

7374
var savedResourcesManifestPath = assetsDir + "/" + CODE_PUSH_HASH_FILE_NAME;
7475
fs.writeFileSync(savedResourcesManifestPath, finalHash);
76+
77+
// "CodePushHash.json" file name breaks flow type checking.
78+
// To fix the issue we need to delete "CodePushHash.json" file and
79+
// use "CodePushHash" file name instead to store the hash value.
80+
// Relates to https://github.com/Microsoft/react-native-code-push/issues/577
81+
var oldSavedResourcesManifestPath = assetsDir + "/" + CODE_PUSH_HASH_OLD_FILE_NAME;
82+
if (fs.existsSync(oldSavedResourcesManifestPath)) {
83+
fs.unlinkSync(oldSavedResourcesManifestPath);
84+
}
7585
});
7686
});
7787
}

0 commit comments

Comments
 (0)