@@ -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,22 +284,43 @@ + (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];
268308 BOOL lazy = enableDev;
269- // When we support only iOS 8 and above, use queryItems for a better API.
270- NSString *query = [NSString stringWithFormat: @" platform=ios&dev=%@ &lazy=%@ &minify=%@ &modulesOnly=%@ &runModule=%@ " ,
271- enableDev ? @" true" : @" false" ,
272- lazy ? @" true" : @" false" ,
273- enableMinification ? @" true" : @" false" ,
274- modulesOnly ? @" true" : @" false" ,
275- runModule ? @" true" : @" false" ];
309+ NSArray <NSURLQueryItem *> *queryItems = @[
310+ [[NSURLQueryItem alloc ] initWithName: @" platform" value: kRCTPlatformName ],
311+ [[NSURLQueryItem alloc ] initWithName: @" dev" value: enableDev ? @" true" : @" false" ],
312+ [[NSURLQueryItem alloc ] initWithName: @" lazy" value: lazy ? @" true" : @" false" ],
313+ [[NSURLQueryItem alloc ] initWithName: @" minify" value: enableMinification ? @" true" : @" false" ],
314+ [[NSURLQueryItem alloc ] initWithName: @" inlineSourceMap" value: inlineSourceMap ? @" true" : @" false" ],
315+ [[NSURLQueryItem alloc ] initWithName: @" modulesOnly" value: modulesOnly ? @" true" : @" false" ],
316+ [[NSURLQueryItem alloc ] initWithName: @" runModule" value: runModule ? @" true" : @" false" ],
317+ ];
276318
277319 NSString *bundleID = [[NSBundle mainBundle ] objectForInfoDictionaryKey: (NSString *)kCFBundleIdentifierKey ];
278320 if (bundleID) {
279- query = [NSString stringWithFormat: @" %@ & app= %@ " , query, bundleID];
321+ queryItems = [queryItems arrayByAddingObject: [[ NSURLQueryItem alloc ] initWithName: @" app" value: bundleID] ];
280322 }
281- return [[self class ] resourceURLForResourcePath: path packagerHost: packagerHost scheme: scheme query: query ];
323+ return [[self class ] resourceURLForResourcePath: path packagerHost: packagerHost scheme: scheme queryItems: queryItems ];
282324}
283325
284326+ (NSURL *)resourceURLForResourcePath : (NSString *)path
@@ -295,6 +337,20 @@ + (NSURL *)resourceURLForResourcePath:(NSString *)path
295337 return components.URL ;
296338}
297339
340+ + (NSURL *)resourceURLForResourcePath : (NSString *)path
341+ packagerHost : (NSString *)packagerHost
342+ scheme : (NSString *)scheme
343+ queryItems : (NSArray <NSURLQueryItem *> *)queryItems
344+ {
345+ NSURLComponents *components = [NSURLComponents componentsWithURL: serverRootWithHostPort (packagerHost, scheme)
346+ resolvingAgainstBaseURL: NO ];
347+ components.path = path;
348+ if (queryItems != nil ) {
349+ components.queryItems = queryItems;
350+ }
351+ return components.URL ;
352+ }
353+
298354- (void )updateValue : (id )object forKey : (NSString *)key
299355{
300356 [[NSUserDefaults standardUserDefaults ] setObject: object forKey: key];
@@ -312,6 +368,11 @@ - (BOOL)enableMinification
312368 return [[NSUserDefaults standardUserDefaults ] boolForKey: kRCTEnableMinificationKey ];
313369}
314370
371+ - (BOOL )inlineSourceMap
372+ {
373+ return [[NSUserDefaults standardUserDefaults ] boolForKey: kRCTInlineSourceMapKey ];
374+ }
375+
315376- (NSString *)jsLocation
316377{
317378 return [[NSUserDefaults standardUserDefaults ] stringForKey: kRCTJsLocationKey ];
@@ -341,6 +402,11 @@ - (void)setEnableMinification:(BOOL)enableMinification
341402 [self updateValue: @(enableMinification) forKey: kRCTEnableMinificationKey ];
342403}
343404
405+ - (void )setInlineSourceMap : (BOOL )inlineSourceMap
406+ {
407+ [self updateValue: @(inlineSourceMap) forKey: kRCTInlineSourceMapKey ];
408+ }
409+
344410- (void )setPackagerScheme : (NSString *)packagerScheme
345411{
346412 [self updateValue: packagerScheme forKey: kRCTPackagerSchemeKey ];
0 commit comments