修改由于 code-push 的 release 命令发布热更新可能导致hash值不同bug #236
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
存在的问题
通过code-push的 release 命令直接上传包到服务器时, 生成的hash值可能会与生成iOS应用包时,包含进入的RN包的hash值不一致。
产生问题的具体步骤如下:
此时,我电脑的桌面上有一个bundle文件夹,里面包含main.jsbundle和asserts文件
原因分析
因为在iOS应用中,CodePush这个框架在计算打包进入应用的RN包的hash值时,在解析路径时,固定地使用了这样的相对路径来计算hash值:


CodePush/main.jsbundle:hash值
CodePush/assets/图片路径:图片hash值
最终要计算hash值的字符串形如:

而在code-push-server这边的计算方式与CodePush的计算方式是一样的,不过存在一点差异:

就是在解压包之后,就按着这个包的内容来进行进行hash运算,最终就导致了最终要计算的hash值字符串不一致了,如下图所示:
因为相对路径值不同,导致最终计算得到的hash值不同
Pull Request
我的修改方案是 core/utils/security.js文件中做如下修改:

确保相对路径的开头是CodePush