@@ -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
@@ -183,6 +185,7 @@ - (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackURLProvider:(
183185                                           packagerScheme: [self  packagerScheme ]
184186                                                enableDev: [self  enableDev ]
185187                                       enableMinification: [self  enableMinification ]
188+                                           inlineSourceMap: [self  inlineSourceMap ]
186189                                              modulesOnly: NO 
187190                                                runModule: YES ];
188191  }
@@ -195,6 +198,7 @@ - (NSURL *)jsBundleURLForSplitBundleRoot:(NSString *)bundleRoot
195198                                         packagerScheme: [self  packagerScheme ]
196199                                              enableDev: [self  enableDev ]
197200                                     enableMinification: [self  enableMinification ]
201+                                         inlineSourceMap: [self  inlineSourceMap ]
198202                                            modulesOnly: YES 
199203                                              runModule: NO ];
200204}
@@ -234,20 +238,37 @@ - (NSURL *)resourceURLForResourceRoot:(NSString *)root
234238  return  [[self  class ] resourceURLForResourcePath: path
235239                                     packagerHost: packagerServerHostPort
236240                                           scheme: packagerServerScheme
237-                                              query :nil ];
241+                                        queryItems :nil ];
238242}
239243
240244+ (NSURL  *)jsBundleURLForBundleRoot : (NSString  *)bundleRoot 
241245                       packagerHost : (NSString  *)packagerHost 
242246                          enableDev : (BOOL )enableDev 
243247                 enableMinification : (BOOL )enableMinification 
248+ {
249+   return  [self  jsBundleURLForBundleRoot: bundleRoot
250+                            packagerHost: packagerHost
251+                          packagerScheme: nil 
252+                               enableDev: enableDev
253+                      enableMinification: enableMinification
254+                         inlineSourceMap: NO 
255+                             modulesOnly: NO 
256+                               runModule: YES ];
257+ }
258+ 
259+ + (NSURL  *)jsBundleURLForBundleRoot : (NSString  *)bundleRoot 
260+                        packagerHost : (NSString  *)packagerHost 
261+                           enableDev : (BOOL )enableDev 
262+                  enableMinification : (BOOL )enableMinification 
263+                     inlineSourceMap : (BOOL )inlineSourceMap 
244264
245265{
246266  return  [self  jsBundleURLForBundleRoot: bundleRoot
247267                           packagerHost: packagerHost
248268                         packagerScheme: nil 
249269                              enableDev: enableDev
250270                     enableMinification: enableMinification
271+                         inlineSourceMap: inlineSourceMap
251272                            modulesOnly: NO 
252273                              runModule: YES ];
253274}
@@ -259,27 +280,45 @@ + (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
259280                 enableMinification : (BOOL )enableMinification 
260281                        modulesOnly : (BOOL )modulesOnly 
261282                          runModule : (BOOL )runModule 
283+ {
284+   return  [self  jsBundleURLForBundleRoot: bundleRoot
285+                            packagerHost: packagerHost
286+                          packagerScheme: nil 
287+                               enableDev: enableDev
288+                      enableMinification: enableMinification
289+                         inlineSourceMap: NO 
290+                             modulesOnly: modulesOnly
291+                               runModule: runModule];
292+ }
293+ 
294+ + (NSURL  *)jsBundleURLForBundleRoot : (NSString  *)bundleRoot 
295+                        packagerHost : (NSString  *)packagerHost 
296+                      packagerScheme : (NSString  *)scheme 
297+                           enableDev : (BOOL )enableDev 
298+                  enableMinification : (BOOL )enableMinification 
299+                     inlineSourceMap : (BOOL )inlineSourceMap 
300+                         modulesOnly : (BOOL )modulesOnly 
301+                           runModule : (BOOL )runModule 
262302{
263303  NSString  *path = [NSString  stringWithFormat: @" /%@ .bundle" 
304+   BOOL  lazy = enableDev;
305+   NSArray <NSURLQueryItem  *> *queryItems = @[
306+     [[NSURLQueryItem  alloc ] initWithName: @" platform" value: kRCTPlatformName ],
307+     [[NSURLQueryItem  alloc ] initWithName: @" dev" value: enableDev ? @" true" @" false" 
308+     [[NSURLQueryItem  alloc ] initWithName: @" minify" value: enableMinification ? @" true" @" false" 
309+     [[NSURLQueryItem  alloc ] initWithName: @" inlineSourceMap" value: inlineSourceMap ? @" true" @" false" 
310+     [[NSURLQueryItem  alloc ] initWithName: @" modulesOnly" value: modulesOnly ? @" true" @" false" 
311+     [[NSURLQueryItem  alloc ] initWithName: @" runModule" value: runModule ? @" true" @" false" 
264312#ifdef  HERMES_BYTECODE_VERSION
265-   NSString  *runtimeBytecodeVersion = [NSString  stringWithFormat: @" &runtimeBytecodeVersion=%u " 
266- #else 
267-   NSString  *runtimeBytecodeVersion = @" " 
313+     [[NSURLQueryItem  alloc ] initWithName: @" runtimeBytecodeVersion" value: HERMES_BYTECODE_VERSION],
268314#endif 
269- 
270-   //  When we support only iOS 8 and above, use queryItems for a better API.
271-   NSString  *query = [NSString  stringWithFormat: @" platform=ios&dev=%@ &minify=%@ &modulesOnly=%@ &runModule=%@%@ " 
272-                                                enableDev ? @" true" @" false" 
273-                                                enableMinification ? @" true" @" false" 
274-                                                modulesOnly ? @" true" @" false" 
275-                                                runModule ? @" true" @" false" 
276-                                                runtimeBytecodeVersion];
315+   ];
277316
278317  NSString  *bundleID = [[NSBundle  mainBundle ] objectForInfoDictionaryKey: (NSString  *)kCFBundleIdentifierKey ];
279318  if  (bundleID) {
280-     query  = [NSString   stringWithFormat: @" %@ & app= %@ " , query,  bundleID];
319+     queryItems  = [queryItems  arrayByAddingObject: [[ NSURLQueryItem   alloc ]  initWithName: @" app"   value: bundleID] ];
281320  }
282-   return  [[self  class ] resourceURLForResourcePath: path packagerHost: packagerHost scheme: scheme query: query ];
321+   return  [[self  class ] resourceURLForResourcePath: path packagerHost: packagerHost scheme: scheme queryItems: queryItems ];
283322}
284323
285324+ (NSURL  *)resourceURLForResourcePath : (NSString  *)path 
@@ -296,6 +335,20 @@ + (NSURL *)resourceURLForResourcePath:(NSString *)path
296335  return  components.URL ;
297336}
298337
338+ + (NSURL  *)resourceURLForResourcePath : (NSString  *)path 
339+                          packagerHost : (NSString  *)packagerHost 
340+                                scheme : (NSString  *)scheme 
341+                            queryItems : (NSArray <NSURLQueryItem *> *)queryItems 
342+ {
343+   NSURLComponents  *components = [NSURLComponents  componentsWithURL: serverRootWithHostPort (packagerHost, scheme)
344+                                            resolvingAgainstBaseURL: NO ];
345+   components.path  = path;
346+   if  (queryItems != nil ) {
347+     components.queryItems  = queryItems;
348+   }
349+   return  components.URL ;
350+ }
351+ 
299352- (void )updateValue : (id )object  forKey : (NSString  *)key 
300353{
301354  [[NSUserDefaults  standardUserDefaults ] setObject: object forKey: key];
@@ -313,6 +366,11 @@ - (BOOL)enableMinification
313366  return  [[NSUserDefaults  standardUserDefaults ] boolForKey: kRCTEnableMinificationKey ];
314367}
315368
369+ - (BOOL )inlineSourceMap 
370+ {
371+   return  [[NSUserDefaults  standardUserDefaults ] boolForKey: kRCTInlineSourceMapKey ];
372+ }
373+ 
316374- (NSString  *)jsLocation 
317375{
318376  return  [[NSUserDefaults  standardUserDefaults ] stringForKey: kRCTJsLocationKey ];
@@ -342,6 +400,11 @@ - (void)setEnableMinification:(BOOL)enableMinification
342400  [self  updateValue: @(enableMinification) forKey: kRCTEnableMinificationKey ];
343401}
344402
403+ - (void )setInlineSourceMap : (BOOL )inlineSourceMap 
404+ {
405+   [self  updateValue: @(inlineSourceMap) forKey: kRCTInlineSourceMapKey ];
406+ }
407+ 
345408- (void )setPackagerScheme : (NSString  *)packagerScheme 
346409{
347410  [self  updateValue: packagerScheme forKey: kRCTPackagerSchemeKey ];
0 commit comments