@@ -22,10 +22,12 @@ void RCTBundleURLProviderAllowPackagerServerAccess(BOOL allowed)
2222 kRCTAllowPackagerAccess = allowed;
2323}
2424#endif
25+ static NSString *const kRCTPlatformName = @" ios" ;
2526static NSString *const kRCTPackagerSchemeKey = @" RCT_packager_scheme" ;
2627static NSString *const kRCTJsLocationKey = @" RCT_jsLocation" ;
2728static NSString *const kRCTEnableDevKey = @" RCT_enableDev" ;
2829static NSString *const kRCTEnableMinificationKey = @" RCT_enableMinification" ;
30+ static NSString *const kRCTInlineSourceMapKey = @" RCT_inlineSourceMap" ;
2931
3032@implementation RCTBundleURLProvider
3133
@@ -187,6 +189,7 @@ - (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackURLProvider:(
187189 packagerScheme: [self packagerScheme ]
188190 enableDev: [self enableDev ]
189191 enableMinification: [self enableMinification ]
192+ inlineSourceMap: [self inlineSourceMap ]
190193 modulesOnly: NO
191194 runModule: YES ];
192195 }
@@ -199,6 +202,7 @@ - (NSURL *)jsBundleURLForSplitBundleRoot:(NSString *)bundleRoot
199202 packagerScheme: [self packagerScheme ]
200203 enableDev: [self enableDev ]
201204 enableMinification: [self enableMinification ]
205+ inlineSourceMap: [self inlineSourceMap ]
202206 modulesOnly: YES
203207 runModule: NO ];
204208}
@@ -238,20 +242,37 @@ - (NSURL *)resourceURLForResourceRoot:(NSString *)root
238242 return [[self class ] resourceURLForResourcePath: path
239243 packagerHost: packagerServerHostPort
240244 scheme: packagerServerScheme
241- query :nil ];
245+ queryItems :nil ];
242246}
243247
244248+ (NSURL *)jsBundleURLForBundleRoot : (NSString *)bundleRoot
245249 packagerHost : (NSString *)packagerHost
246250 enableDev : (BOOL )enableDev
247251 enableMinification : (BOOL )enableMinification
252+ {
253+ return [self jsBundleURLForBundleRoot: bundleRoot
254+ packagerHost: packagerHost
255+ packagerScheme: nil
256+ enableDev: enableDev
257+ enableMinification: enableMinification
258+ inlineSourceMap: NO
259+ modulesOnly: NO
260+ runModule: YES ];
261+ }
262+
263+ + (NSURL *)jsBundleURLForBundleRoot : (NSString *)bundleRoot
264+ packagerHost : (NSString *)packagerHost
265+ enableDev : (BOOL )enableDev
266+ enableMinification : (BOOL )enableMinification
267+ inlineSourceMap : (BOOL )inlineSourceMap
248268
249269{
250270 return [self jsBundleURLForBundleRoot: bundleRoot
251271 packagerHost: packagerHost
252272 packagerScheme: nil
253273 enableDev: enableDev
254274 enableMinification: enableMinification
275+ inlineSourceMap: inlineSourceMap
255276 modulesOnly: NO
256277 runModule: YES ];
257278}
@@ -263,27 +284,45 @@ + (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
263284 enableMinification : (BOOL )enableMinification
264285 modulesOnly : (BOOL )modulesOnly
265286 runModule : (BOOL )runModule
287+ {
288+ return [self jsBundleURLForBundleRoot: bundleRoot
289+ packagerHost: packagerHost
290+ packagerScheme: nil
291+ enableDev: enableDev
292+ enableMinification: enableMinification
293+ inlineSourceMap: NO
294+ modulesOnly: modulesOnly
295+ runModule: runModule];
296+ }
297+
298+ + (NSURL *)jsBundleURLForBundleRoot : (NSString *)bundleRoot
299+ packagerHost : (NSString *)packagerHost
300+ packagerScheme : (NSString *)scheme
301+ enableDev : (BOOL )enableDev
302+ enableMinification : (BOOL )enableMinification
303+ inlineSourceMap : (BOOL )inlineSourceMap
304+ modulesOnly : (BOOL )modulesOnly
305+ runModule : (BOOL )runModule
266306{
267307 NSString *path = [NSString stringWithFormat: @" /%@ .bundle" , bundleRoot];
308+ BOOL lazy = enableDev;
309+ NSArray <NSURLQueryItem *> *queryItems = @[
310+ [[NSURLQueryItem alloc ] initWithName: @" platform" value: kRCTPlatformName ],
311+ [[NSURLQueryItem alloc ] initWithName: @" dev" value: enableDev ? @" true" : @" false" ],
312+ [[NSURLQueryItem alloc ] initWithName: @" minify" value: enableMinification ? @" true" : @" false" ],
313+ [[NSURLQueryItem alloc ] initWithName: @" inlineSourceMap" value: inlineSourceMap ? @" true" : @" false" ],
314+ [[NSURLQueryItem alloc ] initWithName: @" modulesOnly" value: modulesOnly ? @" true" : @" false" ],
315+ [[NSURLQueryItem alloc ] initWithName: @" runModule" value: runModule ? @" true" : @" false" ],
268316#ifdef HERMES_BYTECODE_VERSION
269- NSString *runtimeBytecodeVersion = [NSString stringWithFormat: @" &runtimeBytecodeVersion=%u " , HERMES_BYTECODE_VERSION];
270- #else
271- NSString *runtimeBytecodeVersion = @" " ;
272- #endif
273-
274- // When we support only iOS 8 and above, use queryItems for a better API.
275- NSString *query = [NSString stringWithFormat: @" platform=ios&dev=%@ &minify=%@ &modulesOnly=%@ &runModule=%@%@ " ,
276- enableDev ? @" true" : @" false" ,
277- enableMinification ? @" true" : @" false" ,
278- modulesOnly ? @" true" : @" false" ,
279- runModule ? @" true" : @" false" ,
280- runtimeBytecodeVersion];
317+ [[NSURLQueryItem alloc ] initWithName: @" runtimeBytecodeVersion" value: HERMES_BYTECODE_VERSION],
318+ #endif
319+ ];
281320
282321 NSString *bundleID = [[NSBundle mainBundle ] objectForInfoDictionaryKey: (NSString *)kCFBundleIdentifierKey ];
283322 if (bundleID) {
284- query = [NSString stringWithFormat: @" %@ & app= %@ " , query, bundleID];
323+ queryItems = [queryItems arrayByAddingObject: [[ NSURLQueryItem alloc ] initWithName: @" app" value: bundleID] ];
285324 }
286- return [[self class ] resourceURLForResourcePath: path packagerHost: packagerHost scheme: scheme query: query ];
325+ return [[self class ] resourceURLForResourcePath: path packagerHost: packagerHost scheme: scheme queryItems: queryItems ];
287326}
288327
289328+ (NSURL *)resourceURLForResourcePath : (NSString *)path
@@ -300,6 +339,20 @@ + (NSURL *)resourceURLForResourcePath:(NSString *)path
300339 return components.URL ;
301340}
302341
342+ + (NSURL *)resourceURLForResourcePath : (NSString *)path
343+ packagerHost : (NSString *)packagerHost
344+ scheme : (NSString *)scheme
345+ queryItems : (NSArray <NSURLQueryItem *> *)queryItems
346+ {
347+ NSURLComponents *components = [NSURLComponents componentsWithURL: serverRootWithHostPort (packagerHost, scheme)
348+ resolvingAgainstBaseURL: NO ];
349+ components.path = path;
350+ if (queryItems != nil ) {
351+ components.queryItems = queryItems;
352+ }
353+ return components.URL ;
354+ }
355+
303356- (void )updateValue : (id )object forKey : (NSString *)key
304357{
305358 [[NSUserDefaults standardUserDefaults ] setObject: object forKey: key];
@@ -317,6 +370,11 @@ - (BOOL)enableMinification
317370 return [[NSUserDefaults standardUserDefaults ] boolForKey: kRCTEnableMinificationKey ];
318371}
319372
373+ - (BOOL )inlineSourceMap
374+ {
375+ return [[NSUserDefaults standardUserDefaults ] boolForKey: kRCTInlineSourceMapKey ];
376+ }
377+
320378- (NSString *)jsLocation
321379{
322380 return [[NSUserDefaults standardUserDefaults ] stringForKey: kRCTJsLocationKey ];
@@ -346,6 +404,11 @@ - (void)setEnableMinification:(BOOL)enableMinification
346404 [self updateValue: @(enableMinification) forKey: kRCTEnableMinificationKey ];
347405}
348406
407+ - (void )setInlineSourceMap : (BOOL )inlineSourceMap
408+ {
409+ [self updateValue: @(inlineSourceMap) forKey: kRCTInlineSourceMapKey ];
410+ }
411+
349412- (void )setPackagerScheme : (NSString *)packagerScheme
350413{
351414 [self updateValue: packagerScheme forKey: kRCTPackagerSchemeKey ];
0 commit comments