Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 25.2k
[iOS] Allow RCTBundleURLProvider to request an inline source map#37878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Uh oh!
There was an error while loading. Please reload this page.
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b834be9
[iOS] Inline the source map if we're using JSC
Saadnajmi 7ef43f5
Don't inline the source map by default
Saadnajmi a65abff
Don't break the public API
Saadnajmi e9fb38e
nits
Saadnajmi 127f8fa
Fix tests
Saadnajmi 56a85f1
Update AppDelegate.mm
Saadnajmi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -22,10 +22,12 @@ void RCTBundleURLProviderAllowPackagerServerAccess(BOOL allowed) | ||
| kRCTAllowPackagerAccess = allowed; | ||
| } | ||
| #endif | ||
| static NSString *const kRCTPlatformName = @"ios"; | ||
| static NSString *const kRCTPackagerSchemeKey = @"RCT_packager_scheme"; | ||
| static NSString *const kRCTJsLocationKey = @"RCT_jsLocation"; | ||
| static NSString *const kRCTEnableDevKey = @"RCT_enableDev"; | ||
| static NSString *const kRCTEnableMinificationKey = @"RCT_enableMinification"; | ||
| static NSString *const kRCTInlineSourceMapKey = @"RCT_inlineSourceMap"; | ||
| @implementation RCTBundleURLProvider | ||
| @@ -187,6 +189,7 @@ - (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackURLProvider:( | ||
| packagerScheme:[self packagerScheme] | ||
| enableDev:[self enableDev] | ||
| enableMinification:[self enableMinification] | ||
| inlineSourceMap:[self inlineSourceMap] | ||
| modulesOnly:NO | ||
| runModule:YES]; | ||
| } | ||
| @@ -199,6 +202,7 @@ - (NSURL *)jsBundleURLForSplitBundleRoot:(NSString *)bundleRoot | ||
| packagerScheme:[self packagerScheme] | ||
| enableDev:[self enableDev] | ||
| enableMinification:[self enableMinification] | ||
| inlineSourceMap:[self inlineSourceMap] | ||
| modulesOnly:YES | ||
| runModule:NO]; | ||
| } | ||
| @@ -238,20 +242,37 @@ - (NSURL *)resourceURLForResourceRoot:(NSString *)root | ||
| return [[self class] resourceURLForResourcePath:path | ||
| packagerHost:packagerServerHostPort | ||
| scheme:packagerServerScheme | ||
| query:nil]; | ||
| queryItems:nil]; | ||
| } | ||
| + (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot | ||
| packagerHost:(NSString *)packagerHost | ||
| enableDev:(BOOL)enableDev | ||
| enableMinification:(BOOL)enableMinification | ||
| { | ||
| return [self jsBundleURLForBundleRoot:bundleRoot | ||
| packagerHost:packagerHost | ||
| packagerScheme:nil | ||
| enableDev:enableDev | ||
| enableMinification:enableMinification | ||
| inlineSourceMap:NO | ||
| modulesOnly:NO | ||
| runModule:YES]; | ||
| } | ||
| + (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot | ||
| packagerHost:(NSString *)packagerHost | ||
| enableDev:(BOOL)enableDev | ||
| enableMinification:(BOOL)enableMinification | ||
| inlineSourceMap:(BOOL)inlineSourceMap | ||
| { | ||
| return [self jsBundleURLForBundleRoot:bundleRoot | ||
| packagerHost:packagerHost | ||
| packagerScheme:nil | ||
| enableDev:enableDev | ||
| enableMinification:enableMinification | ||
| inlineSourceMap:inlineSourceMap | ||
| modulesOnly:NO | ||
| runModule:YES]; | ||
| } | ||
| @@ -263,22 +284,43 @@ + (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot | ||
| enableMinification:(BOOL)enableMinification | ||
| modulesOnly:(BOOL)modulesOnly | ||
| runModule:(BOOL)runModule | ||
| { | ||
| return [self jsBundleURLForBundleRoot:bundleRoot | ||
| packagerHost:packagerHost | ||
| packagerScheme:nil | ||
| enableDev:enableDev | ||
| enableMinification:enableMinification | ||
| inlineSourceMap:NO | ||
| modulesOnly:modulesOnly | ||
| runModule:runModule]; | ||
| } | ||
| + (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot | ||
| packagerHost:(NSString *)packagerHost | ||
| packagerScheme:(NSString *)scheme | ||
| enableDev:(BOOL)enableDev | ||
| enableMinification:(BOOL)enableMinification | ||
| inlineSourceMap:(BOOL)inlineSourceMap | ||
| modulesOnly:(BOOL)modulesOnly | ||
| runModule:(BOOL)runModule | ||
| { | ||
| NSString *path = [NSString stringWithFormat:@"/%@.bundle", bundleRoot]; | ||
| BOOL lazy = enableDev; | ||
| // When we support only iOS 8 and above, use queryItems for a better API. | ||
| NSString *query = [NSString stringWithFormat:@"platform=ios&dev=%@&lazy=%@&minify=%@&modulesOnly=%@&runModule=%@", | ||
| enableDev ? @"true" : @"false", | ||
| lazy ? @"true" : @"false", | ||
| enableMinification ? @"true" : @"false", | ||
| modulesOnly ? @"true" : @"false", | ||
| runModule ? @"true" : @"false"]; | ||
| NSArray<NSURLQueryItem *> *queryItems = @[ | ||
Saadnajmi marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| [[NSURLQueryItem alloc] initWithName:@"platform" value:kRCTPlatformName], | ||
| [[NSURLQueryItem alloc] initWithName:@"dev" value:enableDev ? @"true" : @"false"], | ||
| [[NSURLQueryItem alloc] initWithName:@"lazy" value:lazy ? @"true" : @"false"], | ||
| [[NSURLQueryItem alloc] initWithName:@"minify" value:enableMinification ? @"true" : @"false"], | ||
| [[NSURLQueryItem alloc] initWithName:@"inlineSourceMap" value:inlineSourceMap ? @"true" : @"false"], | ||
| [[NSURLQueryItem alloc] initWithName:@"modulesOnly" value:modulesOnly ? @"true" : @"false"], | ||
| [[NSURLQueryItem alloc] initWithName:@"runModule" value:runModule ? @"true" : @"false"], | ||
| ]; | ||
| NSString *bundleID = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleIdentifierKey]; | ||
| if (bundleID) { | ||
| query = [NSString stringWithFormat:@"%@&app=%@", query, bundleID]; | ||
| queryItems = [queryItems arrayByAddingObject:[[NSURLQueryItem alloc] initWithName:@"app" value:bundleID]]; | ||
| } | ||
| return [[self class] resourceURLForResourcePath:path packagerHost:packagerHost scheme:scheme query:query]; | ||
| return [[self class] resourceURLForResourcePath:path packagerHost:packagerHost scheme:scheme queryItems:queryItems]; | ||
| } | ||
| + (NSURL *)resourceURLForResourcePath:(NSString *)path | ||
| @@ -295,6 +337,20 @@ + (NSURL *)resourceURLForResourcePath:(NSString *)path | ||
| return components.URL; | ||
| } | ||
| + (NSURL *)resourceURLForResourcePath:(NSString *)path | ||
| packagerHost:(NSString *)packagerHost | ||
| scheme:(NSString *)scheme | ||
| queryItems:(NSArray<NSURLQueryItem *> *)queryItems | ||
| { | ||
| NSURLComponents *components = [NSURLComponents componentsWithURL:serverRootWithHostPort(packagerHost, scheme) | ||
| resolvingAgainstBaseURL:NO]; | ||
| components.path = path; | ||
| if (queryItems != nil) { | ||
| components.queryItems = queryItems; | ||
| } | ||
| return components.URL; | ||
| } | ||
| - (void)updateValue:(id)object forKey:(NSString *)key | ||
| { | ||
| [[NSUserDefaults standardUserDefaults] setObject:object forKey:key]; | ||
| @@ -312,6 +368,11 @@ - (BOOL)enableMinification | ||
| return [[NSUserDefaults standardUserDefaults] boolForKey:kRCTEnableMinificationKey]; | ||
| } | ||
| - (BOOL)inlineSourceMap | ||
| { | ||
| return [[NSUserDefaults standardUserDefaults] boolForKey:kRCTInlineSourceMapKey]; | ||
| } | ||
| - (NSString *)jsLocation | ||
| { | ||
| return [[NSUserDefaults standardUserDefaults] stringForKey:kRCTJsLocationKey]; | ||
| @@ -341,6 +402,11 @@ - (void)setEnableMinification:(BOOL)enableMinification | ||
| [self updateValue:@(enableMinification) forKey:kRCTEnableMinificationKey]; | ||
| } | ||
| - (void)setInlineSourceMap:(BOOL)inlineSourceMap | ||
| { | ||
| [self updateValue:@(inlineSourceMap) forKey:kRCTInlineSourceMapKey]; | ||
| } | ||
| - (void)setPackagerScheme:(NSString *)packagerScheme | ||
| { | ||
| [self updateValue:packagerScheme forKey:kRCTPackagerSchemeKey]; | ||
4 changes: 2 additions & 2 deletions
4 packages/rn-tester/RNTesterUnitTests/RCTBundleURLProviderTests.m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.