@@ -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
@@ -183,6 +185,7 @@ - (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackURLProvider:(
183
185
packagerScheme: [self packagerScheme ]
184
186
enableDev: [self enableDev ]
185
187
enableMinification: [self enableMinification ]
188
+ inlineSourceMap: [self inlineSourceMap ]
186
189
modulesOnly: NO
187
190
runModule: YES ];
188
191
}
@@ -195,6 +198,7 @@ - (NSURL *)jsBundleURLForSplitBundleRoot:(NSString *)bundleRoot
195
198
packagerScheme: [self packagerScheme ]
196
199
enableDev: [self enableDev ]
197
200
enableMinification: [self enableMinification ]
201
+ inlineSourceMap: [self inlineSourceMap ]
198
202
modulesOnly: YES
199
203
runModule: NO ];
200
204
}
@@ -234,20 +238,37 @@ - (NSURL *)resourceURLForResourceRoot:(NSString *)root
234
238
return [[self class ] resourceURLForResourcePath: path
235
239
packagerHost: packagerServerHostPort
236
240
scheme: packagerServerScheme
237
- query :nil ];
241
+ queryItems :nil ];
238
242
}
239
243
240
244
+ (NSURL *)jsBundleURLForBundleRoot : (NSString *)bundleRoot
241
245
packagerHost : (NSString *)packagerHost
242
246
enableDev : (BOOL )enableDev
243
247
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
244
264
245
265
{
246
266
return [self jsBundleURLForBundleRoot: bundleRoot
247
267
packagerHost: packagerHost
248
268
packagerScheme: nil
249
269
enableDev: enableDev
250
270
enableMinification: enableMinification
271
+ inlineSourceMap: inlineSourceMap
251
272
modulesOnly: NO
252
273
runModule: YES ];
253
274
}
@@ -259,27 +280,45 @@ + (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
259
280
enableMinification : (BOOL )enableMinification
260
281
modulesOnly : (BOOL )modulesOnly
261
282
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
262
302
{
263
303
NSString *path = [NSString stringWithFormat: @" /%@ .bundle" , bundleRoot];
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" ],
264
312
#ifdef HERMES_BYTECODE_VERSION
265
- NSString *runtimeBytecodeVersion = [NSString stringWithFormat: @" &runtimeBytecodeVersion=%u " , HERMES_BYTECODE_VERSION];
266
- #else
267
- NSString *runtimeBytecodeVersion = @" " ;
313
+ [[NSURLQueryItem alloc ] initWithName: @" runtimeBytecodeVersion" value: HERMES_BYTECODE_VERSION],
268
314
#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
+ ];
277
316
278
317
NSString *bundleID = [[NSBundle mainBundle ] objectForInfoDictionaryKey: (NSString *)kCFBundleIdentifierKey ];
279
318
if (bundleID) {
280
- query = [NSString stringWithFormat: @" %@ & app= %@ " , query, bundleID];
319
+ queryItems = [queryItems arrayByAddingObject: [[ NSURLQueryItem alloc ] initWithName: @" app" value: bundleID] ];
281
320
}
282
- return [[self class ] resourceURLForResourcePath: path packagerHost: packagerHost scheme: scheme query: query ];
321
+ return [[self class ] resourceURLForResourcePath: path packagerHost: packagerHost scheme: scheme queryItems: queryItems ];
283
322
}
284
323
285
324
+ (NSURL *)resourceURLForResourcePath : (NSString *)path
@@ -296,6 +335,20 @@ + (NSURL *)resourceURLForResourcePath:(NSString *)path
296
335
return components.URL ;
297
336
}
298
337
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
+
299
352
- (void )updateValue : (id )object forKey : (NSString *)key
300
353
{
301
354
[[NSUserDefaults standardUserDefaults ] setObject: object forKey: key];
@@ -313,6 +366,11 @@ - (BOOL)enableMinification
313
366
return [[NSUserDefaults standardUserDefaults ] boolForKey: kRCTEnableMinificationKey ];
314
367
}
315
368
369
+ - (BOOL )inlineSourceMap
370
+ {
371
+ return [[NSUserDefaults standardUserDefaults ] boolForKey: kRCTInlineSourceMapKey ];
372
+ }
373
+
316
374
- (NSString *)jsLocation
317
375
{
318
376
return [[NSUserDefaults standardUserDefaults ] stringForKey: kRCTJsLocationKey ];
@@ -342,6 +400,11 @@ - (void)setEnableMinification:(BOOL)enableMinification
342
400
[self updateValue: @(enableMinification) forKey: kRCTEnableMinificationKey ];
343
401
}
344
402
403
+ - (void )setInlineSourceMap : (BOOL )inlineSourceMap
404
+ {
405
+ [self updateValue: @(inlineSourceMap) forKey: kRCTInlineSourceMapKey ];
406
+ }
407
+
345
408
- (void )setPackagerScheme : (NSString *)packagerScheme
346
409
{
347
410
[self updateValue: packagerScheme forKey: kRCTPackagerSchemeKey ];
0 commit comments