mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Unify supplimentary bundle path creation logic between Android and iOS
Differential Revision: D5941546 fbshipit-source-id: c9b8fab887f480faa373c26a1d5ba310e8acde78
This commit is contained in:
committed by
Facebook Github Bot
parent
adde2ed5e9
commit
9e01d72103
@@ -10,12 +10,12 @@
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
std::unique_ptr<JSModulesUnbundle> JSIndexedRAMBundleRegistry::bundleById(uint32_t index) const {
|
||||
return folly::make_unique<JSIndexedRAMBundle>(bundlePathById(index).c_str());
|
||||
}
|
||||
JSIndexedRAMBundleRegistry::JSIndexedRAMBundleRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle, const std::string& entryFile):
|
||||
RAMBundleRegistry(std::move(mainBundle)), m_baseDirectoryPath(jsBundlesDir(entryFile)) {}
|
||||
|
||||
std::string JSIndexedRAMBundleRegistry::bundlePathById(uint32_t index) const {
|
||||
return m_baseDirectoryPath + "/js-bundles/" + toString(index) + ".jsbundle";
|
||||
std::unique_ptr<JSModulesUnbundle> JSIndexedRAMBundleRegistry::bundleById(uint32_t index) const {
|
||||
std::string bundlePathById = m_baseDirectoryPath + toString(index) + ".jsbundle";
|
||||
return folly::make_unique<JSIndexedRAMBundle>(bundlePathById.c_str());
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
|
||||
@@ -13,16 +13,11 @@ namespace react {
|
||||
|
||||
class RN_EXPORT JSIndexedRAMBundleRegistry: public RAMBundleRegistry {
|
||||
public:
|
||||
JSIndexedRAMBundleRegistry(
|
||||
std::unique_ptr<JSModulesUnbundle> mainBundle,
|
||||
std::string baseDirectoryPath):
|
||||
RAMBundleRegistry(std::move(mainBundle)), m_baseDirectoryPath(baseDirectoryPath) {}
|
||||
JSIndexedRAMBundleRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle, const std::string& entryFile);
|
||||
|
||||
protected:
|
||||
virtual std::unique_ptr<JSModulesUnbundle> bundleById(uint32_t index) const override;
|
||||
private:
|
||||
std::string bundlePathById(uint32_t index) const;
|
||||
|
||||
std::string m_baseDirectoryPath;
|
||||
};
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include "RAMBundleRegistry.h"
|
||||
|
||||
#include <libgen.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
@@ -23,5 +25,20 @@ JSModulesUnbundle *RAMBundleRegistry::getBundle(uint32_t bundleId) const {
|
||||
return m_bundles.at(bundleId).get();
|
||||
}
|
||||
|
||||
std::string RAMBundleRegistry::jsBundlesDir(std::string entryFile) {
|
||||
char *pEntryFile = const_cast<char *>(entryFile.c_str());
|
||||
std::string dir = dirname(pEntryFile);
|
||||
std::string entryName = basename(pEntryFile);
|
||||
|
||||
std::size_t dotPosition = entryName.find(".");
|
||||
if (dotPosition != std::string::npos) {
|
||||
entryName.erase(dotPosition, std::string::npos);
|
||||
}
|
||||
|
||||
std::string path = "js-bundles/" + entryName + "/";
|
||||
// android's asset manager does not work with paths that start with a dot
|
||||
return dir == "." ? path : dir + "/" + path;
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
||||
@@ -28,6 +28,7 @@ public:
|
||||
JSModulesUnbundle::Module getModule(uint32_t bundleId, uint32_t moduleId);
|
||||
virtual ~RAMBundleRegistry() {};
|
||||
protected:
|
||||
std::string jsBundlesDir(std::string entryFile);
|
||||
virtual std::unique_ptr<JSModulesUnbundle> bundleById(uint32_t index) const {
|
||||
throw std::runtime_error("Please, override this method in a subclass to support multiple RAM bundles.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user