Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/react-native/React/Base/RCTBundleURLProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ RCT_EXTERN void RCTBundleURLProviderAllowPackagerServerAccess(BOOL allowed);

@property (nonatomic, assign) BOOL enableMinification;
@property (nonatomic, assign) BOOL enableDev;
@property (nonatomic, assign) BOOL inlineSourceMap;

/**
* The scheme/protocol used of the packager, the default is the http protocol
Expand Down Expand Up @@ -133,7 +134,8 @@ RCT_EXTERN void RCTBundleURLProviderAllowPackagerServerAccess(BOOL allowed);
enableDev:(BOOL)enableDev
enableMinification:(BOOL)enableMinification
modulesOnly:(BOOL)modulesOnly
runModule:(BOOL)runModule;
runModule:(BOOL)runModule
inlineSourceMap:(BOOL)inlineSourceMap;
/**
* Given a hostname for the packager and a resource path (including "/"), return the URL to the resource.
* In general, please use the instance method to decide if the packager is running and fallback to the pre-packaged
Expand All @@ -142,6 +144,6 @@ RCT_EXTERN void RCTBundleURLProviderAllowPackagerServerAccess(BOOL allowed);
+ (NSURL *)resourceURLForResourcePath:(NSString *)path
packagerHost:(NSString *)packagerHost
scheme:(NSString *)scheme
query:(NSString *)query;
queryItems:(NSArray<NSURLQueryItem *> *)queryItems;
Comment thread
Saadnajmi marked this conversation as resolved.

@end
55 changes: 38 additions & 17 deletions packages/react-native/React/Base/RCTBundleURLProvider.mm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void RCTBundleURLProviderAllowPackagerServerAccess(BOOL allowed)
static NSString *const kRCTJsLocationKey = @"RCT_jsLocation";
static NSString *const kRCTEnableDevKey = @"RCT_enableDev";
static NSString *const kRCTEnableMinificationKey = @"RCT_enableMinification";
static NSString *const kRCTinlineSourceMapKey = @"RCT_inlineSourceMap";

@implementation RCTBundleURLProvider

Expand All @@ -43,6 +44,9 @@ - (NSDictionary *)defaults
return @{
kRCTEnableDevKey : @YES,
kRCTEnableMinificationKey : @NO,
#if !USE_HERMES
kRCTinlineSourceMapKey: @YES,
#endif
};
}

Expand Down Expand Up @@ -188,7 +192,8 @@ - (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackURLProvider:(
enableDev:[self enableDev]
enableMinification:[self enableMinification]
modulesOnly:NO
runModule:YES];
runModule:YES
inlineSourceMap:[self inlineSourceMap]];
Comment thread
Saadnajmi marked this conversation as resolved.
Outdated
}
}

Expand All @@ -200,7 +205,8 @@ - (NSURL *)jsBundleURLForSplitBundleRoot:(NSString *)bundleRoot
enableDev:[self enableDev]
enableMinification:[self enableMinification]
modulesOnly:YES
runModule:NO];
runModule:NO
inlineSourceMap:NO];
Comment thread
Saadnajmi marked this conversation as resolved.
Outdated
}

- (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackExtension:(NSString *)extension
Expand Down Expand Up @@ -238,7 +244,7 @@ - (NSURL *)resourceURLForResourceRoot:(NSString *)root
return [[self class] resourceURLForResourcePath:path
packagerHost:packagerServerHostPort
scheme:packagerServerScheme
query:nil];
queryItems:nil];
}

+ (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
Expand All @@ -253,7 +259,8 @@ + (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
enableDev:enableDev
enableMinification:enableMinification
modulesOnly:NO
runModule:YES];
runModule:YES
inlineSourceMap:NO];
Comment thread
Saadnajmi marked this conversation as resolved.
Outdated
}

+ (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
Expand All @@ -263,34 +270,37 @@ + (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
enableMinification:(BOOL)enableMinification
modulesOnly:(BOOL)modulesOnly
runModule:(BOOL)runModule
inlineSourceMap:(BOOL)inlineSourceMap;

{
NSString *path = [NSString stringWithFormat:@"/%@.bundle", bundleRoot];
BOOL lazy = enableDev;
// When we support only iOS 8 and above, use queryItems for a better API.
NSString *query = [NSString stringWithFormat:@"platform=ios&dev=%@&lazy=%@&minify=%@&modulesOnly=%@&runModule=%@",
enableDev ? @"true" : @"false",
lazy ? @"true" : @"false",
enableMinification ? @"true" : @"false",
modulesOnly ? @"true" : @"false",
runModule ? @"true" : @"false"];

NSArray<NSURLQueryItem *> *queryItems = @[
Comment thread
Saadnajmi marked this conversation as resolved.
[[NSURLQueryItem alloc] initWithName:@"dev" value:enableDev ? @"true" : @"false"],
[[NSURLQueryItem alloc] initWithName:@"lazy" value:enableMinification ? @"true" : @"false"],
Comment thread
Saadnajmi marked this conversation as resolved.
Outdated
[[NSURLQueryItem alloc] initWithName:@"minify" value:modulesOnly ? @"true" : @"false"],
[[NSURLQueryItem alloc] initWithName:@"modulesOnly" value:modulesOnly ? @"true" : @"false"],
[[NSURLQueryItem alloc] initWithName:@"runModule" value:runModule ? @"true" : @"false"],
[[NSURLQueryItem alloc] initWithName:@"inlineSourceMap" value:inlineSourceMap ? @"true" : @"false"],
];

NSString *bundleID = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleIdentifierKey];
if (bundleID) {
query = [NSString stringWithFormat:@"%@&app=%@", query, bundleID];
queryItems = [queryItems arrayByAddingObject:[[NSURLQueryItem alloc] initWithName:@"app" value:bundleID]];
}
return [[self class] resourceURLForResourcePath:path packagerHost:packagerHost scheme:scheme query:query];
return [[self class] resourceURLForResourcePath:path packagerHost:packagerHost scheme:scheme queryItems:queryItems];
}

+ (NSURL *)resourceURLForResourcePath:(NSString *)path
packagerHost:(NSString *)packagerHost
scheme:(NSString *)scheme
query:(NSString *)query
queryItems:(NSArray<NSURLQueryItem *> *)queryItems
{
NSURLComponents *components = [NSURLComponents componentsWithURL:serverRootWithHostPort(packagerHost, scheme)
resolvingAgainstBaseURL:NO];
components.path = path;
if (query != nil) {
components.query = query;
if (queryItems != nil) {
components.queryItems = queryItems;
}
return components.URL;
}
Expand All @@ -312,6 +322,11 @@ - (BOOL)enableMinification
return [[NSUserDefaults standardUserDefaults] boolForKey:kRCTEnableMinificationKey];
}

- (BOOL)inlineSourceMap
{
return [[NSUserDefaults standardUserDefaults] boolForKey:kRCTinlineSourceMapKey];
}

- (NSString *)jsLocation
{
return [[NSUserDefaults standardUserDefaults] stringForKey:kRCTJsLocationKey];
Expand Down Expand Up @@ -341,6 +356,12 @@ - (void)setEnableMinification:(BOOL)enableMinification
[self updateValue:@(enableMinification) forKey:kRCTEnableMinificationKey];
}

- (void)setInlineSourceMap:(BOOL)inlineSourceMap
{
[self updateValue:@(inlineSourceMap) forKey:kRCTinlineSourceMapKey];
}


Comment thread
Saadnajmi marked this conversation as resolved.
Outdated
- (void)setPackagerScheme:(NSString *)packagerScheme
{
[self updateValue:packagerScheme forKey:kRCTPackagerSchemeKey];
Expand Down
3 changes: 3 additions & 0 deletions packages/rn-tester/RNTester/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ - (NSDictionary *)prepareInitialProps

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if !USE_HERMES
[[RCTBundleURLProvider sharedSettings] setInlineSourceMap:YES];
#endif
Comment thread
Saadnajmi marked this conversation as resolved.
Outdated
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"js/RNTesterApp.ios"];
}

Expand Down