Skip to content

Commit 9e01d72

Browse files
fromcelticparkfacebook-github-bot
authored andcommitted
Unify supplimentary bundle path creation logic between Android and iOS
Differential Revision: D5941546 fbshipit-source-id: c9b8fab887f480faa373c26a1d5ba310e8acde78
1 parent adde2ed commit 9e01d72

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

React/CxxBridge/RCTCxxBridge.mm

+1-2
Original file line numberDiff line numberDiff line change
@@ -1190,8 +1190,7 @@ - (void)executeApplicationScript:(NSData *)script
11901190
[self->_performanceLogger markStopForTag:RCTPLRAMBundleLoad];
11911191
[self->_performanceLogger setValue:scriptStr->size() forTag:RCTPLRAMStartupCodeSize];
11921192
if (self->_reactInstance) {
1193-
std::string baseDirectoryPath = sourceUrlStr.stringByDeletingLastPathComponent.UTF8String;
1194-
auto registry = std::make_unique<JSIndexedRAMBundleRegistry>(std::move(ramBundle), baseDirectoryPath);
1193+
auto registry = std::make_unique<JSIndexedRAMBundleRegistry>(std::move(ramBundle), sourceUrlStr.UTF8String);
11951194
self->_reactInstance->loadRAMBundle(std::move(registry), std::move(scriptStr),
11961195
sourceUrlStr.UTF8String, !async);
11971196
}

ReactAndroid/src/main/jni/react/jni/JniRAMBundleRegistry.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
#include "JniRAMBundleRegistry.h"
44

5-
#include <libgen.h>
6-
75
#include <folly/Conv.h>
86
#include <folly/Memory.h>
97

@@ -12,16 +10,6 @@
1210
namespace facebook {
1311
namespace react {
1412

15-
static std::string jsBundlesDir(const std::string& entryFile) {
16-
std::string dir = dirname(entryFile.c_str());
17-
std::string entryName = basename(entryFile.c_str());
18-
entryName.erase(entryName.find("."), std::string::npos);
19-
20-
std::string path = "js-bundles/" + entryName + "/";
21-
// android's asset manager does not work with paths that start with a dot
22-
return dir == "." ? path : dir + "/" + path;
23-
}
24-
2513
JniRAMBundleRegistry::JniRAMBundleRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle, AAssetManager *assetManager, const std::string& entryFile) :
2614
RAMBundleRegistry(std::move(mainBundle)),
2715
m_assetManager(assetManager),

ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
namespace facebook {
1111
namespace react {
1212

13-
std::unique_ptr<JSModulesUnbundle> JSIndexedRAMBundleRegistry::bundleById(uint32_t index) const {
14-
return folly::make_unique<JSIndexedRAMBundle>(bundlePathById(index).c_str());
15-
}
13+
JSIndexedRAMBundleRegistry::JSIndexedRAMBundleRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle, const std::string& entryFile):
14+
RAMBundleRegistry(std::move(mainBundle)), m_baseDirectoryPath(jsBundlesDir(entryFile)) {}
1615

17-
std::string JSIndexedRAMBundleRegistry::bundlePathById(uint32_t index) const {
18-
return m_baseDirectoryPath + "/js-bundles/" + toString(index) + ".jsbundle";
16+
std::unique_ptr<JSModulesUnbundle> JSIndexedRAMBundleRegistry::bundleById(uint32_t index) const {
17+
std::string bundlePathById = m_baseDirectoryPath + toString(index) + ".jsbundle";
18+
return folly::make_unique<JSIndexedRAMBundle>(bundlePathById.c_str());
1919
}
2020

2121
} // namespace react

ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.h

+1-6
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,11 @@ namespace react {
1313

1414
class RN_EXPORT JSIndexedRAMBundleRegistry: public RAMBundleRegistry {
1515
public:
16-
JSIndexedRAMBundleRegistry(
17-
std::unique_ptr<JSModulesUnbundle> mainBundle,
18-
std::string baseDirectoryPath):
19-
RAMBundleRegistry(std::move(mainBundle)), m_baseDirectoryPath(baseDirectoryPath) {}
16+
JSIndexedRAMBundleRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle, const std::string& entryFile);
2017

2118
protected:
2219
virtual std::unique_ptr<JSModulesUnbundle> bundleById(uint32_t index) const override;
2320
private:
24-
std::string bundlePathById(uint32_t index) const;
25-
2621
std::string m_baseDirectoryPath;
2722
};
2823

ReactCommon/cxxreact/RAMBundleRegistry.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include "RAMBundleRegistry.h"
44

5+
#include <libgen.h>
6+
57
namespace facebook {
68
namespace react {
79

@@ -23,5 +25,20 @@ JSModulesUnbundle *RAMBundleRegistry::getBundle(uint32_t bundleId) const {
2325
return m_bundles.at(bundleId).get();
2426
}
2527

28+
std::string RAMBundleRegistry::jsBundlesDir(std::string entryFile) {
29+
char *pEntryFile = const_cast<char *>(entryFile.c_str());
30+
std::string dir = dirname(pEntryFile);
31+
std::string entryName = basename(pEntryFile);
32+
33+
std::size_t dotPosition = entryName.find(".");
34+
if (dotPosition != std::string::npos) {
35+
entryName.erase(dotPosition, std::string::npos);
36+
}
37+
38+
std::string path = "js-bundles/" + entryName + "/";
39+
// android's asset manager does not work with paths that start with a dot
40+
return dir == "." ? path : dir + "/" + path;
41+
}
42+
2643
} // namespace react
2744
} // namespace facebook

ReactCommon/cxxreact/RAMBundleRegistry.h

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class RN_EXPORT RAMBundleRegistry : noncopyable {
2828
JSModulesUnbundle::Module getModule(uint32_t bundleId, uint32_t moduleId);
2929
virtual ~RAMBundleRegistry() {};
3030
protected:
31+
std::string jsBundlesDir(std::string entryFile);
3132
virtual std::unique_ptr<JSModulesUnbundle> bundleById(uint32_t index) const {
3233
throw std::runtime_error("Please, override this method in a subclass to support multiple RAM bundles.");
3334
}

0 commit comments

Comments
 (0)