Skip to content

Commit 8821d27

Browse files
cpojerfacebook-github-bot
authored andcommitted
RCTDevSplitBundleLoader: Add ability to enable modulesOnly and runModule
Summary: Changelog: [Internal] Reviewed By: jimmy623 Differential Revision: D21882786 fbshipit-source-id: 1f90c62c3a385f1b12caef4bcc01e5bf53f0f882
1 parent d676558 commit 8821d27

File tree

3 files changed

+69
-13
lines changed

3 files changed

+69
-13
lines changed

RNTester/RNTesterUnitTests/RCTBundleURLProviderTests.m

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,22 @@
2020

2121
static NSURL *localhostBundleURL()
2222
{
23-
return [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8081/%@.bundle?platform=ios&dev=true&minify=false&app=com.apple.dt.xctest.tool", testFile]];
23+
return [NSURL
24+
URLWithString:
25+
[NSString
26+
stringWithFormat:
27+
@"http://localhost:8081/%@.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runMdoule=true&app=com.apple.dt.xctest.tool",
28+
testFile]];
2429
}
2530

2631
static NSURL *ipBundleURL()
2732
{
28-
return [NSURL URLWithString:[NSString stringWithFormat:@"http://192.168.1.1:8081/%@.bundle?platform=ios&dev=true&minify=false&app=com.apple.dt.xctest.tool", testFile]];
33+
return [NSURL
34+
URLWithString:
35+
[NSString
36+
stringWithFormat:
37+
@"http://192.168.1.1:8081/%@.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runMdoule=true&app=com.apple.dt.xctest.tool",
38+
testFile]];
2939
}
3040

3141
@implementation NSBundle (RCTBundleURLProviderTests)
@@ -50,16 +60,14 @@ - (void)setUp
5060
{
5161
[super setUp];
5262

53-
RCTSwapInstanceMethods([NSBundle class],
54-
@selector(URLForResource:withExtension:),
55-
@selector(RCT_URLForResource:withExtension:));
63+
RCTSwapInstanceMethods(
64+
[NSBundle class], @selector(URLForResource:withExtension:), @selector(RCT_URLForResource:withExtension:));
5665
}
5766

5867
- (void)tearDown
5968
{
60-
RCTSwapInstanceMethods([NSBundle class],
61-
@selector(URLForResource:withExtension:),
62-
@selector(RCT_URLForResource:withExtension:));
69+
RCTSwapInstanceMethods(
70+
[NSBundle class], @selector(URLForResource:withExtension:), @selector(RCT_URLForResource:withExtension:));
6371

6472
[super tearDown];
6573
}

React/Base/RCTBundleURLProvider.h

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ extern const NSUInteger kRCTBundleURLProviderDefaultPort;
4545
*/
4646
- (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackURLProvider:(NSURL * (^)(void))fallbackURLProvider;
4747

48+
/**
49+
* Returns the jsBundleURL for a given split bundle entrypoint in development
50+
*/
51+
- (NSURL *)jsBundleURLForSplitBundleRoot:(NSString *)bundleRoot;
52+
4853
/**
4954
* Returns the jsBundleURL for a given bundle entrypoint and
5055
* the fallback offline JS bundle if the packager is not running.
@@ -89,15 +94,30 @@ extern const NSUInteger kRCTBundleURLProviderDefaultPort;
8994
+ (instancetype)sharedSettings;
9095

9196
/**
92-
Given a hostname for the packager and a bundle root, returns the URL to the js bundle. Generally you should use the
93-
instance method -jsBundleURLForBundleRoot:fallbackResource: which includes logic to guess if the packager is running
94-
and fall back to a pre-packaged bundle if it is not.
97+
* Given a hostname for the packager and a bundle root, returns the URL to the js bundle. Generally you should use the
98+
* instance method -jsBundleURLForBundleRoot:fallbackResource: which includes logic to guess if the packager is running
99+
* and fall back to a pre-packaged bundle if it is not.
100+
*
101+
* The options here mirror some of Metro's Bundling Options:
102+
* - enableDev: Whether to keep or remove `__DEV__` blocks from the bundle.
103+
* - enableMinification: Enables or disables minification. Usually production bundles are minified and development
104+
* bundles are not.
105+
* - modulesOnly: When true, will only send module definitions without polyfills and without the require-runtime.
106+
* - runModule: When true, will run the main module after defining all modules. This is used in the main bundle but not
107+
* in split bundles.
95108
*/
96109
+ (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
97110
packagerHost:(NSString *)packagerHost
98111
enableDev:(BOOL)enableDev
99112
enableMinification:(BOOL)enableMinification;
100113

114+
+ (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
115+
packagerHost:(NSString *)packagerHost
116+
enableDev:(BOOL)enableDev
117+
enableMinification:(BOOL)enableMinification
118+
modulesOnly:(BOOL)modulesOnly
119+
runModule:(BOOL)runModule;
120+
101121
/**
102122
* Given a hostname for the packager and a resource path (including "/"), return the URL to the resource.
103123
* In general, please use the instance method to decide if the packager is running and fallback to the pre-packaged

React/Base/RCTBundleURLProvider.m

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ - (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackURLProvider:(
145145
}
146146
}
147147

148+
- (NSURL *)jsBundleURLForSplitBundleRoot:(NSString *)bundleRoot
149+
{
150+
return [RCTBundleURLProvider jsBundleURLForBundleRoot:bundleRoot
151+
packagerHost:[self packagerServerHost]
152+
enableDev:[self enableDev]
153+
enableMinification:[self enableMinification]
154+
modulesOnly:YES
155+
runModule:NO];
156+
}
157+
148158
- (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
149159
fallbackResource:(NSString *)resourceName
150160
fallbackExtension:(NSString *)extension
@@ -186,12 +196,30 @@ + (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
186196
packagerHost:(NSString *)packagerHost
187197
enableDev:(BOOL)enableDev
188198
enableMinification:(BOOL)enableMinification
199+
200+
{
201+
return [self jsBundleURLForBundleRoot:bundleRoot
202+
packagerHost:packagerHost
203+
enableDev:enableDev
204+
enableMinification:enableMinification
205+
modulesOnly:NO
206+
runModule:YES];
207+
}
208+
209+
+ (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
210+
packagerHost:(NSString *)packagerHost
211+
enableDev:(BOOL)enableDev
212+
enableMinification:(BOOL)enableMinification
213+
modulesOnly:(BOOL)modulesOnly
214+
runModule:(BOOL)runModule
189215
{
190216
NSString *path = [NSString stringWithFormat:@"/%@.bundle", bundleRoot];
191217
// When we support only iOS 8 and above, use queryItems for a better API.
192-
NSString *query = [NSString stringWithFormat:@"platform=ios&dev=%@&minify=%@",
218+
NSString *query = [NSString stringWithFormat:@"platform=ios&dev=%@&minify=%@&modulesOnly=%@&runMdoule=%@",
193219
enableDev ? @"true" : @"false",
194-
enableMinification ? @"true" : @"false"];
220+
enableMinification ? @"true" : @"false",
221+
modulesOnly ? @"true" : @"false",
222+
runModule ? @"true" : @"false"];
195223
NSString *bundleID = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleIdentifierKey];
196224
if (bundleID) {
197225
query = [NSString stringWithFormat:@"%@&app=%@", query, bundleID];

0 commit comments

Comments
 (0)