@@ -22,10 +22,12 @@ void RCTBundleURLProviderAllowPackagerServerAccess(BOOL allowed)
22
22
kRCTAllowPackagerAccess = allowed;
23
23
}
24
24
#endif
25
+ static NSString *const kRCTPlatformName = @" ios" ;
25
26
static NSString *const kRCTPackagerSchemeKey = @" RCT_packager_scheme" ;
26
27
static NSString *const kRCTJsLocationKey = @" RCT_jsLocation" ;
27
28
static NSString *const kRCTEnableDevKey = @" RCT_enableDev" ;
28
29
static NSString *const kRCTEnableMinificationKey = @" RCT_enableMinification" ;
30
+ static NSString *const kRCTInlineSourceMapKey = @" RCT_inlineSourceMap" ;
29
31
30
32
@implementation RCTBundleURLProvider
31
33
@@ -187,6 +189,7 @@ - (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackURLProvider:(
187
189
packagerScheme: [self packagerScheme ]
188
190
enableDev: [self enableDev ]
189
191
enableMinification: [self enableMinification ]
192
+ inlineSourceMap: [self inlineSourceMap ]
190
193
modulesOnly: NO
191
194
runModule: YES ];
192
195
}
@@ -199,6 +202,7 @@ - (NSURL *)jsBundleURLForSplitBundleRoot:(NSString *)bundleRoot
199
202
packagerScheme: [self packagerScheme ]
200
203
enableDev: [self enableDev ]
201
204
enableMinification: [self enableMinification ]
205
+ inlineSourceMap: [self inlineSourceMap ]
202
206
modulesOnly: YES
203
207
runModule: NO ];
204
208
}
@@ -238,20 +242,37 @@ - (NSURL *)resourceURLForResourceRoot:(NSString *)root
238
242
return [[self class ] resourceURLForResourcePath: path
239
243
packagerHost: packagerServerHostPort
240
244
scheme: packagerServerScheme
241
- query :nil ];
245
+ queryItems :nil ];
242
246
}
243
247
244
248
+ (NSURL *)jsBundleURLForBundleRoot : (NSString *)bundleRoot
245
249
packagerHost : (NSString *)packagerHost
246
250
enableDev : (BOOL )enableDev
247
251
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
248
268
249
269
{
250
270
return [self jsBundleURLForBundleRoot: bundleRoot
251
271
packagerHost: packagerHost
252
272
packagerScheme: nil
253
273
enableDev: enableDev
254
274
enableMinification: enableMinification
275
+ inlineSourceMap: inlineSourceMap
255
276
modulesOnly: NO
256
277
runModule: YES ];
257
278
}
@@ -263,27 +284,45 @@ + (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
263
284
enableMinification : (BOOL )enableMinification
264
285
modulesOnly : (BOOL )modulesOnly
265
286
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
266
306
{
267
307
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" ],
268
316
#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
+ ];
281
320
282
321
NSString *bundleID = [[NSBundle mainBundle ] objectForInfoDictionaryKey: (NSString *)kCFBundleIdentifierKey ];
283
322
if (bundleID) {
284
- query = [NSString stringWithFormat: @" %@ & app= %@ " , query, bundleID];
323
+ queryItems = [queryItems arrayByAddingObject: [[ NSURLQueryItem alloc ] initWithName: @" app" value: bundleID] ];
285
324
}
286
- return [[self class ] resourceURLForResourcePath: path packagerHost: packagerHost scheme: scheme query: query ];
325
+ return [[self class ] resourceURLForResourcePath: path packagerHost: packagerHost scheme: scheme queryItems: queryItems ];
287
326
}
288
327
289
328
+ (NSURL *)resourceURLForResourcePath : (NSString *)path
@@ -300,6 +339,20 @@ + (NSURL *)resourceURLForResourcePath:(NSString *)path
300
339
return components.URL ;
301
340
}
302
341
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
+
303
356
- (void )updateValue : (id )object forKey : (NSString *)key
304
357
{
305
358
[[NSUserDefaults standardUserDefaults ] setObject: object forKey: key];
@@ -317,6 +370,11 @@ - (BOOL)enableMinification
317
370
return [[NSUserDefaults standardUserDefaults ] boolForKey: kRCTEnableMinificationKey ];
318
371
}
319
372
373
+ - (BOOL )inlineSourceMap
374
+ {
375
+ return [[NSUserDefaults standardUserDefaults ] boolForKey: kRCTInlineSourceMapKey ];
376
+ }
377
+
320
378
- (NSString *)jsLocation
321
379
{
322
380
return [[NSUserDefaults standardUserDefaults ] stringForKey: kRCTJsLocationKey ];
@@ -346,6 +404,11 @@ - (void)setEnableMinification:(BOOL)enableMinification
346
404
[self updateValue: @(enableMinification) forKey: kRCTEnableMinificationKey ];
347
405
}
348
406
407
+ - (void )setInlineSourceMap : (BOOL )inlineSourceMap
408
+ {
409
+ [self updateValue: @(inlineSourceMap) forKey: kRCTInlineSourceMapKey ];
410
+ }
411
+
349
412
- (void )setPackagerScheme : (NSString *)packagerScheme
350
413
{
351
414
[self updateValue: packagerScheme forKey: kRCTPackagerSchemeKey ];
0 commit comments