Unify supplimentary bundle path creation logic between Android and iOS

Differential Revision: D5941546

fbshipit-source-id: c9b8fab887f480faa373c26a1d5ba310e8acde78
This commit is contained in:
Alex Dvornikov
2017-10-04 15:03:52 -07:00
committed by Facebook Github Bot
parent adde2ed5e9
commit 9e01d72103
6 changed files with 25 additions and 25 deletions

View File

@@ -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

View File

@@ -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;
};

View File

@@ -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

View File

@@ -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.");
}